TimeWeightedVectorStoreRetriever does not support Chroma due to datetime metadata issue #29306
Open
5 tasks done
Labels
🤖:bug
Related to a bug, vulnerability, unexpected error with an existing feature
Ɑ: vector store
Related to vector store module
Checked other resources
Example Code
This is an example from LangChain (but using Chroma instead of Faiss)
link
Error Message and Stack Trace (if applicable)
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
in <cell line: 14>()
12 # Add documents with a timestamp from yesterday
13 yesterday = datetime.now() - timedelta(days=1)
---> 14 retriever.add_documents(
15 [Document(page_content="hello world", metadata={"last_accessed_at": yesterday})]
16 )
/usr/local/lib/python3.10/dist-packages/langchain/retrievers/time_weighted_retriever.py in add_documents(self, documents, **kwargs)
162 doc.metadata["buffer_idx"] = len(self.memory_stream) + i
163 self.memory_stream.extend(dup_docs)
--> 164 return self.vectorstore.add_documents(dup_docs, **kwargs)
165
166 async def aadd_documents(
/usr/local/lib/python3.10/dist-packages/langchain_core/vectorstores/base.py in add_documents(self, documents, **kwargs)
285 texts = [doc.page_content for doc in documents]
286 metadatas = [doc.metadata for doc in documents]
--> 287 return self.add_texts(texts, metadatas, **kwargs)
288 msg = (
289 f"
add_documents
andadd_texts
has not been implemented "/usr/local/lib/python3.10/dist-packages/langchain_chroma/vectorstores.py in add_texts(self, texts, metadatas, ids, **kwargs)
564 "langchain_community.vectorstores.utils.filter_complex_metadata."
565 )
--> 566 raise ValueError(e.args[0] + "\n\n" + msg)
567 else:
568 raise e
ValueError: Expected metadata value to be a str, int, float or bool, got 2025-01-19 06:02:08.017004 which is a datetime in upsert.
Try filtering complex metadata from the document using langchain_community.vectorstores.utils.filter_complex_metadata.
Description
Description
When using
TimeWeightedVectorStoreRetriever
with theChroma
vector store, an error occurs when attempting to add documents withdatetime
metadata. The error indicates thatChroma
does not supportdatetime
objects in metadata, which is required byTimeWeightedVectorStoreRetriever
for its time-weighted retrieval functionality.Expected Behavior
The
TimeWeightedVectorStoreRetriever
should successfully add documents to theChroma
vector store, even withdatetime
metadata, and allow time-weighted retrieval.System Info
System Information
Package Information
Optional packages not installed
Other Dependencies
The text was updated successfully, but these errors were encountered: