Package com.tnsai.intelligence.rag
Class HierarchicalRAGStrategy
java.lang.Object
com.tnsai.intelligence.rag.HierarchicalRAGStrategy
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault maximum number of parent edges expanded from a child hit.static final doubleDefault relevance multiplier applied at every parent level. -
Constructor Summary
ConstructorsConstructorDescriptionHierarchicalRAGStrategy(RAGStrategy childStrategy, HierarchyIndex index, Set<String> allowedSources, int maxDepth, double parentScoreDecay) Creates a hierarchical retrieval strategy. -
Method Summary
Modifier and TypeMethodDescriptionname()Returns the unique name of this strategy (e.g., "vector", "keyword", "hybrid").retrieve(String query, RAGContext context) Retrieves documents relevant to the given query.
-
Field Details
-
DEFAULT_MAX_DEPTH
public static final int DEFAULT_MAX_DEPTHDefault maximum number of parent edges expanded from a child hit.- See Also:
-
DEFAULT_PARENT_SCORE_DECAY
public static final double DEFAULT_PARENT_SCORE_DECAYDefault 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 hitsindex- hierarchy documents and parent relationshipsallowedSources- selected source groups; empty allows all groupsmaxDepth- maximum parent edges expanded from each hitparentScoreDecay- relevance multiplier per parent edge
-
-
Method Details
-
name
Description copied from interface:RAGStrategyReturns the unique name of this strategy (e.g., "vector", "keyword", "hybrid").Names are compared case-insensitively using
Locale.ROOT.- Specified by:
namein interfaceRAGStrategy- Returns:
- the strategy name, never null
-
retrieve
Description copied from interface:RAGStrategyRetrieves 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:
retrievein interfaceRAGStrategy- 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
-