Skip to content
rushdb
FeaturesUse casesPricingBlogDocsGitHub
Sign InStart free

Agent memory

Agents that remember, and can show where a memory came from.

Company brain & RAG

Answers that span your docs, CRM, support, billing and code, with the record behind every fact.

AI search & assistants

Search and assistants on the records your app already writes.

Analytics

Questions about your data, answered by a read-only query you can inspect.

All use cases →
rushdb

The open-source database for AI. Store any data; your agents always know what’s in it.

GitHubDiscord

Product

FeaturesQuery languagesPricing and CloudSecurity

Use cases

Agent memoryCompany brain & RAGAI search & assistantsAnalytics

Developers

DocsQuick tutorialSelf-hostingTutorialsEngine manualSDKsMCP serverAgent skills

Resources

BlogGuidesComparisonsChangelogllms.txtGitHubContact
PrivacyTermsCookies

Exact vs approximate nearest neighbor: when brute force wins

Exact vs approximate nearest neighbor search, measured: brute force against HNSW build cost, and why RushDB 3.0.15 searches up to 24,000 768-d vectors exactly.

Author
RushDB
Category
Benchmarks
Published
Nov 29, 2026
Reading time
14 min
Contents
  1. └TL;DR
  2. └What is the difference between exact and approximate nearest neighbor search?
  3. └How much did brute force cost per vector in October?
  4. └When does HNSW pay for itself?
  5. └What does RushDB's auto mode do?
  6. └How accurate was ANN in our run?
  7. └What happens with 1M vectors?
  8. └FAQ
  9. └When should I use exact nearest neighbor search instead of HNSW?
  10. └Where does RushDB switch from exact search to HNSW?
  11. └Does RushDB return approximate results without saying so?
  12. └Sources

Contents

  1. └TL;DR
  2. └What is the difference between exact and approximate nearest neighbor search?
  3. └How much did brute force cost per vector in October?
  4. └When does HNSW pay for itself?
  5. └What does RushDB's auto mode do?
  6. └How accurate was ANN in our run?
  7. └What happens with 1M vectors?
  8. └FAQ
  9. └When should I use exact nearest neighbor search instead of HNSW?
  10. └Where does RushDB switch from exact search to HNSW?
  11. └Does RushDB return approximate results without saying so?
  12. └Sources
░░░░░░░░░░░░░░░░░░░░░░░░00%

14 min read

Topics

  • vector-search
  • hnsw
  • benchmarks
  • embeddings
  • rag

Share

  • X.com
  • LinkedIn

Exact vs approximate nearest neighbor search is a trade between query cost and build cost. Brute force scores every vector, returns the true top k and has nothing to build. An HNSW graph answers in about a millisecond, but it has to be built first and kept in memory.

In October we measured about 1.7 µs per 768-d vector for exact search on a pre-release build, and RushDB switched to HNSW above a fixed 5,000 vectors. Exact search has become much faster since, and RushDB 3.0.15 picks the path by cost on every search: an unfiltered 768-d index is searched exactly up to 24,000 vectors at the default ef of 128, and a selective filter keeps far larger indexes exact.

TL;DR

  • October measurement (pre-release 3.0 build, developer workstation, 2026-10-12, ANN ef 64): exact search cost ~1.7 µs per 768-d vector and ~2.6 µs per 1,536-d vector up to 10,000 vectors. HNSW answered in 0.24–1.1 ms per 768-d query once built; the build took 0.12 s at 1,000 vectors, 2.1 s at 5,000 and 47.6 s at 50,000.
  • Exact search got faster in 3.0.7, 3.0.11 and 3.0.13 (a SIMD kernel on several threads, then vectors kept resident in memory). The 3.0.13 release notes give 11.7 ms for an exact top 10 over 100,000 resident 1,536-d vectors, against 1.37 ms for the graph at ef 128.
  • Since 3.0.13, auto compares costs per search. Without a filter the switch is at vectors × dimensions = 144,000 × ef: 24,000 vectors at 768-d and 12,000 at 1,536-d with the default ef of 128. A filtered search uses pool² × dimensions ≤ 26,000 × ef × index vectors instead. Above that it uses HNSW once the graph is resident, and no search waits for a build.
  • On random 768-d vectors, an October laptop run measured recall@10 of 0.63 at ef 64 and 0.84 at ef 256. Embeddings with cluster structure usually do better; measure yours.
  • The graph has to fit in memory. Since 3.0.1 vectors have their own 256 MiB cache, which holds the graph of a 768-d space of about 1.7M vectors; before that, a 1M-vector space fell back to exact search at 4.5 s with one client.

What is the difference between exact and approximate nearest neighbor search?

Exact nearest neighbor search (brute force, flat k-NN) computes the similarity between the query and every stored vector and keeps the top k. Its answer is correct by definition, and its cost grows linearly with the number of vectors. Approximate nearest neighbor (ANN) search walks an index, usually an HNSW graph, and visits only a small part of the data, trading some recall for latency.

HNSW (hierarchical navigable small world) builds a layered proximity graph: each vector links to its near neighbours, and a search hops greedily from a coarse layer down to a fine one. The breadth of the search, ef, sets how many candidates it keeps. Higher ef means better recall and more work.

Exact (brute force)ANN (HNSW)
Recall1.0below 1.0; rises with ef
Query costlinear in vectors scoredroughly flat once built
Build costnoneseconds to minutes; memory for the graph
Filtersscore only the records that passwalk past records that fail; fall back if too few pass
MetricsanyL2, inner product and cosine in most libraries; RushDB builds it for cosine only (dot and euclidean indexes search exactly)

The argument for brute force at small sizes has been made well elsewhere. Doug Turnbull's Just brute force your embeddings (July 2026) measured a NumPy dot product over 1M 384-d vectors at 12 ms average on an M4 MacBook Pro. Different hardware, dimensions and code than ours, so don't compare the numbers directly; the point holds.

How much did brute force cost per vector in October?

In the October run, exact search cost about 1.7 µs per 768-d vector and 2.6 µs per 1,536-d vector, up to 10,000 vectors, or about 9 ms for a 5,000-vector query.

Setup: vector_mode_crossover from the engine's capacity bench, 2026-10-12, on a pre-release 3.0 build, run on a developer workstation with an idle development stack, a different machine from the dedicated host behind our capacity envelope. A fresh durable store per row, random unit vectors, cosine, top 10, 30 warm queries, ANN ef 64. "Cold" is the first query; for ANN it includes building the graph. Storage format v5.

dimsvectorsexact p50ANN p50ANN cold (build + first query)
7681,0001.58 ms0.24 ms124 ms
7685,0008.73 ms0.50 ms2,135 ms
76810,00017.86 ms0.66 ms5,959 ms
76820,00037.61 ms0.80 ms14,570 ms
76850,000166.02 ms1.13 ms47,645 ms
1,5365,00013.00 ms0.82 ms4,124 ms
1,53610,00026.12 ms1.15 ms11,428 ms
1,53650,000293.12 ms3.26 ms184,818 ms

Divide exact p50 by vectors and the per-vector cost is 1.6–1.9 µs for 768-d up to 20,000 vectors, then 3.3 µs at 50,000. At that size the space is about 154 MB of f32, well past the CPU caches; we didn't profile the jump. No ANN search in these runs fell back to exact.

This table is a record of that build, not of 3.0.15. Three releases changed the exact path since:

  • 3.0.7 scores each stored vector in place with one SIMD kernel (AVX2 where the CPU has it) and splits a large search across the server's threads.
  • 3.0.11 keeps a searched space's vectors in memory as f32 rows.
  • 3.0.13 adds each vector's norm and binding to those rows and scores them in one parallel pass.

The 3.0.13 figure above, 11.7 ms for 100,000 resident 1,536-d vectors, works out to about 0.12 µs per vector, roughly a twentieth of the October figure, on a different setup.

ANN builds changed too: since 3.0.11 a build of 50,000 vectors or more inserts from several threads, and a cold build of 1M 768-d vectors went from 24.5 to 5.6 minutes on 20 threads (changelog). We haven't re-run the crossover bench on 3.0.15.

When does HNSW pay for itself?

When exact search over the pool costs more than walking the graph, and the space is stable enough that the build is paid once. In the October table that point came early: HNSW answered at 1 ms or less at every 768-d size up to 20,000, while exact search passed 10 ms between 5,000 and 10,000 vectors.

Simple arithmetic on the October table, not a separate measurement: at 5,000 768-d vectors each ANN query saved about 8.2 ms, so a 2.1 s build was repaid after roughly 260 queries; at 50,000 vectors the saving was about 165 ms per query and the build paid off after about 290. With today's faster exact path the per-query saving at small sizes is close to zero, so there is little to repay a build with. That is why the default threshold moved up.

RushDB 3.0.15 builds this comparison into the router. The unfiltered rule was calibrated on 100,000 × 1,536-d cosine vectors, where exact search took 11.7 ms and a walk at ef 128 took 1.4 ms (3.0.13 changelog); at 768-d and ef 128 it puts the switch at 24,000 vectors. A larger ef makes the walk dearer, so it moves the switch up: at ef 512 an unfiltered 768-d index stays exact up to 96,000 vectors.

There's also memory. The HNSW graph and the resident vectors are both charged to the vector cache (vector-cache-bytes, 256 MiB by default).

The graph's resident part takes about 150 bytes per 768-d vector, and a build reserves about 2 × dimensions + 320 bytes per vector while it runs, in chunks sized to the free budget. The resident f32 rows take dimensions × 4 + 32 bytes per vector, about 3.1 KB at 768-d, so the default budget holds them for about 86,000 768-d vectors. A space whose rows don't fit is scored from storage, more slowly, with the same results (vector internals).

What does RushDB's auto mode do?

auto, the default, searches exactly while the pool is cheap enough to score or the metric isn't cosine. The pool is the records matching the predicate (at most the index's vectors), or the whole index without one. resources.vector-exact-max-pool sets "cheap enough"; its default, auto, compares the two paths' costs from the pool, the index size, the dimensions and the search's ef (vector search docs):

  • without a filter, exact while index vectors × dimensions ≤ 144,000 × ef;
  • with a filter, exact while pool² × dimensions ≤ 26,000 × ef × index vectors. A filtered walk slows down as the filter admits less of the index, so a narrow filter on a large index is scored exactly.
IndexUnfiltered: exact up toFiltered: exact up to (ef 128 / 512)
100,000 × 1,536-d12,000 vectors14,720 / 29,439 matching records
1,000,000 × 768-d24,000 vectors65,828 / 131,656 matching records

Above that, auto uses HNSW once the graph is resident, and answers exactly while the graph builds in the background. Every ANN candidate is re-scored exactly against the stored vector, and with a filter the walk skips records outside it, so every gathered candidate matches.

Diagram

If the graph doesn't fit the vector cache, the search runs exactly and reports budget. A forced mode: "ann" with a filter whose pool is cheap enough to score is answered exactly and reports smallCandidateSet. And mode: "ann" on a dot or euclidean index is refused, because the HNSW path is cosine-only. The filter runs first in every case: the predicate becomes a candidate set before any ranking, so a filtered search never returns fewer results because good matches were dropped after ranking. Filtered vector search covers that part.

A number fixes the threshold instead: vector-exact-max-pool: 20000 scores at most 20,000 vectors exactly whatever the dimensions and ef. Every config.yml written before 3.0.13 holds 5000, which 3.0.13 and later read as auto; write fixed:5000 to keep the old behaviour (configuration reference).

We watched the old fixed threshold switch on a live node (pre-release build of 2026-10-27, in-memory, i9-12900H laptop, 2026-10-31, random 768-d example vectors on Doc records with a lang field, filter lang = "en", top 3). The query:

JSON
{"kind":"vector","query":{"labels":["Doc"],"property":"emb","index":"doc-emb",
  "vector":[0.0213, -0.0441, "… 768 numbers …"],"predicate":{"lang":"en"},"limit":3}}

What vectorSearch and the top hits reported, step by step (record n is a sequence field in the example data):

Text
4,000 vectors, auto   → {"mode":"exact","pool":4000}                          376, 2970, 1353
6,000 vectors, auto   → {"mode":"exact","fallback":"annWarming","pool":6000}  376, 4076, 2970
same, seconds later   → {"mode":"ann","ef":64,"pool":6000}                    376, 4076, 1279
same, mode exact      → {"mode":"exact","pool":6000}                          376, 4076, 2970

The ANN answer missed the true third match (2970) and returned 1279 instead. That's what recall below 1.0 looks like in one query.

On 3.0.15 the same query stays exact at both sizes: about a third of the 6,000 records match lang = "en", far inside the filtered rule (and 6,000 × 768 is inside the unfiltered one too), and pool now reports those matching records, not the index's 6,000. To see the graph on a space this small today, send mode: "ann" without a filter. The dot index, asked for ANN, is refused with the same message on both builds:

JSON
{"code":"invalid_request","message":"vector search mode `ann` requires a cosine index; this index uses `dot` (use `exact` or `auto`)","retryable":false}

How accurate was ANN in our run?

On the same laptop node, 50 random queries against 6,000 random unit 768-d vectors, comparing mode: "ann" with mode: "exact" top 10: recall@10 was 0.63 at ef 64 and 0.84 at ef 256, with or without the lang filter. Server time was about 1 ms for ANN and 13 ms for exact search.

effilterrecall@10exact p50ANN p50
64none0.6313 ms1 ms
64lang = en (~⅓)0.6511 ms4 ms
256none0.8413 ms1 ms
256lang = en0.8311 ms5 ms

Read this as a worst case, not as RushDB's recall. Random unit vectors in 768 dimensions have no cluster structure, which is the hardest input for any proximity graph, and real embeddings usually score higher. It's one run on a laptop that had other work on it.

The build was also older than two changes to ef. Before 3.0.7 a walk kept at least 128 candidates whatever ef asked for, so these ef 64 rows don't map one-to-one onto today's ef 64, which walks only 64. The default ef is now 128 (resources.vector-default-ef). The method is short (50 queries in both modes, compare the returned ids), so run it on your own embeddings before choosing ef. On 3.0.15 a 6,000-vector 768-d index is searched exactly by default, with recall 1.0, so the trade only starts to matter above the switch point.

What happens with 1M vectors?

A 1M × 768-d index is far past the unfiltered switch (24,000 vectors at ef 128), so unfiltered searches use the graph. A filter matching up to about 65,800 of those records is scored exactly. The graph has to fit in memory: at about 150 bytes of vector cache per 768-d vector, the default vector-cache-bytes of 256 MiB holds a space of about 1.7M vectors; past that, searches run exactly and report budget, and raising the setting fixes it (troubleshooting).

The resident f32 rows of 1M 768-d vectors (about 3.1 GB) don't fit the default budget, so exact searches and the re-score read those vectors from storage.

A cold build of that space takes minutes: 5.6 minutes on 20 threads in the 3.0.11 release notes. Searches during the build answer exactly with annWarming. After a restart the graph is reopened from its persisted segments, and only vectors no segment covers are decoded again. The capacity planning table for one 768-d space gives a settled search p50 of 1.8 ms at 10K vectors, 7.2 ms at 50K and 21.6 ms at 150K, slower right after a bulk bind while segments merge.

The separate vector budget is new in 3.0.1. Before it, the graph shared a 128 MiB cache with the text and planner caches, and in our capacity run (i9-12900H bench host, 2026-10-19, storage format v5) a 1M-vector space didn't fit. Every search fell back to exact, at 4.5 s with one client and 58 s p50 with 32 concurrent clients. With the graph resident (a 384 MiB cache on the same store) one-client searches took about 62 ms. Since 3.0.1 the same space answers from its index on default settings.

Trade-offs to know:

  • ANN is HNSW (via USearch) with cosine only; dot and euclidean indexes always search exactly.
  • The graph may hold vectors at 16-bit precision; results are always re-scored with the stored 32-bit vectors. An 8-bit graph was tested in 3.0.14 and not made the default, because its recall was lower at small ef.
  • Spaces past about 1.7M 768-d vectors need a larger vector-cache-bytes.
  • RushDB stores and searches vectors; it never calls an embedding model. You bring the vectors.

Combining vector scores with BM25 is a separate step, covered in hybrid search: RRF vs DBSF .

FAQ

When should I use exact nearest neighbor search instead of HNSW?

When the candidate set is small enough that scoring it costs less than a graph walk. On RushDB 3.0.15 that is up to 24,000 768-d or 12,000 1,536-d vectors per unfiltered index at the default ef, and more for a selective filter on a large index. Exact search then has perfect recall and needs no build and no graph memory.

Where does RushDB switch from exact search to HNSW?

Since 3.0.13 there is no fixed count. auto searches exactly while index vectors × dimensions ≤ 144,000 × ef without a filter, or pool² × dimensions ≤ 26,000 × ef × index vectors with one. Releases before 3.0.13 used a fixed 5,000 vectors, chosen from the October measurement. Set resources.vector-exact-max-pool to a number, or fixed:5000 for the old value, to pin it.

Does RushDB return approximate results without saying so?

No. Each vector response carries vectorSearch with the mode used (exact or ann), ef for ANN, the pool the search could score, and a fallback reason (annWarming, lowConfidence, budget or smallCandidateSet) when a search that would have used the graph was answered exactly. describe.explainVector reports the same decision before you search. ANN candidates are always re-scored exactly, so scores are true cosine similarities even when the set is approximate.

Sources

  • Vector search (RushDB engine docs)
  • Vector internals
  • Configuration reference (vector-exact-max-pool, vector-default-ef, vector-cache-bytes)
  • Capacity planning
  • Troubleshooting: vector search is slow or exact
  • RushDB engine changelog at v3.0.15 (3.0.1 vector cache, 3.0.7 ef and exact kernel, 3.0.11 resident vectors and parallel builds, 3.0.13 cost-based routing)
  • Malkov and Yashunin (2016), the HNSW paper on arXiv
  • USearch
  • Doug Turnbull: Just brute force your embeddings

RushDB

Precision your agents can query.

RushDB is a self-describing, graph-native database that helps AI agents reason over data with confidence: progressively introspect what's queryable—without guesswork.

Start free →

Related reading

  1. Nov 29, 2026Filtered vector search: pre-filter vs post-filter, measured14 min
  2. Nov 29, 2026Hybrid search explained: RRF vs DBSF with worked scores11 min
  3. Nov 29, 2026RushDB capacity: one node from 200K to 30M records13 min