Tencent Cloud VectorDB Python SDK

raw JSON →
2.1.1 verified Fri May 01 auth: no python

Tencent Cloud VectorDB Python SDK for managing vector databases, including collection creation, data insertion, and similarity search. Current version 2.1.1, requires Python >=3. Monthly releases.

pip install tcvectordb
error ModuleNotFoundError: No module named 'tcvectordb'
cause SDK not installed or installation failed.
fix
Run pip install tcvectordb.
error ImportError: cannot import name 'IndexType' from 'tcvectordb'
cause Enums were relocated in v2.0.
fix
Import from tcvectordb.model.enum instead: from tcvectordb.model.enum import IndexType.
error tcvectordb.exception.VectorDBException: Authentication failed
cause Incorrect username or key, or using password parameter.
fix
Ensure username and key are correct. Do not use password; use key.
breaking In v2.0, the SDK was rewritten; old v1.x code using `import tcvectordb` directly will not work. Enums moved from root to `tcvectordb.model.enum`.
fix Update imports to use `tcvectordb.model.enum` and follow v2.x API patterns.
deprecated `database.create_collection` with `index` parameter as a list of IndexField objects is deprecated; use `tcvectordb.model.index.Index` object.
fix Use `Index` class with `IndexField` entries.
gotcha The SDK uses `key` parameter for authentication, not `password`. Using `password` will result in silent auth failure.
fix Use `key=os.environ.get('VECTORDB_KEY')` when creating VectorDBClient.
gotcha The `url` must include the protocol (https://) and port if non-default. Missing protocol causes connection errors.
fix Set `url='https://your-endpoint:port'`.

Creates a database and collection with HNSW index.

import os
from tcvectordb import VectorDBClient
from tcvectordb.model.enum import FieldType, IndexType, MetricType
from tcvectordb.model.index import Index, IndexField

client = VectorDBClient(
    url=os.environ.get('VECTORDB_URL', ''),
    username=os.environ.get('VECTORDB_USERNAME', 'root'),
    key=os.environ.get('VECTORDB_KEY', ''),
)
db = client.create_database('test_db')
index = Index(
    IndexField(name='id', field_type=FieldType.String, primary_key=True),
    IndexField(name='vector', field_type=FieldType.Vector, dimension=3, index_type=IndexType.HNSW, metric_type=MetricType.COSINE)
)
collection = db.create_collection('test_col', shard=1, replicas=0, index=index)
print('Collection created successfully')