Skip to content

Commit e31e6d9

Browse files
committed
Feat(rerank): Add no-op DocumentPostProcessor as fallback
- Register a default DocumentPostProcessor that returns documents as-is Signed-off-by: KoreaNirsa <[email protected]>
1 parent f597aee commit e31e6d9

File tree

1 file changed

+24
-0
lines changed
  • spring-ai-rag/src/main/java/org/springframework/ai/rag/postretrieval/rerank

1 file changed

+24
-0
lines changed

spring-ai-rag/src/main/java/org/springframework/ai/rag/postretrieval/rerank/RerankConfig.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.springframework.ai.rag.postretrieval.document.DocumentPostProcessor;
44
import org.springframework.beans.factory.annotation.Value;
5+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
56
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
67
import org.springframework.context.annotation.Bean;
78
import org.springframework.context.annotation.Configuration;
@@ -24,9 +25,32 @@ public class RerankConfig {
2425
@Value("${spring.ai.rerank.cohere.api-key}")
2526
private String apiKey;
2627

28+
/**
29+
* Registers a DocumentPostProcessor bean that enables reranking using Cohere.
30+
*
31+
* This bean is only created when the property `spring.ai.rerank.enabled=true` is set.
32+
* The API key is injected from application properties or environment variables.
33+
*
34+
* @return An instance of RerankerPostProcessor backed by Cohere API
35+
*/
2736
@Bean
2837
@ConditionalOnProperty(name = "spring.ai.rerank.enabled", havingValue = "true")
2938
public DocumentPostProcessor rerankerPostProcessor() {
3039
return new RerankerPostProcessor(CohereApi.builder().apiKey(apiKey).build());
3140
}
41+
42+
/**
43+
* Provides a fallback DocumentPostProcessor when reranking is disabled
44+
* or no custom implementation is registered.
45+
*
46+
* This implementation performs no reranking and simply returns the original list of documents.
47+
* If additional post-processing is required, a custom bean should be defined.
48+
*
49+
* @return A pass-through DocumentPostProcessor that returns input as-is
50+
*/
51+
@Bean
52+
@ConditionalOnMissingBean
53+
public DocumentPostProcessor noOpPostProcessor() {
54+
return (query, documents) -> documents;
55+
}
3256
}

0 commit comments

Comments
 (0)