Find answers from the community

s
F
Y
a
P
Updated last month

How do I add a node_postprocessor to a RetrieverQueryEngine?

How do I add a node_postprocessor to a RetrieverQueryEngine?
k
2 comments
Please stand by @dkatz123 as I search the knowledge base. I normally take about 20 seconds or so. :wave:
----------------------
To add a node_postprocessor to a RetrieverQueryEngine in LlamaIndex, you can follow these steps:

  1. First, you need to define your node_postprocessor. This could be any of the built-in postprocessors like KeywordNodePostprocessor, SimilarityPostprocessor, PrevNextNodePostprocessor, etc., or a custom one that you have created. Here's an example of defining a KeywordNodePostprocessor:
Plain Text
node_postprocessors = [
    KeywordNodePostprocessor(
        required_keywords=["Combinator"], exclude_keywords=["Italy"]
    )
]

Source ()

  1. Then, you can add this node_postprocessor to the RetrieverQueryEngine using the from_args method:
Plain Text
query_engine = RetrieverQueryEngine.from_args(
    retriever, node_postprocessors=node_postprocessors
)

Source ()

  1. Now, you can use this query_engine to query your data:
Plain Text
response = query_engine.query("What did the author do growing up?")

Source ()

Remember, the node_postprocessor is applied within a query engine, after the node retrieval step and before the response synthesis step. It takes a set of nodes, and applies some kind of transformation or filtering before returning them. This can help reduce the time/number of LLM calls/cost or improve response quality. Source ()
----------------------
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