Tantivy
Rank documents by BM25 relevance, tokenize text, and stem words with Snowball stemmers for many languages
- Connector software
- Free and open source
- Service credentials
- Not needed
- Query Farm hosting
- Available · $10/month organization minimum
Use with an agent
Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.
npx skills add Query-farm/vgi-skills --skill orchard
Copy this request into your coding agent to get started.
Use https://query.farm/products/orchard/connectors/tantivy/index.md to help me query Tantivy with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.
Rank a small JSON corpus by BM25 relevance to a query, best score first.
Example output · captured
- Connector release
- v0.5.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
SELECT doc_id, score
FROM tantivy.main.bm25_search('["the cat sat","dogs bark","stock crash"]', 'cat')
ORDER BY score DESC, doc_id
| doc_id | score |
|---|---|
| 0 | 0.8782 |
Quick start
Choose where to run Tantivy, then follow the steps below.
The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.
1. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
2. Attach the connector
Attach the release directly
Downloads the latest release for your platform and caches it locally.
ATTACH 'tantivy' AS tantivy (
TYPE vgi,
LOCATION 'github-auto://Query-farm/vgi-tantivy'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'tantivy' AS tantivy (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-tantivy:0.5.0'
);
3. Run a query
SELECT doc_id, score
FROM tantivy.main.bm25_search('["the cat sat","dogs bark","stock crash"]', 'cat')
ORDER BY score DESC, doc_id
Run the connector on a server you manage. You operate the service and choose who can connect.
1. Deploy the connector on your server
Follow the connector’s deployment instructions. Use its supported HTTP transport, or launch it remotely over SSH. The connection guide explains both options.
2. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach the connector
For an HTTP deployment, replace the example URL with your endpoint. Add the authentication options your deployment requires. For SSH, use the SSH connection instructions.
ATTACH 'tantivy' AS tantivy
(TYPE vgi, LOCATION 'https://your-connector.example.com');
4. Run a query
SELECT doc_id, score
FROM tantivy.main.bm25_search('["the cat sat","dogs bark","stock crash"]', 'cat')
ORDER BY score DESC, doc_id
Query Farm operates Tantivy for your team. Hosting has a $10 monthly minimum per organization; usage counts toward it. From $2.97 per instance-month ($10 monthly minimum).
1. Create your hosted connector
Open the console, choose your organization and deployment size, and add any service credentials there.
2. Install the vgi extension
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach your deployment
Copy the ATTACH statement from your deployment in the console and run it in DuckDB or Haybarn. Use tantivy as the catalog alias for the query below.
4. Run a query
SELECT doc_id, score
FROM tantivy.main.bm25_search('["the cat sat","dogs bark","stock crash"]', 'cat')
ORDER BY score DESC, doc_id
Technical details
- Verified connector release
- v0.5.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
- Verified on
- December 1, 2026
Pin a version for production
When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.
Attach the release directly
Uses the verified release each time you attach the connector.
ATTACH 'tantivy' AS tantivy (
TYPE vgi,
LOCATION 'github-auto://Query-farm/[email protected]'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'tantivy' AS tantivy (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-tantivy:0.5.0'
);
Overview
Full-text search (BM25 ranking), tokenization, and Snowball stemming, powered by the tantivy search engine.

Add BM25 full-text search, relevance ranking, and query-time text analysis (tokenization and Snowball stemming) directly to DuckDB SQL — no separate search service, index server, or ETL pipeline required. The tantivy worker is a standalone VGI worker that DuckDB attaches over Apache Arrow, exposing lexical (keyword) search and text-normalization functions you can call inline from any query.
How it works
Every function is powered by tantivy, the fast full-text search engine written in Rust (the library behind Quickwit), documented at docs.rs/tantivy. For each bm25_search / bm25_score call the worker builds a fresh in-RAM tantivy index, registers the appropriate per-language analyzer (simple tokenizer + lowercasing + a Snowball stemmer), indexes your documents, runs the query through tantivy's query parser and top-docs collector, and drops the index when the call returns. Nothing is persisted or shared between calls, so results are fully deterministic and there is no external state to manage. Relevance is computed with the industry-standard Okapi BM25 ranking model, and stemming uses the Snowball algorithms.
Key concepts
Corpora are passed inline as constant JSON rather than as table references, because the ranking function binds its corpus at query-bind time: assemble a text column into a JSON payload with json_group_array, materialize it with SET VARIABLE, and pass getvariable(...) (a subquery is not accepted as a table-function argument). Multi-term queries match documents containing every term; use a OR b for any-term matching. Relevance is lexical (keyword/BM25), not semantic — there is no embedding model or vector store. Text analysis is language-aware through Snowball stemming, so word variants collapse to a shared root; the set of stemmer languages is discoverable at runtime.
Who it's for
Reach for this worker whenever you want lightweight, embedded lexical search and relevance ranking inside an analytical SQL workflow — log triage, document shortlisting, fuzzy keyword matching, or normalizing text before joins and grouping — without standing up Elasticsearch, OpenSearch, or a dedicated indexing service. Every index is built in RAM per call and dropped immediately, and corpora are passed inline as constant JSON, so queries run with no external state.
Catalog
Everything tantivy exposes once attached — read straight from the worker's
released build.
main 1 table · 4 functions
Full-text search, relevance scoring, and text-analysis functions.
Schema examples (9)
Rank a small JSON corpus by BM25 relevance to a query, best score first.
SELECT doc_id, score
FROM tantivy.main.bm25_search('["the cat sat","dogs bark","stock crash"]', 'cat')
ORDER BY score DESC, doc_id;
| doc_id | score |
|---|---|
| 0 | 0.8782 |
Compute the ad-hoc BM25 score of a single document against a query.
SELECT tantivy.main.bm25_score('the cat sat on the mat', 'cat') AS score;
Tokenize text into lowercased word tokens (no stemming).
SELECT tantivy.main.tokenize('Running quickly, CATS!') AS tokens;
Tokenize and Snowball-stem text for a language.
SELECT tantivy.main.tokenize('Running quickly', 'english') AS tokens;
5 more examples
Snowball-stem a single word to its root for a language.
SELECT tantivy.main.stem('running', 'english') AS root;
List the first few supported Snowball stemmer languages, alphabetically.
SELECT lang FROM tantivy.main.supported_languages ORDER BY lang LIMIT 5;
Rank product titles for 'running OR shoes' with bm25_search, join the hits back to the titles by id, and use tokenize(…, 'english') to list which stemmed query terms each hit contains.
SELECT p.title, round(h.score, 3) AS score,
list_sort(list_intersect(tantivy.main.tokenize(p.title, 'english'), tantivy.main.tokenize('running shoes', 'english'))) AS matched_terms
FROM tantivy.main.bm25_search('[{"id":1,"text":"Trail running shoes"},{"id":2,"text":"Leather dress shoes"},{"id":3,"text":"Runners guide to the marathon"},{"id":4,"text":"Cast iron skillet"},{"id":5,"text":"Running socks"}]', 'running OR shoes') AS h
JOIN (VALUES (1, 'Trail running shoes'), (2, 'Leather dress shoes'), (3, 'Runners guide to the marathon'), (4, 'Cast iron skillet'), (5, 'Running socks')) AS p(id, title) ON p.id = h.doc_id
ORDER BY h.score DESC, p.title;
Tokenize a sentence (no stemming), then stem each token with stem() to group the word variants under their English Snowball root, most frequent root first.
SELECT tantivy.main.stem(tok, 'english') AS root,
list(DISTINCT tok ORDER BY tok) AS variants, count(*) AS occurrences
FROM unnest(tantivy.main.tokenize('Runners were running; the runner runs and ran a run.')) AS u(tok)
GROUP BY root
ORDER BY occurrences DESC, root;
Stem the word 'connections' with every supported Snowball stemmer (one row per language from supported_languages) and keep only the languages whose stemmer changes it.
SELECT lang, tantivy.main.stem('connections', lang) AS root
FROM tantivy.main.supported_languages
WHERE tantivy.main.stem('connections', lang) <> 'connections'
ORDER BY lang;
supported_languages
The Snowball stemmer language ids this worker supports (valid lang values for tokenize, stem, and the search analyzer).
List the first few supported Snowball stemmer languages.
SELECT lang FROM tantivy.main.supported_languages ORDER BY lang LIMIT 5;
Check whether a specific language is supported.
SELECT count(*) > 0 AS supported
FROM tantivy.main.supported_languages
WHERE lang = 'english';
Stem the word 'connections' with every supported Snowball stemmer (one row per language from supported_languages) and keep only the languages whose stemmer changes it.
SELECT lang, tantivy.main.stem('connections', lang) AS root
FROM tantivy.main.supported_languages
WHERE tantivy.main.stem('connections', lang) <> 'connections'
ORDER BY lang;
2 more examples
SELECT lang FROM tantivy.main.supported_languages() ORDER BY lang LIMIT 5;
SELECT count(*) > 0 AS supported
FROM tantivy.main.supported_languages()
WHERE lang = 'english';
bm25_score (doc_text VARCHAR, query VARCHAR)
Ad-hoc BM25 score of a single document against a query (1-doc index; 0.0 if no match)
Ad-hoc BM25 relevance of a single document against a query.
SELECT tantivy.main.bm25_score('the cat sat on the mat', 'cat') AS score;
stem (word VARCHAR, lang VARCHAR)
Snowball-stem a single word for the given language (e.g. running → run)
Snowball-stem a single English word to its root.
SELECT tantivy.main.stem('running', 'english') AS root;
Stem the word 'connections' with every supported Snowball stemmer (one row per language from supported_languages) and keep only the languages whose stemmer changes it.
SELECT lang, tantivy.main.stem('connections', lang) AS root
FROM tantivy.main.supported_languages
WHERE tantivy.main.stem('connections', lang) <> 'connections'
ORDER BY lang;
Tokenize a sentence (no stemming), then stem each token with stem() to group the word variants under their English Snowball root, most frequent root first.
SELECT tantivy.main.stem(tok, 'english') AS root,
list(DISTINCT tok ORDER BY tok) AS variants, count(*) AS occurrences
FROM unnest(tantivy.main.tokenize('Runners were running; the runner runs and ran a run.')) AS u(tok)
GROUP BY root
ORDER BY occurrences DESC, root;
tokenize (text VARCHAR, lang VARCHAR) +1 overload
Tokenize text into VARCHAR[]; 1-arg form only splits+lowercases (no stemming)
tokenize(text VARCHAR) → VARCHAR[]tokenize(text VARCHAR, lang VARCHAR) → VARCHAR[]
Tokenize text into lowercased word tokens (1-arg form, no stemming).
SELECT tantivy.main.tokenize('Running quickly, CATS!') AS tokens;
Tokenize and Snowball-stem text for a language (2-arg form).
SELECT tantivy.main.tokenize('Running quickly', 'english') AS tokens;
Tokenize a sentence (no stemming), then stem each token with stem() to group the word variants under their English Snowball root, most frequent root first.
SELECT tantivy.main.stem(tok, 'english') AS root,
list(DISTINCT tok ORDER BY tok) AS variants, count(*) AS occurrences
FROM unnest(tantivy.main.tokenize('Runners were running; the runner runs and ran a run.')) AS u(tok)
GROUP BY root
ORDER BY occurrences DESC, root;
bm25_search (docs_json VARCHAR, query VARCHAR)
BM25 full-text ranking of a JSON document corpus against a query, as (doc_id, score) rows
Rank a small JSON corpus by BM25 relevance to a query, best score first.
SELECT doc_id, score
FROM tantivy.main.bm25_search('["the cat sat","dogs bark","a cat and a dog"]', 'cat')
ORDER BY score DESC, doc_id;
Rank a corpus carrying explicit {id,text} document ids.
SELECT doc_id, score
FROM tantivy.main.bm25_search('[{"id":10,"text":"the cat sat"},{"id":20,"text":"stock crash"}]', 'cat');
Rank product titles for 'running OR shoes' with bm25_search, join the hits back to the titles by id, and use tokenize(…, 'english') to list which stemmed query terms each hit contains.
SELECT p.title, round(h.score, 3) AS score,
list_sort(list_intersect(tantivy.main.tokenize(p.title, 'english'), tantivy.main.tokenize('running shoes', 'english'))) AS matched_terms
FROM tantivy.main.bm25_search('[{"id":1,"text":"Trail running shoes"},{"id":2,"text":"Leather dress shoes"},{"id":3,"text":"Runners guide to the marathon"},{"id":4,"text":"Cast iron skillet"},{"id":5,"text":"Running socks"}]', 'running OR shoes') AS h
JOIN (VALUES (1, 'Trail running shoes'), (2, 'Leather dress shoes'), (3, 'Runners guide to the marathon'), (4, 'Cast iron skillet'), (5, 'Running socks')) AS p(id, title) ON p.id = h.doc_id
ORDER BY h.score DESC, p.title;
5 more examples
SELECT tantivy.main.bm25_score('the cat sat on the mat', 'cat') AS score;
SELECT tantivy.main.tokenize('Running quickly, CATS!') AS tokens;
SELECT tantivy.main.tokenize('Running quickly', 'english') AS tokens;
SELECT tantivy.main.stem('running', 'english') AS root;
SELECT lang FROM tantivy.main.supported_languages() ORDER BY lang LIMIT 5;
Try these queries
Compute the ad-hoc BM25 score of a single document against a query.
SELECT tantivy.main.bm25_score('the cat sat on the mat', 'cat') AS score
Uses bm25_score
Tokenize text into lowercased word tokens (no stemming).
SELECT tantivy.main.tokenize('Running quickly, CATS!') AS tokens
Uses tokenize
Snowball-stem a single word to its root for a language.
SELECT tantivy.main.stem('running', 'english') AS root
Uses stem
List the first few supported Snowball stemmer languages, alphabetically.
SELECT lang FROM tantivy.main.supported_languages ORDER BY lang LIMIT 5
Uses supported_languages
List the first few supported Snowball stemmer languages, alphabetically.
SELECT lang FROM tantivy.main.supported_languages() ORDER BY lang LIMIT 5
Check whether a specific language is supported.
SELECT count(*) > 0 AS supported
FROM tantivy.main.supported_languages()
WHERE lang = 'english'
7 more examples in the Catalog, each listed under the table or function it uses.
Tantivy is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.
Related workers
NLP
AI & language
Detect language, score sentiment, extract entities and tokenize text from queries
Rerank
AI & language
Score and reorder retrieved passages against a query with local cross-encoder models, for sharper RAG results
tiktoken
AI & language
Count, tokenize, truncate and chunk text using exact OpenAI BPE token counts