Find answers from the community

Updated 2 months ago

Is there a way to retrieve nodes based on metadata information only, and not the main text

Is there a way to retrieve nodes based on metadata information only, and not the main text?
k
n
5 comments
Please stand by @node0 as I search the knowledge base. I normally take about 20 seconds or so. :wave:
----------------------
Yes, LlamaIndex allows you to retrieve nodes based on metadata information. You can use the MetadataFilters and ExactMatchFilter classes from the llama_index.core.vector_stores module to filter documents based on metadata.

Here is an example of how you can do this:

Plain Text
from llama_index.core.vector_stores import ExactMatchFilter, MetadataFilters

filters = MetadataFilters(
    filters=[ExactMatchFilter(key="tag", value="target")]
)

retriever = index.as_retriever(
    similarity_top_k=20,
    filters=filters,
)

source_nodes = retriever.retrieve("What did the author do growing up?")


In this example, the ExactMatchFilter is used to filter nodes that have a metadata key "tag" with the value "target". The retrieve method of the retriever object is then used to retrieve nodes that match the query and the specified metadata filters.

You can find more information about this in the Simple Vector Store example () from the LlamaIndex documentation.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
@kapa.ai Is there a way to do this without using a MetaDataFilter? I would like to match the query with node metadata and disregard the node text.
Let me check the knowledge base for you. One moment! :books:
----------------------
Based on the provided knowledge sources, it appears that LlamaIndex primarily uses the MetadataFilters and ExactMatchFilter classes for filtering based on metadata. There isn't a direct mention of an alternative way to match the query with node metadata and disregard the node text.

However, there is a ResponseMode class in LlamaIndex with a NO_TEXT attribute. When this mode is used, it returns the retrieved context nodes without synthesizing a final response. This might be useful if you want to work directly with the metadata of the nodes.

Plain Text
NO_TEXT = 'no_text'


You can find more information about this in the LlamaIndex API reference ().

Please note that this might not completely fulfill your requirement of disregarding the node text during the retrieval process. For a more specific solution, you might need to refer to more detailed documentation or reach out to the LlamaIndex community or support.
----------------------
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