Skip to content

How to build a retriever that filters documents by metadata #9536

Answered by dosubot bot
aiwalter asked this question in Q&A
Discussion options

You must be logged in to vote

🤖

Sure, I can guide you on how to modify the BaseRetriever to implement the functionality you described.

First, you need to override the _retrieve method in your subclass of BaseRetriever. This method should return a list of NodeWithScore objects. Each NodeWithScore object contains a node and a score. The node is an instance of the Node class, which has a metadata attribute that is a dictionary. The score is a float that represents the relevance of the node to the query.

Here is a simplified version of how you can implement this:

from llama_index.core.base_retriever import BaseRetriever
from llama_index.core.node import NodeWithScore
from typing import List, Dict
from collections import d…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@aiwalter
Comment options

@dosubot
Comment options

Answer selected by aiwalter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant