Performance workbook
Questions people ask about the performance of duckdb-vectors, answered with measured figures first and the explanation after. All figures come from one reference machine, a MacBook Pro M1 (2021), with the embedding model already loaded. They use two kinds of corpus: synthetic ones generated by the benchmark scripts, which anyone can reproduce, and a real corpus of 247 Markdown files of engineering documentation (5,172 chunks), which grounds the numbers in everyday use. Network round-trip figures are engineering estimates and are labelled as such. How to reproduce these numbers? lists the commands.
How big is the index file?
About 2.4 KB per chunk at the default model, so the file stays small next to anything it ships inside:
| Chunks | Database file |
|---|---|
| 1,000 | ~4.8 MB |
| 10,000 | ~26 MB |
| 50,000 | ~114 MB |
| 100,000 | ~235 MB |
| 5,172 (the real corpus) | ~17 MB |
The synthetic chunks are ~300 words each, the Markdown chunker's default target. Each chunk stores its text, a FLOAT[256] vector (256 × 4 = 1,024 bytes with the default local:minishlab/potion-multilingual-128M), an etag, a title, its metadata as JSON, and its entry in the keyword (BM25) index. The vector term grows with the model's dimension: 1,536 bytes at 384 dims, 4,096 bytes at 1,024 dims. Storage grows linearly with chunk count and is never the constraint: even 100,000 chunks fit in a few hundred megabytes, and because the file travels inside the agent's container image there is no separate data tier to provision, secure, or pay for.
How fast is a query?
~26 ms (p50) and ~31 ms (p95) for a full hybrid query() with top_k=5 over 1,000 chunks, at the default model. Embedding the query takes ~0.3 ms of that:
| Slice | Time | Share |
|---|---|---|
| Query embedding | ~0.3 ms | ~1% |
| Hybrid scan (cosine + BM25 + fusion + fetch) | ~25.5 ms | ~99% |
The default model is static: it maps tokens to fixed vectors with no transformer forward pass, so the embed slice is effectively free and latency is almost entirely the scan. The tail stays close to the median because there is no network hop to stall on.
How does query time grow with the corpus?
Linearly, from a fixed floor of about 20 ms:
| Chunks | Query p50, default model | Query p95, default model | Query p50, scan only (hashing) |
|---|---|---|---|
| 1,000 | 25.8 ms | 31.4 ms | 19.4 ms |
| 10,000 | 33.7 ms | 35.8 ms | 30.1 ms |
| 50,000 | 68.3 ms | ~170 ms | 73.3 ms |
| 100,000 | 104-108 ms | 110-143 ms | 122.3 ms |
The brute-force cosine scan is the only term that grows with chunk count, at roughly 1 ms per 1,000 chunks; the keyword scan, Reciprocal Rank Fusion, and the fetch of the top chunks form the fixed floor. The hashing column isolates that scan curve with an embedder that costs nothing. Medians are stable across runs; the p95 tail at 50,000 chunks and above varied between runs (140-170 ms), so treat it as indicative.
How long does a first index take?
~3.6 s for the real corpus (247 files, 5,172 chunks), and ~2.0 s for the synthetic one (250 files, 1,590 chunks), at the default model:
| Corpus | Files | Chunks | First index | File locked |
|---|---|---|---|---|
| Real engineering documentation | 247 | 5,172 | 3.6 s | 1.8 s |
| Synthetic (seed 20261103) | 250 | 1,590 | 2.0 s | 0.6 s |
A first index chunks every file, embeds every chunk, writes them, and builds the keyword index. Chunking is fast because one DuckDB connection serves every Markdown file of a run, and writing is fast because each batch is one DELETE and one INSERT per 5,000 rows rather than two statements per chunk. With the default static model, embedding is cheap too; a contextual model makes embedding the dominant cost (see Which model and dimension should I choose?). These figures exclude the one-time downloads of a first launch: the package, the embedding model, and the DuckDB markdown and fts extensions.
What does a restart cost?
~1 s for an unchanged folder, with nothing re-embedded or written, which is what an MCP server started with --index pays on every launch:
| Real corpus (247 files, 5,172 chunks) | Time | Rows written | File locked |
|---|---|---|---|
| Re-index, unchanged | 1.05 s | 0 | 0.017 s |
| Re-index, one file edited | 1.20 s | 1 | 0.22 s |
The indexer re-reads and re-chunks the folder, compares each chunk's fingerprint (etag) and stored fields with what is in the database, and embeds and writes only what changed. The time is the chunking pass; the database file is locked only for the lookup and the writes, so other sessions sharing it keep querying.
How fast is search through the MCP server?
~45 ms per search after the first, and ~2 s for the first one, which loads the embedding model; report takes ~40 ms. Measured over stdio against the real corpus:
| Call | Time |
|---|---|
First search (model load) | ~2.1 s |
Later search (median of 15) | ~45 ms, max ~70 ms |
report | ~40 ms |
The server keeps one embedder for its lifetime, so the model loads once, while each call opens and closes its own store. The ~20 ms above an in-process query is the MCP round-trip plus opening the store.
Can several sessions share one index?
Yes. Measured with two processes querying one database file at once, every query succeeded (15 of 15 each), and so did every query issued while a third process re-indexed (10 of 10). DuckDB lets one process hold a file at a time, so a store connects only when a call needs the file and waits up to lock_timeout seconds (default 10, DUCKDB_VECTORS_LOCK_TIMEOUT) when another process holds it. Each search holds the file for the length of the call, and an unchanged re-index holds it for about 0.02 s, so sessions wait milliseconds rather than fail.
How fast is writing from code?
~4 s for 10,000 chunks and ~20 s for 50,000, added through add_texts in batches of 2,000 (hashing backend, so the figures isolate the writes). The keyword index is not rebuilt per call: writes mark it stale in the database file, and it is rebuilt once, when the store closes or on the first keyword search that finds it stale. That rebuild takes ~0.09 s for 50,000 chunks. Close the store when done writing, so readers find a fresh index; a writer that exits without closing loses nothing, because the next search sees the stale marker and rebuilds.
What does the package deliberately leave out?
Two things, both scope choices that keep it small rather than missing features.
No stemmed, multi-field full-text engine. The embedding model is the primary relevance signal, and it already handles paraphrase and synonyms across languages. The keyword signal is a language-agnostic exact-token BM25, with no stemming and no stopwords, present only to catch what vectors miss: acronyms, codes, and identifiers, so a query for ESRS finds ESRS.
No re-ranking stage. Retrieval returns the fused top-k directly; there is no cross-encoder or LLM re-ranker. A re-ranker adds a second model, possibly a network hop, and latency, for a modest gain the hybrid fusion already covers for the target use case. A harness that needs one is free to add it.
When is a network vector database the better fit?
When the corpus outgrows what an exact scan serves well, far beyond the hundred-thousand-chunk range measured here. Below that, a hosted vector database pays a network round-trip on every query, an estimated ~10-50 ms same-region and 50-150 ms or more cross-region or on a cold connection, with a long tail, and none of that time does any searching. In-process retrieval answers in ~26 ms at 1,000 chunks and ~105 ms at 100,000, with no hop at all. The sweet spot for duckdb-vectors is integrating thousands to tens of thousands of chunks directly into the agent, trading a managed vector service for a file in the image.
How did these numbers change?
Most of them improved by fixing one measured cost at a time. The before and after values below were measured on the same MacBook Pro M1 (2021) when each change was made, and are kept here to show which changes paid off:
| Change | Before | After | Source |
|---|---|---|---|
| Re-indexing an unchanged folder writes nothing | 16-18 s, file held throughout; queries from another process 0/10 | ~1 s, file held 0.02 s; 25/25 | v261102 |
| One DuckDB connection for every Markdown file of a run | 7.8 s to chunk 247 files | 0.9 s | v261102 |
| Connect on first use and retry a lock conflict | two MCP servers on one file: 15 and 0 queries succeed | 15 of 15 each | v261102 |
| The MCP server keeps the embedding model loaded | ~1.25 s per later search | ~45 ms | v261103 |
| Rebuild the keyword index once, not on every write | 110 s to write 50,000 chunks | 93 s | Unreleased |
One DELETE and one INSERT per batch, not two statements per chunk | 93 s to write 50,000 chunks; first index of the real corpus 17.7 s | 19.7 s; 3.6 s | Unreleased |
| Default model: 256-dim static instead of 384-dim contextual | 1,000-chunk file 9.5 MB; query embedding ~4.4 ms | 4.5 MB; ~0.3 ms (same benchmark) | v261024 |
The Source column names the release in CHANGES.md that records each change. The model row compares two figures measured with the same earlier benchmark script; the 4.8 MB of the first table comes from the current script, whose synthetic chunks differ slightly, so do not compare it with the 9.5 MB.
One change is worth a note, because the projection behind it was wrong. Rebuilding the keyword index on every write looked like the cost that made large builds slow: timings at 2,000 and 6,000 chunks grew faster than linearly, and a curve through them projected ~22-25 min to build 100,000 chunks, against ~3-4 min with a single rebuild. Measured afterwards, one rebuild over 50,000 chunks takes 0.09 s; the real cost was the row-by-row writes, at ~1.6-2 ms per chunk, so deferring the rebuild gained only 10-20%, and batching the writes made them about five times faster. Deferring the rebuild also needed a safeguard: a row written after the last rebuild was missing from keyword search without any error, so writes now mark the index stale in the database file and the next keyword search rebuilds it. Profile the stage that costs the time before projecting a gain.
How to reproduce these numbers?
Run the benchmark scripts from the repository root with the project venv. Each prints a table in the format used on this page and can write raw results with --json.
$ .venv/bin/python scripts/benchmark_queries.py # query latency and file size at 1k, 10k, 50k, 100k chunks
$ .venv/bin/python scripts/benchmark_queries.py --embeddings hashing # the scan curve alone
$ .venv/bin/python scripts/benchmark_indexing.py # first index, restart, one-file edit on a synthetic folder
$ .venv/bin/python scripts/benchmark_indexing.py --folder /path/to/your/docs
$ .venv/bin/python scripts/benchmark_embedders.py # the model comparison
$ make bench-tagged BENCH_ARGS="--dataset multihop --sample-queries 500 --ablate --suffix" # tagged retrieval
$ .venv/bin/python -m scripts.benchmark_kb_datasets legalbench \
--folder tmp/kb/legalbench/pages --work tmp/kb/legalbench # a public set as Markdown pages
$ duckdb-vectors --manifest tmp/kb/legalbench annotate # contexts (see the generation procedure)
$ duckdb-vectors --manifest tmp/kb/legalbench annotate \
--from-pack fixtures/benchmarks/legalbench-contexts.json.gz # or our contexts, no model
$ duckdb-vectors --manifest tmp/kb/legalbench evaluate-retrieval \
--tags 'context=context: $.retrieval.context' # one test run
$ .venv/bin/python -m scripts.benchmark_kb_analyze tmp/kb/*/results/test-*.json # tables and decisionannotate, with or without --from-pack, writes the contexts to a sidematter file next to each page by default, and the indexer merges it; --write-to frontmatter writes into the pages. The generation procedure and the evaluation procedure explain each step. The tagged retrieval benchmark downloads its public data on first use, writes one JSON file per run keyed by git SHA, and is described in its README. benchmark_queries.py builds synthetic indexes of ~300-word chunks drawn from a letter-only vocabulary, so the keyword index holds real tokens. benchmark_indexing.py generates its Markdown folder from a fixed seed. The MCP and multi-session figures come from the server's own tests and stdio probes against the real corpus.
Next steps
- User guide: the API, indexing, and configuration, including
lock_timeout. - Tagged retrieval workbook: questions and answers on tags, and the evidence behind them.
- Troubleshoot a search that returns the wrong passages: the entry point to the layers of tagged retrieval.
- Project tags in embeddings: the first layer, with no model call.
- Evaluate retrieval on your own queries: measure a gain.
- Generate contextual tags: write section contexts offline.
- Inspect a knowledge base: review tags, their distribution, and search results.
- Architecture: the schema, the keyword index marker, and the internals.
- Knowledge base in Kiro: one index shared by every Kiro workspace over MCP.