Skip to content

How to filter documents based on a list of metadata in LangChain's Chroma VectorStore? #21965

Answered by dosubot bot
abhigrazitti asked this question in Q&A
Discussion options

You must be logged in to vote

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:

  1. Define the list of document names you want to filter by.
  2. Modify the as_retriever method to include the filter in the search_kwargs.

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 u…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@abhigrazitti
Comment options

@simpliatanu
Comment options

Answer selected by abhigrazitti
Comment options

You must be logged in to vote
1 reply
@dosubot
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants