Class HybridRAGStrategy
- All Implemented Interfaces:
RAGStrategy
GraphRAGStrategy is supplied — knowledge-graph hits via
Reciprocal Rank Fusion (RRF).
The strategy name stays hybrid. A missing graph capability
does not degrade to VECTOR-only: BM25 and vector still fuse, and
graphStream() reports HybridGraphStream.SKIPPED_NO_GRAPH_STORE.
Unweighted RRF uses ReciprocalRankFusion.DEFAULT_K (60).
Two-stream construction still delegates to HybridMemoryRetriever
so existing lexical/semantic scores stay unchanged. The three-stream
constructor ranks each source independently, then fuses the lists.
Scores are normalized to 0.0..1.0 against the number of
non-empty streams before RAGContext.minScore() applies.
- Since:
- 0.2.4
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringMetadata key forHybridGraphStream.metadataValue().static final StringMetadata key listing the streams that contributed to a hit.static final StringProvenance token for the BM25 stream.static final StringProvenance token for the graph stream.static final StringProvenance token for the vector stream. -
Constructor Summary
ConstructorsConstructorDescriptionHybridRAGStrategy(com.tnsai.memory.advanced.BM25Index bm25Index, com.tnsai.memory.advanced.VectorMemoryStore vectorStore) Creates a two-stream hybrid strategy from BM25 and vector stores.HybridRAGStrategy(com.tnsai.memory.advanced.BM25Index bm25Index, com.tnsai.memory.advanced.VectorMemoryStore vectorStore, GraphRAGStrategy graphStrategy) Creates a three-stream hybrid strategy that RRF-fuses BM25, vector, and graph rankings.HybridRAGStrategy(com.tnsai.memory.advanced.HybridMemoryRetriever hybridRetriever) Creates a two-stream hybrid strategy with a pre-configured retriever. -
Method Summary
Modifier and TypeMethodDescriptionHow the optional graph stream was handled for this instance.name()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
-
METADATA_STREAMS
Metadata key listing the streams that contributed to a hit.- See Also:
-
METADATA_GRAPH_STREAM
Metadata key forHybridGraphStream.metadataValue().- See Also:
-
STREAM_BM25
Provenance token for the BM25 stream.- See Also:
-
STREAM_VECTOR
Provenance token for the vector stream.- See Also:
-
STREAM_GRAPH
Provenance token for the graph stream.- See Also:
-
-
Constructor Details
-
HybridRAGStrategy
public HybridRAGStrategy(com.tnsai.memory.advanced.BM25Index bm25Index, com.tnsai.memory.advanced.VectorMemoryStore vectorStore) Creates a two-stream hybrid strategy from BM25 and vector stores.Uses the default RRF constant (k=60). The graph stream is skipped with
HybridGraphStream.SKIPPED_NO_GRAPH_STORE.- Parameters:
bm25Index- the BM25 keyword indexvectorStore- the vector similarity store
-
HybridRAGStrategy
public HybridRAGStrategy(com.tnsai.memory.advanced.HybridMemoryRetriever hybridRetriever) Creates a two-stream hybrid strategy with a pre-configured retriever.- Parameters:
hybridRetriever- the hybrid retriever to use
-
HybridRAGStrategy
public HybridRAGStrategy(com.tnsai.memory.advanced.BM25Index bm25Index, com.tnsai.memory.advanced.VectorMemoryStore vectorStore, GraphRAGStrategy graphStrategy) Creates a three-stream hybrid strategy that RRF-fuses BM25, vector, and graph rankings.- Parameters:
bm25Index- the BM25 keyword indexvectorStore- the vector similarity storegraphStrategy- source-fenced graph traversal used as the third list- Since:
- 0.14.0
-
-
Method Details
-
graphStream
How the optional graph stream was handled for this instance.- Returns:
- fused or skipped-without-store
- Since:
- 0.14.0
-
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
-