Skip to content

Commit 7ba47a9

Browse files
author
wlleiiwang
committed
Feature: tencent vector db integration
1 parent 6a72770 commit 7ba47a9

File tree

8 files changed

+663
-4
lines changed

8 files changed

+663
-4
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
[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.
2+
3+
### Usage
4+
5+
```python
6+
import os
7+
from mem0 import Memory
8+
9+
config = {
10+
"vector_store": {
11+
"provider": "tencent",
12+
"config": {
13+
"url": "http://your-tencent-vdb-instance-url",
14+
"key": "your-tencent-vdb-api-key",
15+
}
16+
}
17+
}
18+
19+
m = Memory.from_config(config)
20+
messages = [
21+
{"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"},
22+
{"role": "assistant", "content": "How about thriller movies? They can be quite engaging."},
23+
{"role": "user", "content": "I’m not a big fan of thriller movies but I love sci-fi movies."},
24+
{"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."}
25+
]
26+
m.add(messages, user_id="alice", metadata={"category": "movies"})
27+
```
28+
29+
### Config
30+
31+
Here are the parameters available for configuring TencentVectorDB:
32+
33+
| Parameter | Description | Default Value |
34+
| --- | --- | --- |
35+
| `url` | URL for TencentVectorDB instance | Required |
36+
| `key` | API key for TencentVectorDB instance | Required |
37+
| `username` | Username for TencentVectorDB instance | `root` |
38+
| `database_name` | Name of the database | `mem0` |
39+
| `collection_name` | Name of the collection | `mem0` |
40+
| `embedding_model_dims` | Dimensions of the embedding model | `1536` |
41+
| `metric_type` | Metric type for similarity search | `COSINE` |
42+
| `index_type` | Index type for vectors | `HNSW` |
43+
| `shard_num` | Number of shards in the collection | `2` |
44+
| `replica_num` | Number of replicas for the collection | `2` |
45+
| `field_type` | Field type for the embedding vectors | `vector` |
46+
| `params` | Parameters for the index | `None` |
47+
| `no_index_fields` | Fields that will not be indexed | `None` |

docs/docs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@
224224
"components/vectordbs/dbs/cassandra",
225225
"components/vectordbs/dbs/s3_vectors",
226226
"components/vectordbs/dbs/databricks",
227-
"components/vectordbs/dbs/neptune_analytics"
227+
"components/vectordbs/dbs/neptune_analytics",
228+
"components/vectordbs/dbs/tencent"
228229
]
229230
}
230231
]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from typing import Any, Dict, List
2+
3+
from pydantic import BaseModel, ConfigDict, Field, model_validator
4+
5+
6+
class TencentVectorDBConfig(BaseModel):
7+
url: str = Field(None, description="URL for TencentVectorDB instance")
8+
key: str = Field(None, description="API key for TencentVectorDB instance")
9+
username: str = Field("root", description="Username for TencentVectorDB instance")
10+
database_name: str = Field("mem0", description="Name of the database")
11+
collection_name: str = Field("mem0", description="Name of the collection")
12+
embedding_model_dims: int = Field(1536, description="Dimensions of the embedding model")
13+
metric_type: str = Field("COSINE", description="Metric type for similarity search")
14+
index_type: str = Field("HNSW", description="Index type for vectors")
15+
shard_num: int = Field(2, description="Number of shards in the collection")
16+
replica_num: int = Field(2, description="Number of replicas for the collection")
17+
field_type: str = Field("vector", description="Field type for the embedding vectors")
18+
params: Dict[str, Any] = Field({}, description="Parameters for the index")
19+
no_index_fields: List[str] = Field([], description="Fields that will not be indexed")
20+
21+
@model_validator(mode="before")
22+
@classmethod
23+
def validate_extra_fields(cls, values: Dict[str, Any]) -> Dict[str, Any]:
24+
url, key = values.get("url"), values.get("key")
25+
if not url or not key:
26+
raise ValueError(
27+
"Both 'url' and 'key' must be provided."
28+
)
29+
return values
30+
31+
model_config = ConfigDict(arbitrary_types_allowed=True)

mem0/utils/factory.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
from mem0.configs.llms.vllm import VllmConfig
1313
from mem0.configs.rerankers.base import BaseRerankerConfig
1414
from mem0.configs.rerankers.cohere import CohereRerankerConfig
15-
from mem0.configs.rerankers.sentence_transformer import SentenceTransformerRerankerConfig
16-
from mem0.configs.rerankers.zero_entropy import ZeroEntropyRerankerConfig
17-
from mem0.configs.rerankers.llm import LLMRerankerConfig
1815
from mem0.configs.rerankers.huggingface import HuggingFaceRerankerConfig
16+
from mem0.configs.rerankers.llm import LLMRerankerConfig
17+
from mem0.configs.rerankers.sentence_transformer import (
18+
SentenceTransformerRerankerConfig,
19+
)
20+
from mem0.configs.rerankers.zero_entropy import ZeroEntropyRerankerConfig
1921
from mem0.embeddings.mock import MockEmbeddings
2022

2123

@@ -186,6 +188,7 @@ class VectorStoreFactory:
186188
"baidu": "mem0.vector_stores.baidu.BaiduDB",
187189
"cassandra": "mem0.vector_stores.cassandra.CassandraDB",
188190
"neptune": "mem0.vector_stores.neptune_analytics.NeptuneAnalyticsVector",
191+
"tencent": "mem0.vector_stores.tencent.TencentVectorDB",
189192
}
190193

191194
@classmethod

mem0/vector_stores/configs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class VectorStoreConfig(BaseModel):
3434
"faiss": "FAISSConfig",
3535
"langchain": "LangchainConfig",
3636
"s3_vectors": "S3VectorsConfig",
37+
"tencent": "TencentVectorDBConfig",
3738
}
3839

3940
@model_validator(mode="after")

0 commit comments

Comments
 (0)