Class RagChunkPostProcessor

java.lang.Object
sk.iway.iwcm.rag.search.RagChunkPostProcessor

public class RagChunkPostProcessor extends Object
Post-processing pipeline for RAG retrieved chunks. Steps: 1. Select top-K chunks by similarity, then apply soft minimum similarity filter 2. Sort by entityId, then chunkIndex 3. Group by entityId 4. Merge adjacent chunks within each group (removing sliding-window overlap) 5. Limit output to maxBlocks / maxCharacters Similarity is used for ranking and soft filtering, never as hard truth. The pipeline never returns zero chunks when decent top results exist.
  • Constructor Details

    • RagChunkPostProcessor

      public RagChunkPostProcessor(int topK, double minSimilarity, int maxChunkGap, int maxBlocks, int maxCharacters, int maxMergedBlockCharacters)
      Parameters:
      topK - number of top chunks considered for context before adaptive thresholding is applied
      minSimilarity - soft similarity threshold; chunks below this are dropped only if enough top chunks remain
      maxChunkGap - maximum gap between chunkIndex values to still merge (1 = adjacent only)
      maxBlocks - maximum number of merged context blocks to return
      maxCharacters - maximum total characters across all returned blocks
      maxMergedBlockCharacters - maximum characters in a single merged block; prevents unbounded merging
  • Method Details

    • process

      public List<MergedContextBlock> process(List<VectorSearchResult> chunks)
      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