HybridMind combines Tri-Signal Reciprocal Rank Fusion (RRF), Cross-Encoder Reranking, Multi-Hop Query Decomposition, and Ingest-Time Auto-Edges into a single unified retrieval system for AI memory. This document details the mathematical formulations and algorithms behind each stage of the pipeline.
RRF combines ranked candidate lists from multiple distinct retrieval signals without requiring cross-signal score calibration:
Where:
-
$k = 60$ (standard RRF smoothing constant) -
$r_s(d)$ is the 1-based rank position of document/node$d$ within retrieval signal$s$ -
$w_s$ is the signal weight for signal$s$ :-
$w_{dense}$ : Dense vector similarity rank weight (vector_weight) -
$w_{sparse}$ : BM25 lexical rank weight (bm25_boost_weight) -
$w_{graph}$ : Graph proximity rank weight (graph_weight)
-
route_query() is a regex heuristic for temporal, multi-hop, entity, and
default wording. When routing is enabled it supplies only weights omitted by
the caller; explicit request weights remain authoritative. The current values
are declared in config.py so ledgers can hash them. They are defaults, not
evidence of optimality.
When reranking is enabled, a bounded pool (configured by
config.rerank_pool_size, default 25) is passed to the model named by
settings.reranker_model. Controlled signal-ablation modes bypass downstream
rerankers. Responses and evaluators record whether the cross-encoder was
attempted and actually applied.
To prevent text-only cross-encoders from discarding Graph-discovered candidates that lack direct query term matches, both RRF and Cross-Encoder scores are independently min-max normalized to
Multi-hop questions are decomposed into targeted sub-questions using engine/query_decomposition.py:
FUNCTION decompose_multihop_query(query_text, llm_engine):
prompt = BUILD_DECOMPOSITION_PROMPT(query_text)
sub_questions = llm_engine.generate_json(prompt, schema=DECOMP_SCHEMA)
# Guard 1: Single Sub-Question Guard
IF LENGTH(sub_questions) <= 1:
RETURN [query_text] # Retain original query
# Guard 2: Novel Entity Guard
FOR EACH sq IN sub_questions:
IF sq CONTAINS entities NOT IN query_text:
FILTER sq OUT
RETURN sub_questions
The evaluation helper retrieves the bounded sub-questions and unions candidates by node ID. Decomposition is optional, spends an LLM call, and is not assumed to improve recall without a valid ablation.
The answer helper requests structured snippet-index citations and an answer. Citations constrain the reader prompt but do not substitute for exact source evidence IDs in retrieval scoring.
Before evaluation scoring, candidate answers undergo deterministic normalization:
- Lowercase conversion and punctuation removal
- Strip leading/trailing articles (a, an, the)
- Whitespace collapse
During node ingestion (HYBRIDMIND_AUTO_EDGES_ENABLED=true), cosine similarity edges (similar_to) are automatically inferred for vector pairs satisfying:
scripts/sweep_edge_threshold.py is a threshold-sweep tool. A sweep counts as
evidence only with a stable corpus, gold-independent graph construction, exact
targets, and a completed ledger; a generated plan alone is not a result. It can measure:
- Total edge count added to graph
- 2-hop graph path reachability between multi-hop entity pairs