----------------------
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
:
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:
# define retriever that fetches the top 2 examples.
metadata_retriever = index.as_retriever(similarity_top_k=2)