Package sk.iway.iwcm.rag.search
Class RagChunkPostProcessor
java.lang.Object
sk.iway.iwcm.rag.search.RagChunkPostProcessor
Post-processing pipeline for RAG retrieved chunks.
Steps:
1. Select distinct top-K chunks by ranking score, then apply soft minimum similarity filter
2. Sort by entityId, then chunkIndex
3. Group by entity type and entity ID
4. Merge adjacent chunks within each group (removing sliding-window overlap)
5. Limit output to maxBlocks / maxCharacters
Local ranking controls order; original similarity controls soft filtering, never as hard truth.
The pipeline never returns zero chunks when decent top results exist.
-
Constructor Summary
ConstructorsConstructorDescriptionRagChunkPostProcessor(int topK, double minSimilarity, int maxChunkGap, int maxBlocks, int maxCharacters, int maxMergedBlockCharacters) Configures context ranking, merging, and output limits. -
Method Summary
Modifier and TypeMethodDescriptionprocess(List<VectorSearchResult> chunks) Run the full post-processing pipeline on retrieved chunks.
-
Constructor Details
-
RagChunkPostProcessor
public RagChunkPostProcessor(int topK, double minSimilarity, int maxChunkGap, int maxBlocks, int maxCharacters, int maxMergedBlockCharacters) Configures context ranking, merging, and output limits.- Parameters:
topK- number of top chunks considered for context before adaptive thresholding is appliedminSimilarity- soft similarity threshold; chunks below this are dropped only if enough top chunks remainmaxChunkGap- maximum gap between chunkIndex values to still merge (1 = adjacent only)maxBlocks- maximum number of merged context blocks to returnmaxCharacters- maximum total characters across all returned blocksmaxMergedBlockCharacters- maximum characters in a single merged block; prevents unbounded merging
-
-
Method Details
-
process
Run the full post-processing pipeline on retrieved chunks.- Parameters:
chunks- raw vector search results- Returns:
- merged, filtered, and limited context blocks ready for the LLM prompt
-