Find answers from the community

Updated 3 months ago

Logan M i have this usecase i create an

i have this usecase - i create an index of documents, and I want to be able to support 2 types of queries - one to query the entire index of documents and give a response vis semantic search, the other is to be able to filter the index to use the embeddings of only one document to answer. How can i accomplish this?
L
V
8 comments
Will you know the type of query before hand? Or does some process have to make that decision?

You could use a vector index that supports metadata filtering, and filter down to only the document of interest
No idea about query beforehand. user flow goes like this - they either choose to give a query to the entire index because they arent aware which document answers their question, or they know the document before hand and want to query just that to avoid the semantic search filtering process. Which vector index supports metadata filtering?
Thanks a lot for your help, Logan! Appreciate you so darn much
Thanks a ton! Looks like chroma supports metadata filtering
Not sure how exactly I would go about filtering? i assume I have to get the query, filter metadata using the chromadb client, and then how do I integrate that with the query engine or index?
I might be confused, sorry about that, if thats the case @Logan M
Yea that's why I mentioned if you knew the filter ahead of time πŸ‘€

If you know the filtering ahead of time, you can apply it like this example
Plain Text
from llama_index.vector_stores.types import ExactMatchFilter, MetadataFilters

filters = MetadataFilters(filters=[ExactMatchFilter(key="theme", value="Mafia")])
query_engine = index.as_query_engine(filters=filters)


If you dont know the filters ahead of time, you need some process for getting that. You could use the auto query engine which gets the LLM to try and configure filters for you (example is for pinecone. but it will work with chroma too)
https://gpt-index.readthedocs.io/en/stable/examples/vector_stores/chroma_auto_retriever.html#define-vectorindexautoretriever

Or you could run an initial processing step with a pydantic program to try and infer filters before querying
https://gpt-index.readthedocs.io/en/stable/examples/output_parsing/openai_pydantic_program.html
Add a reply
Sign up and join the conversation on Discord