Skip to content

combineResults

combineResults(vectorResults, bm25Results, alpha, similarityTopK): VectorStoreQueryResult

Defined in: packages/core/src/vector-store/rrf.ts:74

Combines vector search results and BM25 results using Reciprocal Rank Fusion (RRF).

RRF is score-agnostic - it only considers the rank position of documents, not their raw scores. This makes it robust when combining results from different scoring systems (like cosine similarity and BM25) that have incompatible score ranges.

The formula for each document is: score = alpha × rrf(vectorRank) + (1 - alpha) × rrf(bm25Rank)

Where: rrf(rank) = 1 / (k + rank)

Documents appearing in both result sets get scores from both, giving them a natural boost over documents appearing in only one result set.

VectorStoreQueryResult

Results from vector similarity search

VectorStoreQueryResult

Results from BM25 keyword search

number

Weight for vector results (0 = pure BM25, 1 = pure vector, 0.5 = balanced)

number

Number of results to return

VectorStoreQueryResult

Combined results sorted by RRF score

const hybridResults = combineResults(
vectorSearchResults,
bm25SearchResults,
0.5, // Equal weight to both
10 // Return top 10
);