Send Feedback
Skip to content

Hybrid Search

This page describes the parameters for hybrid search as part of AI libs.

Hybrid search leverages the power of keyword and semantic searches by combining sparse vectors with dense vectors.

.ai.hybrid.rrf

The .ai.hybrid.rrf function applies Reciprocal Ranked Fusion (RRF) to combine results from multiple search strategies.

By merging ranked lists and scoring items based on their positions across sources, it produces a unified, balanced ranking. RRF is particularly effective when blending different retrieval methods, improving robustness and overall relevance of search results.

Parameters

Name Type(s) Description
results (real[]; long[])[] | int[][] | long[][] The list of nearest neighbor results from bm25 or dense search
const int | long | real | float The constant term for RRF (typically 60)

Returns

Type Description
long[] Re-ranked IDs

Example

q).ai:use`kx.ai
q)a:101 102 103 104 105;
q)b:103 106 101 107 108;
q).ai.hybrid.rrf[(a;b);60];

101 103 102 106 104 107 105 108

The example defines two ranked result lists (a and b) from different search strategies and fuses them using Reciprocal Rank Fusion with a constant of 60. The combined ranking (101 103 102 106 ...) balances contributions from both lists, giving higher priority to items that appear near the top of either list. This demonstrates how .ai.hybrid.rrf produces a unified ranking that improves robustness by blending multiple retrieval sources.

.ai.hybrid.wrrf

The .ai.hybrid.wrrf function applies weighted reciprocal ranked fusion on search results.

This function extends Reciprocal Ranked Fusion (RRF) by applying weights to the contributing search results. Weighted RRF (wRRF) allows greater influence from selected retrieval methods, tailoring the final ranking to specific needs or priorities. It provides more control than standard RRF, making it useful in applications where certain search strategies are more reliable or domain-relevant.

Parameters

Name Type(s) Description
results (real[]; long[])[] | int[][] | long[][] The list of nearest neighbor results from bm25 or dense search
weights long[] The list of weightings, same length as results
const nt | long | real | float The constant term for RRF (typically 60)

Returns

Type Description
long[] Re-ranked IDs

Example

q).ai:use`kx.ai
q)a:101 102 103 104 105;
q)b:103 106 101 107 108;
q).ai.hybrid.wrrf[(a;b);1 2;60];

103 101 106 107 108 102 104 105

Here, the same two ranked lists are fused, but .ai.hybrid.wrrf applies weights (1 for list a and 2 for list b). The output prioritizes items favored by list b, as seen by 103 and 101 rising to the top. This shows how weighted RRF enables fine-tuning of influence across search strategies, giving more control over the final combined ranking.

Next steps