Class HierarchicalRAGStrategy

java.lang.Object
com.tnsai.intelligence.rag.HierarchicalRAGStrategy
All Implemented Interfaces:
RAGStrategy

public final class HierarchicalRAGStrategy extends Object implements RAGStrategy
Expands ranked child hits through a deterministic parent hierarchy.

The child strategy selects relevant leaf or section hits. This strategy then walks immediate parents, applies score decay per level, deduplicates shared ancestors through their best path, and emits stable provenance. Parent expansion never leaves a non-empty source fence.

Since:
0.13.0
  • Field Details

    • DEFAULT_MAX_DEPTH

      public static final int DEFAULT_MAX_DEPTH
      Default maximum number of parent edges expanded from a child hit.
      See Also:
    • DEFAULT_PARENT_SCORE_DECAY

      public static final double DEFAULT_PARENT_SCORE_DECAY
      Default relevance multiplier applied at every parent level.
      See Also:
  • Constructor Details

    • HierarchicalRAGStrategy

      public HierarchicalRAGStrategy(RAGStrategy childStrategy, HierarchyIndex index, Set<String> allowedSources, int maxDepth, double parentScoreDecay)
      Creates a hierarchical retrieval strategy.
      Parameters:
      childStrategy - strategy that selects initial child hits
      index - hierarchy documents and parent relationships
      allowedSources - selected source groups; empty allows all groups
      maxDepth - maximum parent edges expanded from each hit
      parentScoreDecay - relevance multiplier per parent edge
  • Method Details

    • name

      public String name()
      Description copied from interface: RAGStrategy
      Returns the unique name of this strategy (e.g., "vector", "keyword", "hybrid").

      Names are compared case-insensitively using Locale.ROOT.

      Specified by:
      name in interface RAGStrategy
      Returns:
      the strategy name, never null
    • retrieve

      public List<RetrievedDocument> retrieve(String query, RAGContext context)
      Description copied from interface: RAGStrategy
      Retrieves documents relevant to the given query.

      Every returned document must exactly match all metadata filters in the context. Implementations apply that constraint before limiting the result to RAGContext.maxResults().

      Specified by:
      retrieve in interface RAGStrategy
      Parameters:
      query - the search query (never null)
      context - retrieval parameters (max results, min score, exact metadata filters)
      Returns:
      an unmodifiable list of retrieved documents, sorted by descending relevance