Find answers from the community

Updated 8 months ago

I have a bunch of text in a vector store. But the text is mapped to code that I store in t

@kapa.ai I have a bunch of text in a vector store. But the text is mapped to code that I store in the meta data as part of the document. When I run the retriever during a query is there a way to pull the metadata in also as part of the context window prompt during the synthesizer
k
3 comments
Please stand by @cmosguy as I search the knowledge base. I normally take about 20 seconds or so. :wave:
----------------------
Yes, you can pull the metadata as part of the context window prompt during the synthesizer. This can be achieved by using the VectorIndexAutoRetriever module in LlamaIndex. This module takes in VectorStoreInfo, which contains a structured description of the vector store collection and the metadata filters it supports. This information will then be used in the auto-retrieval prompt where the LLM infers metadata filters.

Here is an example of how you can define your VectorIndexAutoRetriever:

Plain Text
from llama_index.core.retrievers import VectorIndexAutoRetriever
from llama_index.core.vector_stores import MetadataInfo, VectorStoreInfo

vector_store_info = VectorStoreInfo(
    content_info="your text content",
    metadata_info=[
        MetadataInfo(
            name="your metadata name",
            type="your metadata type",
            description="your metadata description",
        ),
        # add more MetadataInfo objects for additional metadata fields
    ],
)

retriever = VectorIndexAutoRetriever(
    index, 
    vector_store_info=vector_store_info
)

In the MetadataInfo object, you can specify the name, type, and description of your metadata. You can add more MetadataInfo objects for additional metadata fields.

Moreover, you can also retrieve relevant few-shot examples of metadata to help the LLM better infer the correct metadata filters. This can be done via vector retrieval. Here is an example of how you can define a retriever that fetches the top 2 examples:

Plain Text
# define retriever that fetches the top 2 examples.
metadata_retriever = index.as_retriever(similarity_top_k=2)
You can find more details in the LlamaIndex documentation ().
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Add a reply
Sign up and join the conversation on Discord