Table of Contents

Class HybridRetrievalStrategy

Namespace
LMKit.Retrieval
Assembly
LM-Kit.NET.dll

A retrieval strategy that combines vector (semantic) search and BM25 (keyword) search, fusing the results with weighted Reciprocal Rank Fusion (RRF) for improved recall.

public sealed class HybridRetrievalStrategy : IRetrievalStrategy
Inheritance
HybridRetrievalStrategy
Implements
Inherited Members

Examples

// Use default sub-strategies with equal weight
ragEngine.RetrievalStrategy = new HybridRetrievalStrategy();

// Favor vector search over keyword search
ragEngine.RetrievalStrategy = new HybridRetrievalStrategy
{
    VectorWeight = 0.7f,
    KeywordWeight = 0.3f
};

// Or customize the BM25 parameters
var bm25 = new Bm25RetrievalStrategy { K1 = 1.5f, B = 0.5f };
ragEngine.RetrievalStrategy = new HybridRetrievalStrategy(
    new VectorRetrievalStrategy(), bm25);

Remarks

Hybrid search addresses the fundamental limitation of single-modality retrieval: vector search captures semantic similarity but can miss exact keyword matches, while BM25 excels at lexical matching but misses paraphrases and synonyms. By fusing both ranked lists, hybrid search delivers consistently higher recall.

Both sub-strategies run independently and their results are merged using Reciprocal Rank Fusion (RRF), which is rank-based and does not require score normalization across strategies. The VectorWeight and KeywordWeight properties control the relative influence of each sub-strategy in the fused ranking.

Constructors

HybridRetrievalStrategy()

Initializes a new instance of the HybridRetrievalStrategy class with default sub-strategies.

HybridRetrievalStrategy(IRetrievalStrategy, IRetrievalStrategy)

Initializes a new instance of the HybridRetrievalStrategy class with custom sub-strategies.

Properties

KeywordStrategy

Gets the strategy used for keyword (lexical) retrieval.

KeywordWeight

Gets or sets the weight applied to the keyword (lexical) strategy during Reciprocal Rank Fusion.

RequiresQueryVector

Gets a value indicating whether the strategy requires a query embedding vector.

RrfK

Gets or sets the RRF smoothing constant that controls the influence of rank position in the fusion score.

VectorStrategy

Gets the strategy used for vector (semantic) retrieval.

VectorWeight

Gets or sets the weight applied to the vector (semantic) strategy during Reciprocal Rank Fusion.

Methods

RetrieveAsync(IReadOnlyList<DataSource>, string, float[], int, float, bool, bool, DataFilter, CancellationToken)

Retrieves matching partitions from the given data sources.

See Also

Share