Class DecisionDocumentReranker
- All Implemented Interfaces:
BiFunction<Query,,List<Document>, List<Document>> DocumentPostProcessor
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
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final YesNoQuestionThe question asked unlessDecisionDocumentReranker.Builder.question(YesNoQuestion)replaces it.static final StringThe passage field of the input.static final StringThe query field of the input.static final StringThe name of the question asked about each document.static final StringMetadata key holding the score this reranker gave a document. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.function.BiFunction
andThenMethods inherited from interface org.springframework.ai.rag.postretrieval.document.DocumentPostProcessor
apply
-
Field Details
-
SCORE_METADATA_KEY
Metadata key holding the score this reranker gave a document.- See Also:
-
QUESTION_NAME
The name of the question asked about each document.- See Also:
-
QUERY_FIELD
The query field of the input.- See Also:
-
PASSAGE_FIELD
The passage field of the input.- See Also:
-
DEFAULT_QUESTION
The question asked unlessDecisionDocumentReranker.Builder.question(YesNoQuestion)replaces it.
-
-
Method Details
-
process
- Specified by:
processin interfaceDocumentPostProcessor
-
builder
- Parameters:
decisionModel- the model that judges the documents- Returns:
- a new builder
-