query all nodes on a VectorStore based on a metadata filter #11285
Replies: 1 comment
-
🤖 Hey @CMauricioAH! Great to see you back. Hope you're doing well. Based on the context provided, it seems like you're on the right track with using the Here is an example of how you can use this feature: from llama_index import Document
from llama_index.vector_stores.types import ExactMatchFilter, MetadataFilters
# Insert a document with specific metadata
doc = Document(text="target", metadata={"tag": "target"})
index.insert(doc)
# Create a filter that matches the inserted metadata
filters = MetadataFilters(
filters=[ExactMatchFilter(key="tag", value="target")]
)
# Use the filter in the retriever to retrieve only the documents that match the filter
retriever = index.as_retriever(
similarity_top_k=20,
filters=filters,
)
source_nodes = retriever.retrieve("What did the author do growing up?") This code will retrieve only the documents that have a metadata tag "tag" with the value "target". For multiple values for a metadata key on the filter, it seems like there is a limitation on the vector store. You might need to find a workaround or use a different vector store that supports this feature. You can find more information about this in the following issues and pull requests:
I hope this helps! If you have any other questions, feel free to ask. Sources
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have on a vector store nodes, that contain as metadata an additional id. I want to filter all of those from the vector store with a query. I found there is the VectorStoreQuery, and added as MetadataFilter the id to search for it, but could just not figure out if this is even possible. So far I receive an empty list as response. Any ideas how to do this?
Beta Was this translation helpful? Give feedback.
All reactions