8Approximate search: how much recall does the index give up?
Verbs:search (approximate, through the HNSW sidecar (Malkov and Yashunin 2020)) · search(exact=True) · [embedding.ann] search_expansion · Background: approximate vs exact nearest-neighbour search and the recall-vs-speed trade (Johnson, Douze, and Jégou 2021) · Checked: measurement (the index’s recall against the engine’s own exact search).
Every search goes through the embedding table’s ANN index: a hierarchical navigable small-world graph (Malkov and Yashunin 2020) the engine builds beside each table, which finds near neighbours by walking a graph instead of scoring every vector. That is what keeps search fast as a corpus grows — and it is approximate. The question a practitioner asks before trusting it is simple: on my embeddings, how many of the true nearest neighbours does the index return?
The engine answers it directly. search(exact=True) scores every vector and returns the true nearest neighbours; the default search walks the index. The overlap between the two is the index’s recall(Johnson, Douze, and Jégou 2021).
import tempfileimport timefrom pathlib import Pathimport jammifrom jammi_cookbook import datasets, encoders, keystone, scalefrom jammi_cookbook.claims import claimSCALE = scale.current()MODEL = encoders.text(SCALE)K =10home = Path(tempfile.mkdtemp())db = jammi.connect(f"file://{home}")arxiv = datasets.arxiv(db, SCALE)table = keystone.embed(db, arxiv, SCALE)titles = db.sql(f"SELECT title FROM {arxiv.papers}.public.{arxiv.papers} ORDER BY paper_id LIMIT 200").column("title").to_pylist()queries = [db.encode_query(model=MODEL, query=t) for t in titles]papers = db.sql(f"SELECT COUNT(*) FROM {arxiv.papers}.public.{arxiv.papers}").column(0)[0].as_py()print(f"{papers} papers indexed · {len(queries)} title queries · k = {K}")
2026-10-03T07:41:51.388572Z WARN jammi_kernels::admission: fused-kernel domain check failed; falling back to the eager composition op="attention_block_fused" predicate="head_dim_is_attention_block_fixed_head_dim"
400 papers indexed · 200 title queries · k = 10
8.1 Exact vs approximate, query by query
The exact answer is the baseline. For each query, recall@k is the fraction of the exact top-k the index also returned — order-insensitive, one number per query, averaged.
def top(db, query, **how) ->set[str]: hits = db.search(arxiv.papers, query=query, k=K, embedding_table=table, **how)returnset(hits.column("_row_id").to_pylist())exact = [top(db, q, exact=True) for q in queries]def recall(db) ->tuple[float, float]:"""Mean recall@k of the approximate search against `exact`, and queries per second.""" start = time.perf_counter() found = [top(db, q) for q in queries] qps =len(queries) / (time.perf_counter() - start)returnsum(len(f & e) / K for f, e inzip(found, exact)) /len(queries), qpsdefault_recall, default_qps = recall(db)print(f"recall@{K} at the default search effort: {default_recall:.3f}")db.close()
recall@10 at the default search effort: 0.978
claim("the default search finds nearly every true neighbour", default_recall >=0.95,f"recall@{K}{default_recall:.3f}")
✓ the default search finds nearly every true neighbour (recall@10 0.978)
8.2 The dial — search effort against recall
HNSW search keeps a candidate list as it walks the graph; search_expansion (HNSW’s ef) is that list’s width — at least k, since the list holds the results. A wider list explores more of the graph: more of the true neighbours found, more work per query. It is a query-time setting: the same index, searched with a different effort. Set in the engine’s configuration, it applies to every search a session makes, so each point below reopens the same catalog with a new [embedding.ann] search_expansion.
curve = {}for ef in (K, 16, 32, 64, 128): config = home /f"ef{ef}.toml" config.write_text(f"[embedding.ann]\nsearch_expansion = {ef}\n")with jammi.connect(f"file://{home}", config=str(config)) as tuned: curve[ef] = recall(tuned)print(f"{'ef':>4}{'recall@10':>12}{'queries/s':>12}")for ef, (r, qps) in curve.items():print(f"{ef:>4}{r:>12.3f}{qps:>12.0f}")
recalls = [r for r, _ in curve.values()]claim("recall never falls as the search widens", recalls ==sorted(recalls))claim("the narrowest search misses neighbours the widest finds", curve[K][0] < curve[128][0],f"recall@{K}{curve[K][0]:.3f} at ef {K}, {curve[128][0]:.3f} at ef 128")
✓ recall never falls as the search widens
✓ the narrowest search misses neighbours the widest finds (recall@10 0.725 at ef 10, 1.000 at ef 128)
Recall climbs with the effort toward the exact answer. The queries-per-second column is measured on whatever machine renders this page, so its absolute values mean little — its shape is the cost side of the trade. The narrowest search visibly gives up neighbours; the default effort recovers most of them. How much any setting gives up depends on the geometry of the embeddings: the small fixture encoder packs every similarity into a narrow band, where many near-equal neighbours make the graph walk slip, while a trained encoder spreads them apart. The practitioner’s rule: measure recall against exact=True on your own data, then pick the lowest effort that clears the bar your application needs.
8.3 Bridge note
An index is a trade, and the engine lets you measure it. Approximate search walks an HNSW graph (Malkov and Yashunin 2020) instead of scoring every vector; search(exact=True) scores every vector. Their overlap is the index’s recall on your embeddings (Johnson, Douze, and Jégou 2021), and search_expansion is the dial that trades it against speed at query time — no rebuild, the same index searched harder.
Johnson, Jeff, Matthijs Douze, and Hervé Jégou. 2021. “Billion-Scale Similarity Search with GPUs.”IEEE Transactions on Big Data 7 (3): 535–47.
Malkov, Yu A., and Dmitry A. Yashunin. 2020. “Efficient and Robust Approximate Nearest Neighbor Search Using Hierarchical Navigable Small World Graphs.”IEEE Transactions on Pattern Analysis and Machine Intelligence 42 (4): 824–36.