Search Shortcut cmd + k | ctrl + k

BM25 full-text search for DuckDB — tokenization, Snowball stemming and Chinese (jieba) segmentation via tantivy, persistent named indexes (v0.3.0), and dryrun-style pre-execution cost estimates (tantivy_stats, v0.4.0), through DuckDB's C Extension API (quack-rs), no Arrow IPC

Maintainer(s): alitrack

Compatibility Matrix

This table covers all DuckDB releases that have not reached end-of-life, including LTS releases, and shows the 2 most recent patch releases of each. Older patch releases are not listed, but the extension may be available for them as well.

Platform 1.5.5 1.5.6 2.0.0 2.0.1
Linux AMD64
Linux ARM64
macOS AMD64
macOS ARM64
Windows AMD64
Windows ARM64
WebAssembly

Installing and Loading

INSTALL tantivy FROM community;
LOAD tantivy;

Example

INSTALL tantivy FROM community;
LOAD tantivy;

CREATE TABLE docs(doc_id BIGINT, body VARCHAR);
INSERT INTO docs VALUES (0, 'the cat sat'), (1, 'a cat here'), (2, 'the dog barked');

SELECT * FROM bm25_search('docs', 'cat');
-- doc_id | score
--        1 | 0.92...
--        0 | 0.92...

SELECT * FROM bm25_search('docs', 'cat', top_k := 1);

About tantivy

tantivy — BM25 Full-Text Search for DuckDB

A native Rust DuckDB loadable extension adding BM25 full-text search (via tantivy, the Rust search engine behind Quickwit) plus tokenization and Snowball stemming for 18 languages and Chinese (jieba) word segmentation — written against DuckDB's C Extension API through quack-rs. Table functions bind to real tables and stream real columns: no Arrow IPC, no JSON shims, no external search engine.

v0.3.0 added persistent named indexes: build once from a table (tantivy_create_index), store on disk (mmap-backed), search any number of times (tantivy_search_index) with results bit-identical to bm25_search, then tantivy_save_index / tantivy_load_index to move indexes across processes and machines.

v0.4.0 adds tantivy_stats(name, query), a duckdb-dryrun-style pre-execution cost estimate: exact postings+positions byte ranges from TermInfo, doc-frequency bounds, confidence + notes; absent terms report 0 bytes (AND short-circuits). Never decodes postings, never scores (~2ms).

Functions

Function Description
bm25_search(table, query, [id_column := ''], [text_column := 'body'], [language := 'english'], [top_k := 100]) BM25 search over a table → doc_id BIGINT, score DOUBLE
tantivy_create_index(name, table, [id_column := ''], [text_column := 'body'], [language := 'english'], [path := '']) Build a persistent on-disk index name from a table and register it (v0.3.0)
tantivy_search_index(name, query, [top_k := 10]) BM25 search against a registered persistent index, bit-identical to bm25_search (v0.3.0)
tantivy_stats(name, query) Pre-execution cost estimate for a query against a registered index (v0.4.0)
tantivy_save_index(name, [path := '']) Copy a registered index to path (v0.3.0)
tantivy_load_index(name, path := '...') Open a saved index from any process, read-only (v0.3.0)
tantivy_list() The registered persistent indexes (v0.3.0)
tantivy_terms(table, [text_column := 'body']) Raw-term dictionary of the table → term VARCHAR, df BIGINT
supported_languages() The 18 Snowball languages plus chinese (jieba)
tokenize(text) / tokenize(text, language) Tokenize (+ stem if language given) → VARCHAR[]; language := 'chinese' uses jieba word segmentation
stem(word, language) Snowball-stem a single word
bm25_score(doc, query) / bm25_score(doc, query, language) BM25 score of one doc against a query
tantivy_version() Version string of the embedded tantivy

Unicode text is NFC-normalized on both the indexed documents and the query, so canonically-equivalent spellings (precomposed vs decomposed) match. Ranking applies a deterministic tie-break over the full match set at the cutoff.

Hard limits (by design — clean SQL errors, never crashes or silent data loss)

Limit Value
top_k range [1, 100000]
Rows indexed per bm25_search call 1,000,000 (plus a proportional text-bytes cap) — add a WHERE clause for larger tables
Per-text length 16 MiB

bm25_search builds an in-RAM index per call (high-precision full-text search layer for medium-sized tables); for repeated queries over the same corpus, use the persistent named indexes instead.

Known limitation: temporary tables and uncommitted transactions are not visible to bm25_search (the C-API callbacks receive no caller connection, so the extension queries through a connection it opens itself). Permanent and attached tables work fine.

Windows (rtools/mingw) and musl builds are excluded pending CI coverage, matching the other quack-rs based community extensions. The wasm platforms (wasm_mvp / wasm_eh / wasm_threads) are excluded for now: the C-API Rust extension wasm build path is not yet wired (it needs an examples/ target plus an Emscripten link for the C deps); wasm support is tracked as follow-up work.

→ GitHub

Added Functions

function_name function_type description comment examples
bm25_score scalar NULL NULL  
bm25_search table NULL NULL  
stem scalar NULL NULL  
supported_languages table NULL NULL  
tantivy_create_index table NULL NULL  
tantivy_list table NULL NULL  
tantivy_load_index table NULL NULL  
tantivy_save_index table NULL NULL  
tantivy_search_index table NULL NULL  
tantivy_stats table NULL NULL  
tantivy_terms table NULL NULL  
tantivy_version scalar NULL NULL  
tokenize scalar NULL NULL  

Overloaded Functions

This extension does not add any function overloads.

Added Types

This extension does not add any types.

Added Settings

name description input_type scope aliases typed_value
temp_directory Set the directory to which temporary files are written. VARCHAR GLOBAL [] post.db.tmp
© 2026 DuckDB Foundation, Amsterdam NL
DuckDB Home Code of Conduct Trademark Use Blog