Class DecisionDocumentReranker

java.lang.Object
org.springframework.ai.rag.postretrieval.document.DecisionDocumentReranker
All Implemented Interfaces:
BiFunction<Query,List<Document>,List<Document>>, DocumentPostProcessor

public final class DecisionDocumentReranker extends Object implements DocumentPostProcessor
Reorders retrieved documents by asking a DecisionModel, one document at a time, whether each one answers the query.

Vector search ranks by embedding distance. That is a good way to find candidates and a poor way to order them, because a passage can be on the right subject and still not contain the answer. Asking the model directly whether each candidate answers the query measures something else, and that is what the final order should be based on.

Each document is judged in its own call, because the query and passage pairs are independent. The calls run concurrently; DecisionDocumentReranker.Builder.concurrency(int) or DecisionDocumentReranker.Builder.executor(Executor) controls how many at once.

Each scored document carries its score under SCORE_METADATA_KEY, so a later stage or a log can see why the order came out this way. A document whose call failed or timed out, or that the model refused to judge, is kept rather than dropped, because a failure says nothing about relevance. It is placed after all the scored documents, so a failure can never push a known-good passage out under topK.


 RetrievalAugmentationAdvisor.builder()
     .documentRetriever(retriever)
     .documentPostProcessors(DecisionDocumentReranker.builder(decisionModel).topK(5).build())
     .build();
 
Since:
2.1.0
Author:
Christian Tzolov