An embedded search database in the spirit of SQLite: one file, ACID transactions, SQL. Every table is indexed three ways at once (posting lists, a columnar forward index and vector ANN indexes), and a cost-based planner combines them in a single query. This page is the design, the prototype built from the earlier posting-list research, and its evaluation against SQLite and Tantivy on four BEIR collections.
BM25 top-10, and faster than Tantivy in 24 of 28 text and filter comparisons. FTS5, which scores every match, is 43–200× slower. Tantivy keeps facet counts on three of four collections and stays ahead on cold structured filters.
HNSW top-10 over 1,024-dimension vectors, with recall@10 0.99 on Quora. SQLite's scan takes 7.7 ms to 0.7 s. Cold, a graph walk reads about 4,000 pages where the scan reads all of them.
Weighted fusion of BM25 and vectors over vectors alone, on three of four collections, at 0.2–0.8 ms. RRF matches SQLite's RRF over the same rankings to within 0.005.
Faster than the best fixed strategy on the three larger collections, and within 1.0–1.6× of a per-query oracle. On SciFact, always pre-filtering takes 17% less time.
One file, one SQL statement, three kinds of index: the planner decides per segment which index drives the query and how the others constrain it.
SQLite answers full-text queries with FTS5 and structured ones with B-trees, but it has no vector index, and its FTS5 scores every match without pruning. Search libraries such as Tantivy rank text quickly but have no SQL, no vectors and no transactions. Vector databases do the opposite. Strata keeps SQLite's packaging (an embedded library, one file, a write-ahead log, snapshot isolation) and puts a search engine inside it.
-- full text, ranked, with structured filters SELECT id, title, score() FROM docs WHERE MATCH(body, 'vaccine AND (mrna OR "messenger rna") -animal') AND year BETWEEN 2019 AND 2021 AND category IN ('c01', 'c02') ORDER BY bm25(body, 'mrna vaccine efficacy') DESC LIMIT 10; -- filtered vector search SELECT id FROM docs WHERE rating >= 4 ORDER BY similarity(emb, :q) DESC LIMIT 10; -- hybrid ranking: rank fusion, or a weighted sum of normalised scores SELECT id FROM docs WHERE year >= 2015 ORDER BY 0.2 * bm25(body, :text) + 0.8 * similarity(emb, :q) DESC LIMIT 10; -- facets over any result SELECT category, COUNT(*) FROM docs WHERE MATCH(body, 'vaccine') GROUP BY category ORDER BY 2 DESC LIMIT 5;
The dialect is plain SQL parsed by sqlparser. Search functions are MATCH (boolean full text with phrases, prefixes and negation, juxtaposition meaning AND as in FTS5), bm25, similarity and distance, and rrf, with named options such as nprobe => 32 or strategy => 'prefilter'. Text fields can be generated from other fields, like SQLite's GENERATED ALWAYS AS, so the searchable body (title and text) is indexed without being stored twice.
| Strata | SQLite + FTS5 | Tantivy | |
|---|---|---|---|
| Embedded, one file, ACID | yes | yes | directory of segment files |
| SQL | yes (SELECT) | yes | no |
| BM25 top-k with pruning | MaxScore, Block-Max WAND | scores every match | Block-WAND |
| Structured filters | columns, range and keyword postings | B-tree indexes | fast fields, range queries |
| Vector search | flat, IVF, HNSW, filtered | brute force via a function | none |
| Hybrid ranking in one query | yes | application side | no |
Strata is layered like SQLite, with a search engine where SQLite keeps its B-tree module. SQL text is parsed and bound to the table's schema, giving a predicate tree (text matches, ranges, IN lists under AND, OR and NOT) and a score expression (BM25, similarity, fusion or a column). The planner decides per segment, from statistics the indexes answer without scanning, how each part is evaluated. Operators run on zero-copy views of the segment's sections, mapped straight from the file.
SQLite updates B-tree pages in place. Compressed posting lists, bit-packed columns and ANN graphs do not survive in-place updates: the best encodings, such as partitioned Elias-Fano, are chosen per list, and changing one docID means re-encoding the list. SQLite's own FTS5, Lucene and Tantivy all keep their indexes as immutable segments merged in the background. Strata does the same for the whole table and adds SQLite's transactional envelope.
The commit protocol is shadow paging, as in LMDB: nothing reachable from a valid meta slot is ever overwritten, so there is no rollback journal.
A torn slot fails its checksum and recovery falls back to the other one, which still names a complete version. Freed pages wait until no snapshot needs them, plus one extra commit, so the older slot always stays valid. A crash test kills a writer process with SIGKILL at random moments, over and over; after every restart the database equals some committed prefix of the writes.
-wal file, synced at commit. On open, committed transactions are replayed and a torn tail is ignored.vacuum compacts the file.Every field type maps to the structures that serve it. The posting-list study that preceded this design chose the encodings: Loom for ranked text, Pyramid for filter lists, BP128 for short lists.
The analyzer splits on non-alphanumeric characters, lowercases, folds accents, drops 33 stopwords and applies the Snowball English stemmer. Ranked queries also drop NLTK's 153 English function words and count each term once. Terms sit in front-coded dictionary blocks of 32. Lists of at least 512 documents keep their docIDs as Loom, with frequencies bit-packed per 128 postings and addressed by posting rank; shorter lists use BP128 blocks. Document lengths are one-byte norms. Ranking is BM25 with collection-wide statistics summed over the snapshot's segments, so a document scores the same in any segment:
Top-k uses MaxScore by default: terms are sorted by their upper bound \(U_t\), and once the threshold \(\theta\) of the current top-k exceeds the sum of the smaller bounds, those lists stop driving iteration and are only probed. Block-Max WAND is available, but on these collections' queries MaxScore measured 1.9–2.6× faster. A filter either drives scoring, when it is small enough that scoring its members directly is cheaper, or is probed per candidate. The crossover is a fitted constant times the filter size against the query's list lengths.
rating are detected and stored as scaled integers (0–499).IN are unions. Per-candidate probes instead use the code column and a bitset of accepted codes, at 4–5 ns against 5–33 ns for Pyramid probes.Each vector field keeps float32 vectors for exact re-ranking and 8-bit codes for scanning. Codes are per-dimension scalar quantised, and the query is quantised too, so the inner loop is an integer dot product: NEON usdot on aarch64 (16 byte products per instruction), AVX-512 VNNI on x86-64:
with \(\tilde q\) the 8-bit query, \(\alpha, \beta\) per-query constants, and one 1,024-dimension score in 10–14 ns on the M2. Three index kinds sit on top. Flat scans codes and re-ranks the best \(r\) in float32. IVF stores each k-means cluster's docIDs contiguously, followed by their codes, so a probe is one sequential read and a filter is an intersection with the cluster's docID list. HNSW keeps fixed-degree adjacency arrays in the segment; filtered HNSW traverses through non-matching nodes but only collects matching ones.
The planner works per segment from statistics the indexes answer in microseconds: exact list lengths for terms and keyword values, histogram counts for ranges, document counts, and the vector index's calibrated cost model. Conjunctions assume independence and disjunctions use inclusion-exclusion:
A predicate is either evaluated into a document set before ranking, or checked per candidate of the ranking operator. If that operator tests \(m\) candidates, it materialises when
so a conjunction is probed most selective leaf first, short-circuiting. Inside a materialised conjunction the same test applies child by child: once the running result is small, each remaining child is probed per survivor instead of materialised.
Four strategies compete. Pre-filter scans the filter's members exactly. In-index searches IVF or HNSW with the filter applied inside. Post-filter searches unfiltered with \(k' \approx k/s\) and drops non-members. Flat scans everything. Their costs, from the vector index's model, are roughly
The index strategies pay for the selectivity near the query, \(s_{\text{near}}\), not the global \(s\). A filter on a topic far from the query has almost no members among the query's neighbours, so HNSW wanders through thousands of nodes. When the global estimate favours an index strategy, the planner measures \(s_{\text{near}}\) with a 32-result unfiltered search and re-plans:
Reciprocal rank fusion and weighted fusion are both one SQL expression:
where \(C\) is the union of each input's top 100. With exact => 1, \(C\) is every row passing the filter, which gives the reference ranking for measuring how much the top-100 shortcut loses.
Four BEIR collections, with Cohere embed-english-v3 vectors (1,024 dimensions) for documents and queries, and human relevance judgments: SciFact (5,183 documents), FiQA (57,638), TREC-COVID (171,332) and Quora (522,931). Each document also has synthetic structured fields: year uniform over 1990–2024, category Zipf-distributed over 64 values, rating uniform over [0, 5). A content-correlated topic (the k-means cluster of the document's vector) gives filters that correlate with queries. One generated workload per collection is run by all three systems: BM25, boolean, filter, vector, hybrid and facet queries, at filter selectivities from 0.1% to 50%.
Each system is fully built (one Strata segment, one Tantivy segment after merging, one SQLite file), then measured single-threaded on an Apple M2 MacBook Air (NEON kernels, on mains power), nothing else running. Warm latency is the median of up to three repetitions per query. Cold runs close the database, evict its files from the OS page cache, reopen and run one query; pages read are the file pages the query brought into the page cache.
Strata builds every index of the table in one pass: text, structured, doc store, keys, float32 and 8-bit vectors, and an HNSW graph. That takes 0.5 s for SciFact and 153.1 s for Quora, against 0.3–30.7 s for SQLite and 0.4–9.3 s for Tantivy. Neither baseline builds a vector index: SQLite keeps the vectors as blobs and scans them, and Tantivy has none.
The graph is most of the difference. It takes 12.9 s of FiQA's 14.2 s, 37 s of TREC-COVID's 40.6 s and 146 s of Quora's 153.1 s, on four threads. The rest of the load takes 1.3–7.5 s, 0.2–0.5× SQLite's time. With IVF instead of HNSW, TREC-COVID builds in 19.2 s and Quora in 60.1 s.
The Strata and SQLite files are close in size because both are dominated by float32 vectors, 4 KiB per document. Vectors are 83% of Strata's TREC-COVID file and 97% of Quora's. That share covers the float32 copy kept for re-ranking, 1 KiB of 8-bit codes per document, and 128 bytes of graph. Tantivy, which stores no vectors, takes 7–180 MiB.
Without vectors, Strata's text index is the smallest of the three. With positions, it takes 44.5 MiB on TREC-COVID, against 60.0 MiB for Tantivy and 70.0 MiB for FTS5. On Quora it takes 11.8 MiB, against 21.1 and 25.3 MiB. Part of that gap is the 33 stopwords Strata drops at index time, which the baselines keep. A posting, with its docID and frequency, costs 12.2–12.7 bits. The structured index (columns, keyword postings and range buckets) takes 4.5 MiB on TREC-COVID, against 8.4 MiB for SQLite's four B-tree indexes and 2.7 MiB for Tantivy's columns. The doc store is within 16% of Tantivy's; both use LZ4.
Warm, Strata is faster than Tantivy in 24 of the 28 text and filter comparisons:
Median latency by query kind
The same workload in each system · Tantivy has no vector search · SQLite answers vectors by a brute-force scan
The exceptions are facet counts on SciFact, FiQA and Quora, where Tantivy is 1.1–2.1× faster (on TREC-COVID Strata is 1.5× faster), and SciFact's three-term conjunctions. These queries take 9–27 µs in Tantivy. At that size, the fixed cost of a SQL statement shows: even a query that matches nothing is parsed, bound, planned and run. Strata also materialises the match before reading category codes, while Tantivy's collector reads its column inside the intersection.
Cold, every system waits on page faults and the gaps narrow:
Page counts are in 4 KiB units, but macOS pages are 16 KiB: a random fault reads four times the data of a 4 KiB page, so random-access queries such as HNSW read more, and are slower cold, than on the Xeon VM these runs replace.
Cold latency depends on what the kernel reads around each page fault, and the right policy differs by section. The table compares three policies on the two large collections:
MADV_RANDOM on the whole file). Vector queries drop to 3,676 pages on TREC-COVID and 4,416 on Quora, and take 102–115 ms. BM25, facets and filters, which read postings and columns in order, then fault page by page and are up to 1.5× slower than with read-ahead.Structured filters are the exception: under the default hints they are 1.2–1.5× slower than with read-ahead everywhere. These queries sort by rating and break ties by key. With 500 rating values, a permissive filter leaves hundreds of documents tied at the top. Their keys are scattered over the key index, so each one costs a separate fault. Keeping read-ahead on the docID-to-key half of that index would remove the cost. Per-section hints are a first step; the planner knows each query's access pattern and could choose them per query.
Median milliseconds per query after evicting the database from the page cache, and the median number of 4 KiB pages read (macOS faults in 16 KiB pages, four of these units). Highlighted: the fastest policy for each kind.
Strata's BM25 is within 0.018 nDCG@10 of both baselines on every collection, and no system is consistently ahead: Strata leads on SciFact, Tantivy on TREC-COVID, FTS5 on FiQA and Quora. The analysers differ. Strata stems with Snowball and drops stopwords, FTS5 uses the Porter stemmer, and Tantivy uses Snowball and keeps stopwords.
HNSW is within 0.006 of the exact scan on three collections. SQLite ran only 300 of Quora's 2,000 vector and hybrid queries, so the Quora row compares different query sets. On the shared 300, HNSW scores 0.867 against 0.880 exact, with recall@10 0.989; four queries that lost a relevant duplicate account for the whole difference. Strata's RRF is within 0.005 of SQLite's RRF over the same two rankings, also on those 300 Quora queries (0.846 against 0.850).
All three systems drop NLTK's 153 English function words from BM25 queries, so the rankings are comparable; bm25(body, :text, stopwords => 0) keeps them. On the same queries, dropping them gains 0.055 nDCG@10 on TREC-COVID, whose queries are full questions, and 0.002 on SciFact and FiQA. It costs Quora 0.055 (0.756 against 0.811): its questions are short, and "how", "why" or "can" carry much of their meaning.
Quora: SQLite's exact vector and RRF columns cover 300 queries, Strata's 2,000. On the same 300, Strata scores 0.867 (HNSW) and 0.846 (RRF).
Weighted hybrid ranking: nDCG@10 by BM25 weight
Scores min-max normalised over the union of each input's top 100 · 0 = vectors only, 1 = BM25 only
Weighted fusion beats both of its inputs on three of the four collections. The best BM25 weight is small, 0.1–0.3: the scales differ, and on these collections the embeddings are the stronger ranking. On TREC-COVID it reaches nDCG@10 0.851, against 0.815 for vectors alone, 0.835 for RRF and 0.658 for BM25. On Quora it reaches 0.920 against 0.899 and 0.860. On FiQA, where BM25 is weak (0.268), fusion only matches the vector ranking (0.437), and RRF falls below it (0.381), because RRF gives both rankings equal weight.
The top-100 shortcut is cheap and close to exact. Against weighted ranking computed over every document, it recovers 89–95% of the exact top-10, and its nDCG@10 is within 0.01–0.03. It costs 0.2–0.8 ms per query, where the exact computation costs 0.9 ms on SciFact, 12 ms on FiQA and 62 ms on TREC-COVID.
The text index stores long lists (at least 512 documents) as Loom, the aligned partitioned Elias-Fano design from the posting-list study, and short lists as BP128 blocks. The table compares that against BP128 for every list, on the same index:
Mean microseconds per query, warm cache, one thread. Bits per posting cover docIDs, frequencies and list metadata.
On Quora (522,931 vectors, 1,024 dimensions), HNSW reaches recall@10 0.960 at 0.036 ms and 0.990 at 0.086 ms (ef 64, the default). IVF needs 0.22 ms for 0.936 (nprobe 32) and 0.67 ms for 0.977. The exact scan of 8-bit codes with float32 re-ranking reaches 1.000 in 9.7 ms.
The quantised dot product costs 14 ns per vector with NEON usdot (9.8 ns when four rows are scored at once), against 70 ns in float32; on x86-64 the same kernel uses AVX-512 VNNI. Scoring on the codes alone already finds 99.8% of the exact top-10 over 100 sampled queries; float32 re-ranking settles the rest. HNSW took 146 s to build with four threads, IVF 53 s.
Cold, access patterns decide. With the kernel's default read-ahead, one HNSW query reads 9,672 pages (136 ms). Advising the graph and its codes MADV_RANDOM cuts that to 4,836 pages (113 ms), and prefetching each hop's neighbours cuts it to 28 ms. IVF reads its clusters sequentially, so it is fastest with read-ahead: 26 ms, or 10 ms with prefetching.
Recall@10 against latency
Warm cache · each point is one setting of ef, nprobe or re-rank depth
Filtered vector search is where one fixed strategy cannot win. The chart shows mean latency per strategy at each filter selectivity on the workload's filters:
The filters include random ones and topic filters drawn near to and far from the query.
Filtered vector search: time by strategy and selectivity
Mean over the workload's filters at each selectivity (random and topic filters, near and far from the query)
Across 300 filtered vector queries per collection, the planner is 2.7× faster than the best fixed strategy on TREC-COVID (121 ms against 325 ms for always pre-filtering) and 6.1× faster on Quora (179 ms against 1,089 ms). Recall@10 stays at 0.991–0.998. Always using the HNSW index would take 2.9–6.1 s. Against an oracle that knows the fastest plan per query with recall ≥ 0.9, the planner's total time is 1.0–1.6× the oracle's.
Two refinements made that gap small; the timings in this paragraph come from the development runs on the earlier Xeon VM. The first measures selectivity near the query. Planning on global selectivity alone, 100 TREC-COVID queries took 328 ms against an oracle's 48 ms. A 32-neighbour sample brought that to 61 ms. On Quora, though, it still sent far-topic 10% filters into 60–100 ms graph walks where a 5 ms scan sufficed: 1,076 ms in total. A second, 160-neighbour sample, taken when the first finds at most one match, brought Quora to 451 ms. The second refinement costs post-filtering with the smaller of the global and local selectivity, since its candidate pool is sized from the global one.
For BM25 with filters, and for structured filters alone, geometric-mean regret is 1.06–1.18. Range filters choose between a zone-map scan and histogram bucket postings, and filtered BM25 chooses between driving scoring from the filter and probing it. On IVF, the planner leans on the index and gets recall 0.93; an oracle limited to recall ≥ 0.9 must spend more, which is why the IVF rows show the planner faster than that oracle.
The workload measures one query shape at a time. These ten statements combine them: phrases with negation, prefixes, OR and NOT filters, both fusion methods, facets over a match, column ordering, and exact distance with a forced strategy. Each runs on every collection with the first test query's text and vector bound to :t and :q. Each cell shows the median time, the row count and the plan, read from the executor's plan lines.
The same statement gets different plans as the data changes. The OR filter in the fourth query matches about 15% of documents everywhere. On SciFact the planner scans those 800 documents. On the larger collections it measures 11% near the query and post-filters the HNSW result. The RRF query's topic filter matches 11% of Quora globally but only 3.4% near this query, so the planner switches to an exact scan of the 58,767 members, at 3.1 ms.
A durable single-document commit is one WAL append and one fsync: 4.1 ms at the median, 227 commits per second. On macOS the sync is F_FULLFSYNC, which makes the SSD flush its write cache; the earlier VM's fdatasync on a virtual disk did not have to, and took 0.27 ms. Batching amortises the sync. With 1,000 documents per transaction, the WAL takes 98,000 documents per second. Without fsync it takes 155,000–438,000; a process crash still loses nothing then, but a power failure may lose recent commits.
Write throughput through the WAL
FiQA documents, one writer · each transaction commits
vacuum.The design holds up. One file, with ACID commits and a SQL front end, serves full text, structured filters, vectors and their combinations. Warm, it is faster than both specialised baselines on most of the workload, and its quality matches theirs. It pays for that in build time and in cold structured filters.
Met: every query of the workload, and the ten compound statements, runs as SQL against one file. Commits are durable at 4.1 ms, nearly all of it macOS's F_FULLFSYNC, which flushes the drive's write cache. Every crash test recovered a committed prefix. Snapshots cost at most 0.13 µs, and the file is near SQLite's size.
Missed: SQL covers single-table SELECT only; writes go through the Rust API. Building the HNSW graph makes loads 1.7–5.9× slower than SQLite's (0.2–0.5× without it).
Met: warm BM25 is 1.7–3.2× faster than Tantivy, and conjunctions 2.7–4.1× faster. Strata wins 24 of 28 warm text and filter comparisons. Vector queries take 0.05–0.10 ms, against SQLite's 7.7 ms to 0.7 s scans, and are 28–63× faster cold.
Missed: Tantivy counts facets 1.1–2.1× faster on three of the four collections. Cold structured filters are 1.4–3.4× slower than Tantivy's, because a range touches several sections and key tie-breaks fault one page per key.
Met: RRF and weighted fusion are single SQL expressions, under the same filter as their inputs. RRF quality equals SQLite's RRF. Weighted fusion adds 0.02–0.04 nDCG@10 over vectors alone on three collections, at 0.2–0.8 ms.
Missed: the top-100 shortcut recovers 89–95% of the exact fused top-10. The best weight differs by collection (0.1–0.3), and nothing picks it automatically.
Met: for filtered vector search, the planner is 1.8–6.1× faster than the best fixed strategy on the three larger collections, with recall@10 0.991–0.998. For filtered BM25 and filters alone, geometric-mean regret is 1.06–1.18.
Missed: it spends 1.0–1.6× an oracle's time. On SciFact, always pre-filtering takes 17% less time. With 5,183 documents, scanning a filter's members is never expensive, and planning, probing and the occasional index plan add 1–29 µs per query.
msync(MS_INVALIDATE) on the Mac's local NVMe drive (APFS, 16 KiB pages); a spinning disk, a network volume or 4 KiB pages would shift them, and durable commits depend on what the drive's cache flush costs.year, category and rating are random, so they are independent of the text, which the planner assumes. topic is the k-means cluster of the same embeddings, so it correlates with vector queries by construction.INSERT, DELETE and UPDATE over the existing transaction API. Then incremental HNSW merges, so that merges stop rebuilding the graph.cd strata python3 scripts/prepare_beir.py /home/user/data/beir # BEIR + embeddings (≈ 4.8 GB) cargo test --release # every component, end-to-end SQL test scripts/run_eval.sh # all experiments, sequentially (≈ 4 h) python3 scripts/build_report.py # this page