How to filter documents based on a list of metadata in LangChain's Chroma VectorStore? #21965
-
Checked other resources
Commit to Help
Example Codelst = ['doc1', 'doc2', 'doc3']
base_retriever = chroma_db.as_retriever(search_kwargs={'k': 10}) DescriptionI'm working with LangChain's Chroma VectorStore and I'm trying to filter documents based on a list of document names. However, I’m not sure how to modify this code to filter documents based on my list of document names. Could anyone guide me on how to achieve this? Any help would be greatly appreciated! Thank you in advance! System InfoSystem Information
Package Information
Packages not installed (Not Necessarily a Problem)The following packages were not found:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
To filter documents based on a list of document names in LangChain's Chroma VectorStore, you can modify your code to include a filter using the
Here's an example: # Define your list of document names
lst = ['doc1', 'doc2', 'doc3']
# Create a filter dictionary to filter by document names
filter_dict = {"name": {"$in": lst}}
# Modify the as_retriever method to include the filter in search_kwargs
base_retriever = chroma_db.as_retriever(search_kwargs={'k': 10, 'filter': filter_dict})
# Now you can use the retriever to search with the filter applied
query = "your search query"
results = base_retriever.invoke(query)
for result in results:
print(result) Explanation:
By following this approach, you can filter documents based on a list of document names in LangChain's Chroma VectorStore.
|
Beta Was this translation helpful? Give feedback.
-
Hi, |
Beta Was this translation helpful? Give feedback.
To filter documents based on a list of document names in LangChain's Chroma VectorStore, you can modify your code to include a filter using the
where_document
parameter. Here's how you can achieve this:as_retriever
method to include the filter in thesearch_kwargs
.Here's an example: