How to fill in the configuration if you want to use Tencent Cloud VDB in this place?
Issue with current documentation:
DEFAULT_CONFIG = { "version": "v1.1", # "vector_store": { # "provider": "pgvector", # "config": { # "host": POSTGRES_HOST, # "port": int(POSTGRES_PORT), # "dbname": POSTGRES_DB, # "user": POSTGRES_USER, # "password": POSTGRES_PASSWORD, # "collection_name": POSTGRES_COLLECTION_NAME, # }, # }, # "graph_store": { # "provider": "neo4j", # "config": {"url": NEO4J_URI, "username": NEO4J_USERNAME, "password": NEO4J_PASSWORD}, # },
# "vector_store": {
# "provider": "langchain",
# "config": {
# "class_path": "langchain_community.vectorstores.tencentvectordb.TencentVectorDB",
# "connection_args": {
# "url": os.getenv("VDB_URL"),
# "api_key": os.getenv("VDB_API_KEY"),
# "space": os.getenv("VDB_SPACE")
# }
# }
# },
"llm": {"provider": "openai", "config": {"api_key": OPENAI_API_KEY, "temperature": 0.2, "model": "gpt-4o"}},
"embedder": {"provider": "openai", "config": {"api_key": OPENAI_API_KEY, "model": "text-embedding-3-small"}},
"history_db_path": HISTORY_DB_PATH,
}
MEMORY_INSTANCE = Memory.from_config(DEFAULT_CONFIG)
I tried, but the parameters passed in were incorrect
Hey @orcharddd2024 Thank you for reaching out about integrating Tencent Cloud Vector Database with Mem0. I can see you're trying to use the langchain integration, which is the right approach, but there are a few adjustments needed to get it working properly. Can you try the below config for the tencent cloud vdb? Thanks!
vector_store = TencentVectorDB.from_documents(
documents=[],
embedding=embeddings,
connection_params=connection_params,
index_params=index_params,
collection_name="mem0" # Required for Mem0 integration
)
# Configure Mem0
config = {
"vector_store": {
"provider": "langchain",
"config": {
"client": vector_store # Pass the initialized instance
}
}
}
The TencentVectorDB Class can be configured based upon your requirement.
Hey @orcharddd2024 Thank you for reaching out about integrating Tencent Cloud Vector Database with Mem0. I can see you're trying to use the langchain integration, which is the right approach, but there are a few adjustments needed to get it working properly. Can you try the below config for the tencent cloud vdb? Thanks!
vector_store = TencentVectorDB.from_documents( documents=[], embedding=embeddings, connection_params=connection_params, index_params=index_params, collection_name="mem0" # Required for Mem0 integration ) # Configure Mem0 config = { "vector_store": { "provider": "langchain", "config": { "client": vector_store # Pass the initialized instance } } }The
TencentVectorDBClass can be configured based upon your requirement.
The local test code is as follows
` from langchain_community.vectorstores import TencentVectorDB from langchain_community.vectorstores.tencentvectordb import ConnectionParams VDB_URL="http://xxxx" VDB_API_KEY="xxxx" VDB_SPACE="xxx"
connection_params = ConnectionParams(
url=VDB_URL,
username="root",
key=VDB_API_KEY,
timeout=30
)
vector_store = TencentVectorDB(
embedding=None,
t_vdb_embedding="bge-base-zh",
connection_params=connection_params,
)
texts = ["apple", "pear"] vector_store.add_texts(texts)
results = vector_store.similarity_search("apple", k=5) print(results) `
The error is as follows
Traceback (most recent call last):
File "C:\Users\Administrator\ghtencent\mem0\testzz.py", line 55, in
Possible Reasons:
- Incorrect url. Example: http://10.x.x.x
- Incorrect API key. Example: Tc73SW**********************************
- Incorrect username. Example: root
- Network unreachable. )>
What is the usual reason for this The security mechanisms related to cloud service VDB and whitelist have been set up,Of course, I can confirm again @parshvadaftari
Hey @orcharddd2024 thanks for sharing the detailed logs, it seems like this can be an issue on the tencent cloud. If the VDB is hosted you can always try port tunneling to connect it to local and see if it works. I also see that you're testing it with langchain itself for connection testing. You can run curl -v http://xxxx (with your actual URL) and share the output? This will help isolate whether it's authentication vs pure connectivity.
Hey @orcharddd2024 thanks for sharing the detailed logs, it seems like this can be an issue on the tencent cloud. If the VDB is hosted you can always try port tunneling to connect it to local and see if it works. I also see that you're testing it with langchain itself for connection testing. You can run curl -v http://xxxx (with your actual URL) and share the output? This will help isolate whether it's authentication vs pure connectivity.
embedding = OpenAIEmbeddings( )
tencent_vdb_client = TencentVectorDB( embedding=embedding, connection_params=ConnectionParams( url=VDB_URL, key=VDB_API_KEY, username="root", timeout=30 ), database_name="db-test7", collection_name=VDB_SPACE )
DEFAULT_CONFIG = { "version": "v1.1",
"vector_store": {
"provider": "langchain",
"config": {
"client": tencent_vdb_client # Pass the initialized instance
}
},
"llm": {"provider": "openai", "config": {"api_key": OPENAI_API_KEY, "temperature": 0.2, "model": "gpt-4o"}},
"embedder": {"provider": "openai", "config": {"api_key": OPENAI_API_KEY, "model": "text-embedding-3-small"}},
"history_db_path": HISTORY_DB_PATH,
}
MEMORY_INSTANCE = Memory.from_config(DEFAULT_CONFIG)
After local testing, I was able to connect to Tencent Cloud's vector database. According to the official website of mem0, I changed the code to the above, but there were still errors when Docker started,Especially the errors in the red box;
But you can see from the official website that this example is also written in the same way;
https://docs.mem0.ai/components/vectordbs/dbs/langchain
@parshvadaftari hello
Hey @orcharddd2024 we are looking into this. The issue is fixed in the repo and not released yet. You can try it out using pip install -U pip install git+https://github.com/mem0ai/mem0.git
Hey @orcharddd2024 we are looking into this. The issue is fixed in the repo and not released yet. You can try it out using
pip install -U pip install git+https://github.com/mem0ai/mem0.git
You didn't reply to me. After modifying the source code locally, I was able to read the configuration and made the following changes
mem0/memory/main.py
When the type is langchain, it is necessary to manually construct an instance The instance type is LangchainConfig
But now there is another issue
I am using Tencent Cloud's vector database at http://localhost:8888/doc When calling the interface for inserting data on the platform, it will report that the format of the filter condition is incorrect
in .venv/Lib/site-packages/langchain_community/vectorstores/tencentvectordb.py there is a function called "similarity_search_by_vector". When called externally, no matter what format of filter is passed in, it will report an error;
` def search(self, query: str, vectors: List[List[float]], limit: int = 5, filters: Optional[Dict] = None): """ Search for similar vectors in LangChain. """ # For each vector, perform a similarity search if filters: results = self.client.similarity_search_by_vector(embedding=vectors, k=limit, filter=filters) else: results = self.client.similarity_search_by_vector(embedding=vectors, k=limit)
final_results = self._parse_output(results)
return final_results
` The source code in the open-source framework mem0 is as shown above, but when called, the following error will be reported
Change the source code of mem0 to the following
` def search(self, query: str, vectors: List[List[float]], limit: int = 5, filters: Optional[Dict] = None): """ Search for similar vectors in LangChain / TencentVectorDB. Compatible with TencentVectorDB filter grammar. """ filter_expr = None if filters: if isinstance(filters, dict): # 转换为 LangChain/TencentVectorDB DSL 可解析格式 filter_parts = [] for k, v in filters.items(): if v is None: continue # 自动判断类型,加引号 if isinstance(v, str): v = v.replace('"', '\"') # 转义双引号 filter_parts.append(f'{k} == "{v}"') else: filter_parts.append(f'{k} == {v}') filter_expr = " and ".join(filter_parts)
elif isinstance(filters, str):
# 容错转换: 单等号改双等号, 单引号改双引号
filter_expr = filters.replace(" = ", " == ").replace("'", '"')
# (可选)日志调试
# print(f"[VectorSearch] filter_expr={filter_expr}")
if filter_expr:
results = self.client.similarity_search_by_vector(
embedding=vectors, k=limit, filter=filter_expr
)
else:
results = self.client.similarity_search_by_vector(
embedding=vectors, k=limit
)
final_results = self._parse_output(results)
return final_results
`
Report the following error,The concatenated string is also incorrect;
-
The first mistake is In the similarity search vector call of TencentVectorDB, the passed filter parameter is not a string or None, but a dictionary or other type, causing the Lark parser in the underlying translate_filter() function to report an error: TypeError: text must be str or bytes
-
The second mistake is The Lark syntax parser used internally by TencentVectorDB does not accept traditional SQL style expressions (user_i='zz '). In the source code of langchain_comunity. vectorstores. tencentvectordb (you can open it to see the translate_filter definition), The expected filter expression syntax of Tencent Vector Database's LangChain wrapper is actually JSON style or Python logical expression, rather than SQL format.
but Spelling the expression as user_id=="zz" and... still rejected by Lark......
So no matter how you try to fix it, it always reports an error. Is there a bug in this area? Or was there something I didn't notice? How should I modify it?
.venv/Lib/site-packages/langchain_community/vectorstores/tencentvectordb.py,The relevant source code is as follows
mem0/vector_stores/langchain.py
No matter how you modify this code, it always reports an error. What is the reason for this? Is it a bug? @parshvadaftari hello
There's another question
Hey @orcharddd2024 mem0 handles the configuration of the provider in the codebase, where you don't have to manually construct an instance when the type is Langchain. The code base handles that portion. For the issue with the filters, can you please share what messages, you're trying to add to mem0?
The problem with similarity_search_by_vector which you're facing is not related to mem0 as it depends upon the langchain framework. Can you please share sample messages you're trying to add and how the requests are being made to add them? Thanks!
Hey @orcharddd2024 mem0 handles the configuration of the provider in the codebase, where you don't have to manually construct an instance when the type is Langchain. The code base handles that portion. For the issue with the filters, can you please share what messages, you're trying to add to mem0?
The problem with
similarity_search_by_vectorwhich you're facing is not related to mem0 as it depends upon the langchain framework. Can you please share sample messages you're trying to add and how the requests are being made to add them? Thanks!
Consistently reporting that the filters format is incorrect
http://localhost:8888/docs ,Requests sent through this web page,Request to create memory,as shown below,Error as shown above;
@parshvadaftari hello,Perhaps mem0 passed in the wrong filters when calling the search method? And the error clearly states that a string is needed, but the input is indeed a dictionary;
I downloaded the latest code for testing, and the first issue of configuration read failure bug has been resolved. However, the second issue is that there are always errors when creating memory
mem0/vector_stores/langchain.py