Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Heuristic:0xranx OpenContext RRF Weight Tuning

From Leeroopedia
Knowledge Sources
Domains Search, Optimization
Last Updated 2026-10-24 10:00 GMT

Overview

Hybrid search weight tuning using RRF (Reciprocal Rank Fusion) with vector weight 0.7 and keyword weight 0.3, with RRF constant k=60.

Description

OpenContext's hybrid search combines vector (semantic) and keyword (BM25) search results using Reciprocal Rank Fusion (RRF). The fusion formula is `RRF(d) = Σ weight_i / (k + rank_i(d))` where k=60 is the standard RRF constant. Vector search is weighted at 0.7 and keyword search at 0.3, reflecting the design decision that semantic similarity is generally more relevant than exact keyword matches for knowledge base discovery. Results that appear in both sources get combined scores, naturally boosting documents that match both semantically and lexically.

Usage

Use this heuristic when tuning hybrid search relevance. If users report that semantic matches are too dominant, increase `keywordWeight`. If exact keyword matches are being drowned out, decrease `vectorWeight`. The weights are configurable in the `NativeSearcher` constructor.

The Insight (Rule of Thumb)

  • Action: Set `vectorWeight = 0.7` and `keywordWeight = 0.3` for hybrid search.
  • Value: `RRF_K = 60.0`, `VECTOR_WEIGHT = 0.7`, `KEYWORD_WEIGHT = 0.3`
  • Trade-off: Higher vector weight improves semantic recall but may miss exact keyword matches. Higher keyword weight improves precision for exact terms but loses semantic nuance.
  • Compatibility: Weights are used only in hybrid mode; pure vector or pure keyword mode ignores them.

Reasoning

RRF is rank-based (not score-based), making it robust to different score distributions between vector cosine distance and BM25 scores. The k=60 constant is the standard value from the original RRF paper, providing good balance between top-ranked and mid-ranked results. The 0.7/0.3 split favors semantic search because:

  1. Knowledge base queries are often exploratory, where semantic intent matters more than exact wording.
  2. Keyword search serves as a "safety net" to ensure exact matches (e.g., function names, file paths) are not lost.
  3. Documents appearing in both result sets get a combined score, effectively boosting consensus matches.

Code Evidence

RRF constants from `crates/opencontext-core/src/search/searcher.rs:12-19`:

/// RRF constant, typically 60
const RRF_K: f32 = 60.0;

/// Vector search weight in hybrid mode
const VECTOR_WEIGHT: f32 = 0.7;

/// Keyword search weight in hybrid mode
const KEYWORD_WEIGHT: f32 = 0.3;

Configurable weights in Node.js adapter from `src/core/search/native-adapter.js:19-24`:

class NativeSearcher {
  constructor(options = {}) {
    this.vectorWeight = options.vectorWeight ?? 0.7;
    this.keywordWeight = options.keywordWeight ?? 0.3;
  }
}

RRF fusion formula from `searcher.rs:366-368`:

let rrf_score = VECTOR_WEIGHT / (RRF_K + index as f32 + 1.0);

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment