Search and vectors · Engineering
Hybrid search: BM25 + vectors + graph
Reciprocal-rank fusion for lexical and vector results, and how graph proximity becomes another ranking signal.
No single search signal is always right. Keyword search is precise when the user knows the term. Vector search handles paraphrases and semantic similarity. Graph proximity captures relationships that neither lexical nor vector distance sees.
NonoDB supports hybrid search at two levels: search_all fuses lexical and vector results with reciprocal-rank fusion (RRF), and hybrid_search combines a vector seed with graph proximity.
Why not just add scores?
BM25 scores and vector distances are not on the same scale. A BM25 score of 4.8 and a cosine distance of 0.08 do not mean the same thing, and the ranges change with the corpus.
RRF avoids that by using ranks instead of raw scores:
score = sum(1 / (rrf_k + rank)) for every source that returned the documentA document that ranks first in both sources gets a higher fused score than a document that ranks first in only one. rrf_k smooths the contribution; the default is 60.
The result includes _score (the fused score) and _sources, which preserves the original rank and score/distance for each source. That makes the ranking inspectable instead of a black box.
Lexical + vector
{ "op": "search_all", "coll": "products", "mode": "hybrid", "query": "coffee grinder", "fields": ["title", "description"], "vector": [0.12, -0.03, 0.44], "vector_field": "embedding", "filter": {"status": "active"}, "skip": 0, "limit": 20, "rrf_k": 60}mode can be lexical, fuzzy, vector, or hybrid.
lexicalandhybridrequirequery;vectorrequiresvector;hybridrequires both;fieldsselects text indexes; if omitted, all text indexes are used;vector_fieldis optional when there is exactly one vector index;filteris a normal document filter applied before pagination;skipandlimitapply after fusion;limitdefaults to 10 and is capped at 1,000.
This is not a learned reranker. It is deterministic rank fusion, which is easier to explain and debug.
Vector + graph
hybrid_search is a different operation. It starts from a vector seed and reranks the graph neighborhood with deterministic score, vector_score, and graph_score values.
That is useful when similarity alone returns plausible but unrelated items. A product embedding may be close, but the graph edge says “bought together” or “same category”. The graph score adds that relationship signal without a separate recommendation service.
The graph definition must exist, and graph reads require scopes on both node and edge collections. Vault collections are rejected.
The Atlas compatibility subset
Applications migrating from MongoDB Atlas can send a small subset of $search, $searchMeta, and $vectorSearch through the aggregation path. It supports text/phrase/equals/range/compound, count metadata, and vector search with filters.
It is a migration bridge, not full Atlas Search parity. Unsupported operators return invalid_query rather than silently falling back.
Limits
search_allreturns at most 1,000 results.- Text and fuzzy indexes cover one field each.
- Fuzzy candidate evaluation is capped at 5,000 documents.
- Hybrid uses RRF, not a learned model.
- Vector search needs ready vectors.
- Search is read-only and never runs in the writer.
- The Atlas compatibility stages must be first in the pipeline.
$searchMetacounts are exact only up to 1,000 documents; otherwisecappedis true.
TTL is enforced before results are returned. Expired documents are filtered from lexical, fuzzy, vector, hybrid, and compatibility results, and the search path over-fetches so an expired hit does not consume the requested limit.
When hybrid helps
Use hybrid search when:
- users type short queries with both keywords and intent;
- the corpus has synonyms or paraphrases that BM25 misses;
- the application already has embeddings;
- you want one ranked result set instead of merging in application code.
Do not assume hybrid always beats lexical. It adds a vector dependency, an embedding pipeline, and a second index to maintain. Measure relevance and latency against a lexical baseline before making it the default.
The search guide has search_all examples and the RRF response shape; graph traversal covers vector-seeded graph reranking.