Metadata filtering with ElasticSearch vectorstore #9436
Replies: 6 comments 4 replies
-
🤖 Hey @amitguptadumka! Good to see you diving into LlamaIndex again. We meet once more in the realm of code and queries! 🖥️🚀 To perform multiple metadata filtering with OR condition in Elastic Search, you can use the from llama_index.vector_stores.types import (
MetadataFilter,
FilterCondition,
MetadataFilters
)
filters = MetadataFilters(
filters=[
MetadataFilter(key="theme", value="Mafia"),
MetadataFilter(key="author", value="Stephen King"),
],
condition=FilterCondition.OR,
)
retriever = index.as_retriever(filters=filters)
retriever.retrieve("Your query here") In this code, You can find more information about this in the Chroma Metadata Filter example in the LlamaIndex repository. However, I wasn't able to find specific information about the use of SourcesThis response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Beta Was this translation helpful? Give feedback.
-
@dosu-bot |
Beta Was this translation helpful? Give feedback.
-
Is there a way say i define two separate filters f1 and f2 and can i use those in retriever together, for example: |
Beta Was this translation helpful? Give feedback.
-
Is there a way say i define two separate filters f1 and f2 and can i use those in retriever together, for example: |
Beta Was this translation helpful? Give feedback.
-
@wpiekutowski Any help here please? |
Beta Was this translation helpful? Give feedback.
-
I'm looking for something like a nested filter. If I use the first section of the filter only, then it works perfectly, but as I include a nested filter I get a error saying "AttributeError: 'MetadataFilters' object has no attribute 'operator'". I'm using llama-index v0.10.x filters = MetadataFilters(
filters=[
MetadataFilters(
filters=[
MetadataFilter(key="metadata.country_code", value=country_code, operator=FilterOperator.EQ),
MetadataFilter(key="metadata.country_code", value='Global', operator=FilterOperator.EQ),
],
condition=FilterCondition.OR
),
MetadataFilter(key="metadata.platformTypes", value='AGENT', operator=FilterOperator.EQ),
],
condition=FilterCondition.AND
) |
Beta Was this translation helpful? Give feedback.
-
Hi,
I have my index built in Elastic Search and i want to perform multiple metadata filtering with OR condition while retrieving.
Say for example i have below node:
nodes = [
TextNode(
text="The Shawshank Redemption",
metadata={
"author": "Stephen King",
"theme": "Friendship",
},
),
TextNode(
text="The Godfather",
metadata={
"director": "Francis Ford Coppola",
"theme": "Mafia",
},
),
TextNode(
text="Inception",
metadata={
"director": "Christopher Nolan",
},
),
]
Now i want to retrieve the docs which has "Theme"="Mafia" or "author"= "Stephen King". How to achieve that?
For single filtering i tried this and this is working: filters = MetadataFilters(filters=[ExactMatchFilter(key="author", value='Stephen King')]).
But its not working for multiple conditions, kindly guide.
Beta Was this translation helpful? Give feedback.
All reactions