Find answers from the community

Updated 3 months ago

Filtering

I am building a RAG with index flame. I would like to be able to filter the universe of nodes based on the user's query (metadata filter) but I have not been able to. Any ideas? Thank you very much
L
1 comment
Pretty sure this is in the docs, but

Plain Text
from llama_index.core.vector_stores import (
    MetadataFilter,
    MetadataFilters,
    FilterOperator,
)

filters = MetadataFilters(
    filters=[
        MetadataFilter(key="theme", operator=FilterOperator.EQ, value="Mafia"),
    ]
)

retriever = index.as_retriever(filters=filters)
retriever.retrieve("...")

query_engine = index.as_query_engine(filters=filters)
query_engine.query(...)
Add a reply
Sign up and join the conversation on Discord