Find answers from the community

Updated 11 months ago

do you have any example ? πŸ˜„

At a glance

The post asks for an example, and the comments provide information on how to add metadata and filters to a document using the LlamaIndex library. One community member shares an example of adding metadata and filters, but encounters an error when trying to use the FilterOperator.IN operator. Another community member asks about the vector store being used, and the original poster confirms they are using VectorStoreIndex. However, there is no explicitly marked answer in the comments.

Useful resources
do you have any example ? πŸ˜„
T
A
7 comments
You can add metadata first:

Plain Text
document = Document(
    text="text",
    metadata={"filename": "<doc_file_name>", "category": "<category>"},
)

https://docs.llamaindex.ai/en/stable/understanding/loading/loading.html#adding-metadata

Then you can build filters:

Plain Text
filters = MetadataFilters(
    filters=[
        MetadataFilter(key="product_category", operator=FilterOperator.EQ, value="shoes")
    ]
)

You can pass those in the query:

Plain Text
retriever = index.as_retriever(filters=filters)
when I use something like this it works fine :

Plain Text
        filters = MetadataFilters(
            filters=[
                MetadataFilter(key="file_name", operator=FilterOperator.EQ, value="file1.txt"),
            ],
        )


However when using something like this to add multiple files:


Plain Text
        filters = MetadataFilters(
            filters=[
                MetadataFilter(key="file_name", operator=FilterOperator.IN, value=["file1.txt", "file2.txt"]),
            ],
        )


I've this error : ValueError: Vector Store only supports exact match filters. Please use ExactMatchFilter or FilterOperator.EQ instead
Which vector store are you using? I know some of them have limitations with filtering
I use VectorStoreIndex
which one should I use?
Are you using a 3rd party service for storing it?
Add a reply
Sign up and join the conversation on Discord