Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions docs/components/vectordbs/dbs/tencent.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[TencentVectorDB](https://cloud.tencent.com/product/vdb) is an open-source vector database that suits AI applications of every size, from running a demo chatbot in a Jupyter notebook to building web-scale search that serves billions of users.

### Usage

```python
import os
from mem0 import Memory

config = {
"vector_store": {
"provider": "tencent",
"config": {
"url": "http://your-tencent-vdb-instance-url",
"key": "your-tencent-vdb-api-key",
}
}
}

m = Memory.from_config(config)
messages = [
{"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"},
{"role": "assistant", "content": "How about thriller movies? They can be quite engaging."},
{"role": "user", "content": "I’m not a big fan of thriller movies but I love sci-fi movies."},
{"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."}
]
m.add(messages, user_id="alice", metadata={"category": "movies"})
```

### Config

Here are the parameters available for configuring TencentVectorDB:

| Parameter | Description | Default Value |
| --- | --- | --- |
| `url` | URL for TencentVectorDB instance | Required |
| `key` | API key for TencentVectorDB instance | Required |
| `username` | Username for TencentVectorDB instance | `root` |
| `database_name` | Name of the database | `mem0` |
| `collection_name` | Name of the collection | `mem0` |
| `embedding_model_dims` | Dimensions of the embedding model | `1536` |
| `metric_type` | Metric type for similarity search | `COSINE` |
| `index_type` | Index type for vectors | `HNSW` |
| `shard_num` | Number of shards in the collection | `2` |
| `replica_num` | Number of replicas for the collection | `2` |
| `field_type` | Field type for the embedding vectors | `vector` |
| `params` | Parameters for the index | `None` |
| `no_index_fields` | Fields that will not be indexed | `None` |
3 changes: 2 additions & 1 deletion docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@
"components/vectordbs/dbs/cassandra",
"components/vectordbs/dbs/s3_vectors",
"components/vectordbs/dbs/databricks",
"components/vectordbs/dbs/neptune_analytics"
"components/vectordbs/dbs/neptune_analytics",
"components/vectordbs/dbs/tencent"
]
}
]
Expand Down
31 changes: 31 additions & 0 deletions mem0/configs/vector_stores/tencent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from typing import Any, Dict, List

from pydantic import BaseModel, ConfigDict, Field, model_validator


class TencentVectorDBConfig(BaseModel):
url: str = Field(None, description="URL for TencentVectorDB instance")
key: str = Field(None, description="API key for TencentVectorDB instance")
username: str = Field("root", description="Username for TencentVectorDB instance")
database_name: str = Field("mem0", description="Name of the database")
collection_name: str = Field("mem0", description="Name of the collection")
embedding_model_dims: int = Field(1536, description="Dimensions of the embedding model")
metric_type: str = Field("COSINE", description="Metric type for similarity search")
index_type: str = Field("HNSW", description="Index type for vectors")
shard_num: int = Field(2, description="Number of shards in the collection")
replica_num: int = Field(2, description="Number of replicas for the collection")
field_type: str = Field("vector", description="Field type for the embedding vectors")
params: Dict[str, Any] = Field({}, description="Parameters for the index")
no_index_fields: List[str] = Field([], description="Fields that will not be indexed")

@model_validator(mode="before")
@classmethod
def validate_extra_fields(cls, values: Dict[str, Any]) -> Dict[str, Any]:
url, key = values.get("url"), values.get("key")
if not url or not key:
raise ValueError(
"Both 'url' and 'key' must be provided."
)
return values

model_config = ConfigDict(arbitrary_types_allowed=True)
9 changes: 6 additions & 3 deletions mem0/utils/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
from mem0.configs.llms.vllm import VllmConfig
from mem0.configs.rerankers.base import BaseRerankerConfig
from mem0.configs.rerankers.cohere import CohereRerankerConfig
from mem0.configs.rerankers.sentence_transformer import SentenceTransformerRerankerConfig
from mem0.configs.rerankers.zero_entropy import ZeroEntropyRerankerConfig
from mem0.configs.rerankers.llm import LLMRerankerConfig
from mem0.configs.rerankers.huggingface import HuggingFaceRerankerConfig
from mem0.configs.rerankers.llm import LLMRerankerConfig
from mem0.configs.rerankers.sentence_transformer import (
SentenceTransformerRerankerConfig,
)
from mem0.configs.rerankers.zero_entropy import ZeroEntropyRerankerConfig
from mem0.embeddings.mock import MockEmbeddings


Expand Down Expand Up @@ -186,6 +188,7 @@ class VectorStoreFactory:
"baidu": "mem0.vector_stores.baidu.BaiduDB",
"cassandra": "mem0.vector_stores.cassandra.CassandraDB",
"neptune": "mem0.vector_stores.neptune_analytics.NeptuneAnalyticsVector",
"tencent": "mem0.vector_stores.tencent.TencentVectorDB",
}

@classmethod
Expand Down
1 change: 1 addition & 0 deletions mem0/vector_stores/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class VectorStoreConfig(BaseModel):
"faiss": "FAISSConfig",
"langchain": "LangchainConfig",
"s3_vectors": "S3VectorsConfig",
"tencent": "TencentVectorDBConfig",
}

@model_validator(mode="after")
Expand Down
Loading