Skip to main content

Text Index Benchmark

LakeSoul's full-text search is built on an inverted index (Tantivy) that is maintained incrementally as data is written. Every write produces immutable index deltas alongside the data files; compaction merges them into fresh splits and removes the entries of deleted rows. A search reads the per-split BM25 top-k, merges the candidates by primary key, and then exactly re-verifies each candidate against the current row text before returning it. This page documents the benchmark suite used to quantify that behaviour on real IR corpora, the results obtained, and what each experiment tells us.

The benchmark is a self-contained Rust scenario runner (rust/lakesoul-datafusion/benches/text_index_bench.rs) orchestrated by script/benchmark/text/run.sh, with dataset preparation in script/benchmark/text/download.py, figures in script/benchmark/text/plot.py and the gateway scenario in script/benchmark/text/gateway_bench.py.

What the benchmark answers​

#ExperimentQuestion it answers
T1Rebuild policy × update patternDo appends, same-key rewrites, deletes and topic drift degrade retrieval, and when does rebuilding the shard pay off?
T2Fresh buildHow do analyzer (jieba / default / en_stem), positions and stored text affect build speed, index size and quality? How does the build scale to millions of documents?
T3Rebuild triggerWhen does the production drift trigger fire, and does drift predict quality loss?
T4Search by index stateHow do latency and recall differ between a fresh index, one with accumulated deltas, and one that has just been rebuilt, as the candidate count per shard is swept?
T5Shard countWhat does fanning the index out over more shards cost in build time and query latency?
T6End-to-end DataFusion SQLWhat do insert throughput and text_match + text_score query latency look like through the SQL path?
T7End-to-end ES gatewayWhat do bulk write and _search look like over the Elasticsearch-compatible HTTP API?

Test environment​

ItemValue
MachineLinux, 32 CPU cores, 62 GB RAM, local NVMe SSD
Buildcargo bench release profile, 16 worker threads
Storagelocal filesystem; table data as Parquet, one file per hash bucket
Tokenizerjieba unless the experiment varies it
Index configwith_positions = true, stored = false
SearchBM25, global top-k by score, exact verification on, 100 candidates per shard
MetricnDCG@10, Recall@100, MRR@10 against the dataset qrels; Recall@10 against the exact single-index BM25 baseline
Seed42 (fixed; the workload is deterministic)

Datasets​

DatasetDocumentsJudged queriesRole
SciFact (BEIR)5,183339smoke test (run.sh quick)
MS MARCO8.8M7,437 devmain English benchmark; subsets of 100K/300K/1M/2M documents
T2Retrieval118,60522,812 devChinese benchmark (first 100K documents)

The datasets are normalized into corpus.jsonl / queries.jsonl / qrels.tsv by download.py, which streams the MTEB mirrors; the Rust harness itself never touches the network. The harness restricts the qrels to documents inside the loaded subset and evaluates only queries that have at least one judged document there, so the metrics stay meaningful on subsets (in the MS MARCO 100K subset, 34 queries are judged).

How the benchmark works​

Workload​

The incremental experiments use 100,000 base documents and 10 update rounds of 10,000 documents. Each round writes its documents as a LakeSoul data file and then calls the production auto_build_text_index policy with the new file plus the table's active files, exactly as a write commit does.

Update patterns​

PatternDescription
appendNew primary keys — the corpus grows.
rewriteExisting primary keys rewritten with new text — the corpus stays the same size, the index accumulates new versions.
deletePreviously written documents are deleted (CDC tombstones) — the corpus shrinks.
topic-shiftNew documents sampled from a different part of the corpus — the vocabulary shifts away from the queries.

Rebuild policies​

PolicyBehaviour
noneIncremental deltas only (rebuild_mode: "none").
auto@rProduction policy: rebuild a shard when its delta / base documents ratio exceeds max_delta_ratio = r.
periodic (3)Incremental, with a forced rebuild every 3 rounds.
alwaysForced rebuild every round (upper bound on cost).

periodic and always are expressed through the same auto_build_text_index call with a tiny max_delta_ratio, so no separate code path is measured.

Metrics​

  • nDCG@10 / MRR@10 / Recall@100 — retrieval quality against the dataset qrels of the current live rows.
  • Recall@10 vs exact BM25 — agreement between what the index retrieved and an exact single-index BM25 over the same live rows; a value below 100% isolates candidate loss, a value of 100% means the index order equals the exact BM25 order.
  • p50 / p95 / p99, QPS — query latency through the production scan path.
  • build / update time — wall time of a fresh build, of one incremental index update, and of a rebuild; docs/s normalizes it.
  • peak RSS — process peak memory (VmHWM).
  • bytes/doc and index size — bundle bytes under _text_index/.
  • drift signal — delta / base document ratio of the shard catalog.
  • dropped stale — candidates dropped by the exact verification pass.

Results​

T1 — rebuild policy vs update pattern​

Goal. Find out whether an incrementally maintained text index loses quality as versions accumulate, and whether a cheaper policy can replace rebuilding.

Method. 100K base + 10 × 10K updates, quality measured every round against the qrels (recall@10 vs exact BM25 and nDCG@10).

PolicyRebuildsIndex update (total)Min recall@10 vs BM25Final nDCG@10Final recall@100Index size
none01.3 s100.0%0.35082.4%34 MB
auto@1.001.2 s100.0%0.35082.4%34 MB
auto@2.001.3 s100.0%0.35082.4%34 MB
auto@0.513.6 s100.0%0.33782.4%56 MB
auto@0.2527.7 s100.0%0.33682.4%77 MB
periodic (3)39.2 s100.0%0.33682.4%98 MB
always513.5 s100.0%0.33682.4%141 MB

Ten write rounds of 10K documents cost ~1.3 s of incremental index maintenance in total; a rebuild costs ~2.5 s and 33 MB. Rebuilding does not improve retrieval quality: the incremental index keeps the exact BM25 order (100% recall@10 vs the exact baseline), because verification re-checks every candidate against the current text. The policy default auto@1.0 never fires in this workload and pays nothing; the aggressive policies add 3–10× the maintenance cost and 2–4× the disk for a slightly lower nDCG@10 — rebuilding the corpus loses the better document statistics of the larger index.

Update pattern (auto@1.0):

PatternRebuildsIndex update (total)Min recall@10 vs BM25Final nDCG@10Final recall@100Index size
append01.2 s100.0%0.35082.4%34 MB
rewrite01.2 s100.0%0.37882.4%34 MB
topic-shift01.2 s100.0%0.35082.4%34 MB
delete00.0 s90.6%0.64482.4%33 MB

Appends, same-key rewrites and topic drift never lose a candidate. The delete pattern is the only one that dips (90.6% in the last round, where 90% of the corpus had been deleted and ~89 of every query's 100 candidates were stale versions that verification dropped); a rebuild after bulk deletes removes those entries and restores full candidate headroom. Note that nDCG rises as the corpus shrinks — BM25 simply gets easier with fewer distractors.

T1 policy recall and cost

T2 — fresh build​

Analyzer, positions and stored text (MS MARCO 100K):

TokenizerPositionsStoredBuild docs/sBytes/docBuild timenDCG@10Recall@100p50
jiebayesno39,921343.22.5 s0.35082.4%8.1 ms
jiebanono44,526227.12.2 s0.35082.4%9.2 ms
jiebayesyes34,496535.12.9 s0.35082.4%8.0 ms
defaultyesno93,087269.71.1 s0.35485.3%7.3 ms
defaultnono79,027215.91.3 s0.35485.3%7.5 ms
en_stemyesno44,747261.32.2 s0.36882.4%8.4 ms
en_stemnono48,904208.52.0 s0.36882.4%8.4 ms
  • en_stem gives the best English quality (nDCG 0.368 vs 0.354 for default and 0.350 for jieba), for 30–50% slower builds than default.
  • Positions cost 15–30% of index size and support phrase queries; they can be disabled when only term matching is needed.
  • Stored costs ~190 bytes/document and buys nothing for the search path (the reader takes the text from the data files for verification); keep it off unless a client reads the stored text from the index directly.
  • jieba on English text pays segmentation cost without quality gain — choose the analyzer per language.

Chinese (T2Retrieval, first 100K documents):

TokenizerBuild timeDocs/sBytes/docnDCG@10Recall@100p50QPS
jieba20.1 s4,9682,4970.64280.5%29.9 ms30
default42.4 s2,3562,7600.0161.6%0.9 ms397

Chinese requires jieba: the default analyzer keeps a whole Chinese run as a single token, so it matches almost nothing (and is faster only because those huge tokens are cheap to index and search).

Scaling (MS MARCO, jieba + positions):

DocsBuild timeDocs/sData writeBytes/docIndex sizePeak RSSnDCG@10Recall@100p50QPS
100,0002.5 s39,9210.3 s343.233 MB552 MB0.35082.4%8.1 ms94
300,0009.0 s33,2620.8 s338.897 MB1.3 GB0.27976.5%9.7 ms72
1,000,00030.3 s32,9531.9 s334.4319 MB3.4 GB0.20267.6%12.1 ms45
2,000,00063.3 s31,6053.6 s332.7635 MB6.9 GB0.19058.8%17.1 ms26

The index stays slightly above 300 bytes/document (a third of the raw Parquet text); build time and memory grow linearly (2M documents build in 63 s with 6.9 GB peak RSS). Search latency doubles from 100K to 2M documents. Quality decreases with corpus size because MS MARCO qrels are sparse relative to the larger document pool — the index is not losing candidates (recall@10 vs the exact BM25 baseline stays 100%).

T2 parameter matrix

T2 build scaling

T3 — rebuild trigger​

Goal. When does the production drift signal fire, and does it predict quality loss?

PatternFirst round with delta/base >= 1.0Rebuild round
append10—
rewrite10—
topic-shift10—

With 10% growth per round, the write-volume ratio reaches 1.0 only at round 10 (the shard holds 100K base and 100K delta documents) and the run ends before the next write pushes it above the default threshold. The ratio counts written documents, so rewrite and delete accumulate it the same way even though the live corpus does not grow, and topic-shift changes vocabulary but not the ratio at all. For the text index this signal is therefore a cost heuristic (it bounds delta build work), not a quality alarm: the exact verification pass keeps retrieval quality independent of how stale the index is.

T3 drift and rebuild

T4 — search by index state​

Goal. Measure the read path against a fresh index, an index with three rounds of deltas, and a just-rebuilt index, sweeping the candidate count per shard.

The three states hold 130,000 live documents: fresh (index built once), delta (100K base + 30K appended, 7 splits), rebuilt (the same data after a production rebuild, 1 split).

StateCandidates/shardRecall@10 vs exact BM25Recall@100p50QPSVerify
fresh10100.0%61.8%4.7 ms1963.3 ms
fresh20100.0%73.5%4.5 ms2203.3 ms
fresh40100.0%73.5%5.2 ms1863.8 ms
fresh100100.0%82.4%8.2 ms1265.7 ms
fresh200100.0%82.4%12.5 ms829.1 ms
delta10100.0%61.8%4.5 ms1963.0 ms
delta100100.0%82.4%8.5 ms1145.7 ms
delta200100.0%82.4%13.0 ms748.3 ms
rebuilt10100.0%58.8%5.0 ms1883.3 ms
rebuilt100100.0%82.4%8.5 ms1176.0 ms
rebuilt200100.0%82.4%16.7 ms6411.3 ms
fresh, no verify100100.0%82.4%2.6 ms335—
  • The index order equals the exact BM25 order at any candidate count (recall@10 vs exact BM25 is 100% even at 10 candidates): BM25 ranking is local enough that a per-split top-k merge reproduces it.
  • Recall@100 saturates at ~100 candidates, which is exactly the production default; 200 candidates buy nothing and cost ~50% more latency.
  • Verification costs 3–6 ms per query (it rebuilds a tiny in-memory index over the scanned candidate rows) but keeps stale index entries invisible; without it the query is 3× faster. Disable it only when stale hits are acceptable.
  • Fully rebuilt is not faster to search than a fresh or delta index (slightly slower here): a rebuilt single split is not measurably faster to search than several delta splits — the reason to rebuild is compacting the index and dropping deleted entries, not query speed.

T4 index states

T4 verification cost

T5 — shard count​

Goal. Measure build and search when the same 100K documents are spread over 1, 4, 16 and 64 shards (hash buckets), with 100 candidates per shard.

ShardsBuild timeDocs/sIndex sizeSplitsnDCG@10Recall@100p50QPS
12.8 s36,16333 MB10.35082.4%9.6 ms100
42.9 s34,90337 MB40.35282.4%21.1 ms44
164.2 s24,04941 MB160.31482.4%67.9 ms14
6422.9 s4,37145 MB640.31982.4%236.8 ms4

Query latency grows almost linearly with the number of shards — every shard is searched and its candidates fetched and verified, and the candidate budget multiplies (100 per shard). Build throughput collapses at 64 shards because each shard has its own writer and Tantivy indexing overhead is per-split. Per-split BM25 statistics also make the merged ranking slightly approximate (nDCG 0.314–0.352 against 0.350 for a single shard). Use as few shards as the write parallelism requires; sharding is not a way to make search faster.

T5 shard count

T6 — end-to-end DataFusion SQL​

Goal. Run the production write and query path through Spark-style SQL: INSERT base and incremental batches, then SELECT ... WHERE text_match(content, '...') ORDER BY text_score(content, '...') DESC LIMIT 10 with the index declared through the text_index_columns table option.

MeasurementValue
Base insert (100K rows)3.4 s (29,101 rows/s)
Incremental insert (10K rows)0.16 s / 0.14 s
Query p50 / QPS117.7 ms / 8.4
nDCG@10 / Recall@1000.350 / 82.4%
Index used by the planneryes (EXPLAIN checked)

The SQL path delivers the same quality as the scan API, but ~14× the latency (117 ms vs 8 ms) because each query goes through the full DataFusion plan and batch pipeline rather than the direct candidate path of the scan API. Latency-sensitive clients should use the scan API for scoring and the SQL path for filtering/joins.

T6 SQL

T7 — ES-compatible gateway​

Goal. Drive the Elasticsearch-compatible gateway over HTTP: bulk-write 20K MS MARCO documents, run match searches, then two rewrite rounds of 2,000 documents and re-measure.

MeasurementValue
Bulk write1,161 docs/s (20,000 in 17.2 s)
Search p50 / QPS347 ms / 3.3
nDCG@10 / Recall@1000.604 / 85.7%
Rewrite round 12,000 docs at 1,271 docs/s; quality unchanged
Rewrite round 22,000 docs at 1,240 docs/s; quality unchanged

A later gateway optimization pass re-measured the same 20K/4-bucket setup at 1.0-1.2K docs/s bulk and ~0.42 s search p50 (run-to-run variance); the one-bucket configuration documented in the gateway performance tuning writes ~2.9K docs/s and answers at p50 ~76 ms; with the gateway's deferred index maintenance the same table writes ~12.9K docs/s and still answers at p50 ~46 ms once the background build catches up. Quality matches the engine (the judged MS MARCO subset is small, so the absolute nDCG is higher than on the full corpus). Writes and searches both pay the merge-on-read plus index-maintenance cost per HTTP request, and the default 4-bucket layout multiplies search latency by the shard count; the gateway is a compatibility layer for WeKnora-style clients, not a latency-optimized endpoint.

T7 gateway

What the benchmark found​

Two engine bugs surfaced while running the full matrix; both are fixed in the same series as this page:

  1. Split build merge race. Building a 2M-document shard could fail with Tantivy's "segments that were merged could not be found": the background merge policy retired segments between the id lookup and the forced merge. Background merges are now disabled while a split is built, and the explicit merge sees a stable segment list.
  2. Chinese queries were parsed as phrases. Tantivy turns a whitespace-free literal into a phrase query when positions are indexed, so a Chinese sentence only matched documents containing that exact sentence. T2Retrieval nDCG was 0.038 with almost no candidates; analyzing plain query text into OR-combined terms raised it to 0.642 (recall@100 80.5%), matching an independent jieba BM25 baseline.

Conclusions​

  • Let the index accumulate deltas. Text search quality does not decay with stale index entries because verification is exact; the production auto@1.0 default rebuilds only under write volumes far beyond the measured workload and costs nothing when it does not fire.
  • Rebuild for disk, not for quality. Rebuilds compact many small splits and remove deleted documents' entries (the delete pattern is the only one whose candidate headroom drops). They do not make queries faster and slightly change nDCG through fresh statistics.
  • Pick the analyzer by language. en_stem for English, jieba for Chinese (mandatory), and disable positions and stored text unless phrases or direct stored-text access are needed.
  • Keep shards few. Latency grows ~linearly with shard count and per-split BM25 statistics make the global ranking approximate; start at 1 shard per partition and shard only as write parallelism requires.
  • Candidate count 100 is the sweet spot. Recall@100 saturates there; more candidates cost latency and buy nothing on these corpora.
  • Use the scan API for latency. SQL adds ~100 ms of planning and batch verification overhead per query; the HTTP gateway is a compatibility layer, not the fastest path.

Reproducing​

# 1. Datasets (streamed from the Hugging Face MTEB mirrors once)
uv run --with datasets python script/benchmark/text/download.py scifact \
--out ~/data/lakesoul-text-bench/scifact
uv run --with datasets python script/benchmark/text/download.py msmarco \
--out ~/data/lakesoul-text-bench/msmarco-100000 --limit 100000

# 2. Scenario runner (needs PostgreSQL metadata)
LAKESOUL_PG_URL=... script/benchmark/text/run.sh quick # SciFact smoke (T1-T6)
LAKESOUL_PG_URL=... script/benchmark/text/run.sh all # full matrix (T1-T7)

# 3. Figures
uv run --with matplotlib python script/benchmark/text/plot.py \
--results benchmark-results/text-<timestamp>

Useful scenario switches: --scenario build|search|stream|trigger|sql, --limit, --query-limit, --tokenizer, --no-positions, --stored, --shards, --candidates, --candidate-sweep, --policy, --max-delta-ratio, --drift, --rounds, --per-round, --work-dir (reuse a built table with search) and --out (JSON results).

See also​