Rerank
Score and reorder retrieved passages against a query with local cross-encoder models, for sharper RAG results
- 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/rerank/index.md to help me query Rerank 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 search passages by relevance
Example output Β· captured
- Connector release
- v0.5.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
SELECT doc
FROM (VALUES ('Reset your password from the account settings page.'), ('Our office is open from 9am to 5pm.')) AS t(doc)
ORDER BY rerank.main.rerank_score('how do I reset my password', doc) DESC;
| doc |
|---|
| Reset your password from the account settings page. |
| Our office is open from 9am to 5pm. |
Quick start
Choose where to run Rerank, 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 with uvx
Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.
ATTACH 'rerank' AS rerank (
TYPE vgi,
LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-rerank-worker'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'rerank' AS rerank (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-rerank:0.5.0'
);
3. Run a query
SELECT doc
FROM (VALUES ('Reset your password from the account settings page.'), ('Our office is open from 9am to 5pm.')) AS t(doc)
ORDER BY rerank.main.rerank_score('how do I reset my password', doc) DESC;
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 'rerank' AS rerank
(TYPE vgi, LOCATION 'https://your-connector.example.com');
4. Run a query
SELECT doc
FROM (VALUES ('Reset your password from the account settings page.'), ('Our office is open from 9am to 5pm.')) AS t(doc)
ORDER BY rerank.main.rerank_score('how do I reset my password', doc) DESC;
Query Farm operates Rerank 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 rerank as the catalog alias for the query below.
4. Run a query
SELECT doc
FROM (VALUES ('Reset your password from the account settings page.'), ('Our office is open from 9am to 5pm.')) AS t(doc)
ORDER BY rerank.main.rerank_score('how do I reset my password', doc) DESC;
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 with uvx
Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.
ATTACH 'rerank' AS rerank (
TYPE vgi,
LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-rerank-worker'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'rerank' AS rerank (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-rerank:0.5.0'
);
Overview
Local cross-encoder reranking (fastembed/ONNX) for second-stage RAG precision.
![]()
Rerank retrieval results directly in DuckDB with a local cross-encoder reranker (fastembed / ONNX Runtime, no torch) -- the precision second stage that turns a good recall set into a great answer for RAG and semantic search.
Retrieval-augmented generation and semantic search almost always run in two stages. A fast recall stage (DuckDB VSS approximate nearest-neighbor search over embeddings, or BM25 full-text search) cheaply pulls a top-K candidate set out of a large corpus, but it ranks each document in isolation, so the truly best passage is often buried at rank 7 instead of rank 1. This worker adds the precision second stage: a cross-encoder that reads the query and a candidate document together in a single transformer forward pass and emits a relevance score that is far more accurate than bi-encoder cosine similarity. It is for anyone building local RAG pipelines, document search, or recommendation ranking who wants higher answer quality without standing up a separate model-serving service -- the reranking happens inside your SQL query.
Scores are computed entirely locally by fastembed (from Qdrant, Apache-2.0), which runs quantized cross-encoder models on ONNX Runtime -- there is no PyTorch dependency and no network call at query time. The default model, Xenova/ms-marco-MiniLM-L-6-v2 (~80 MB, Apache-2.0), is fetched once on first use and cached, and the ONNX session is built a single time per worker process and amortized across every row. Because a cross-encoder scores each (query, document) pair at query time and cannot be precomputed or cached the way an embedding can, you should only ever run it over a recall-produced top-K candidate set -- never over a whole corpus.
The catalog exposes a small, focused surface. rerank_score(query, document) returns a DOUBLE relevance logit (higher = more relevant, meaningful only relative to other documents for the same query), so it drops straight into ORDER BY rerank.rerank_score(:q, chunk) DESC LIMIT k; a three-argument overload rerank_score(query, document, model) lets you pick a specific reranker such as BAAI/bge-reranker-base. The supported_models() table function (also available as the supported_models table) lists every reranker the worker can run together with the license of its weights. A NULL or empty query or document always yields a NULL score, so odd input never crashes a query.
Getting started
Install and load the vgi community extension, then ATTACH this worker as a catalog (for example named rerank) pointed at uv run rerank_worker.py. Once attached, order any recall-produced candidate set by rerank.main.rerank_score(:query, document) DESC and keep the top k rows. Ready-to-run SQL for every function lives in each object's own examples and in the schema's example queries.
Learn more
- fastembed source: https://github.com/qdrant/fastembed
- fastembed documentation: https://qdrant.github.io/fastembed/
- ONNX Runtime: https://onnxruntime.ai/
Catalog
Everything rerank exposes once attached β read straight from the worker's
released build.
main 1 table Β· 1 function
Local cross-encoder reranking (fastembed/ONNX) for second-stage RAG precision
Schema examples (2)
Score a (query, document) pair with the default model.
SELECT rerank.main.rerank_score('how do I reset my password', 'Click the forgot password link to reset it.');
List the available reranker models and their licenses.
SELECT model, license FROM rerank.main.supported_models() ORDER BY model;
supported_models
Every cross-encoder reranker model the worker can run, with the license of its weights.
List every supported reranker model and its license.
SELECT model, license FROM rerank.main.supported_models ORDER BY model;
Look up the license of the default model.
SELECT license
FROM rerank.main.supported_models
WHERE model = 'Xenova/ms-marco-MiniLM-L-6-v2';
SELECT model, license FROM rerank.main.supported_models() ORDER BY model;
1 more example
SELECT license
FROM rerank.main.supported_models()
WHERE model = 'Xenova/ms-marco-MiniLM-L-6-v2';
rerank_score (query VARCHAR, document VARCHAR, model VARCHAR) +1 overload
Cross-encoder relevance score (DOUBLE) for a (query, document) pair using the default model (Xenova/ms-marco-MiniLM-L-6-v2). Higher = more relevant; the value is a raw logit, meaningful only RELATIVE to other documents for the SAME query. Intended for ORDER BY rerank_score(:q, doc) DESC LIMIT k over a top-K candidate set. NULL/empty query or document -> NULL.
rerank_score(query VARCHAR, document VARCHAR) β DOUBLErerank_score(query VARCHAR, document VARCHAR, model VARCHAR) β DOUBLE
Score one (query, document) pair with the default model.
SELECT rerank.main.rerank_score('how do I reset my password', 'Click the forgot password link to reset it.');
Score a pair with an explicitly chosen reranker model.
SELECT rerank.main.rerank_score('reset password', 'Reset your password from the account settings page.', 'Xenova/ms-marco-MiniLM-L-6-v2');
SELECT rerank.main.rerank_score('how do I reset my password', 'Click the forgot password link to reset it.') AS score;
1 more example
SELECT doc
FROM (VALUES ('Reset your password from the account settings page.'), ('Our office is open from 9am to 5pm.')) AS t(doc)
ORDER BY rerank.main.rerank_score('how do I reset my password', doc) DESC;
| doc |
|---|
| Reset your password from the account settings page. |
| Our office is open from 9am to 5pm. |
Try these queries
Score a (query, document) pair with the default model.
SELECT rerank.main.rerank_score('how do I reset my password', 'Click the forgot password link to reset it.')
Uses rerank_score
List the available reranker models and their licenses.
SELECT model, license FROM rerank.main.supported_models() ORDER BY model
List every supported reranker model and its license.
SELECT model, license FROM rerank.main.supported_models ORDER BY model
Uses supported_models
Look up the license of the default model.
SELECT license
FROM rerank.main.supported_models
WHERE model = 'Xenova/ms-marco-MiniLM-L-6-v2'
Uses supported_models
Look up the license of the default model.
SELECT license
FROM rerank.main.supported_models()
WHERE model = 'Xenova/ms-marco-MiniLM-L-6-v2'
Score a pair with an explicitly chosen reranker model.
SELECT rerank.main.rerank_score('reset password', 'Reset your password from the account settings page.', 'Xenova/ms-marco-MiniLM-L-6-v2')
Uses rerank_score
1 more example in the Catalog, each listed under the table or function it uses.
Rerank 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
Embed
AI & language
Turn text into embedding vectors on your own machine and rank it by cosine similarity for semantic search and RAG
LLM
AI & language
Call LLMs from SQL β Anthropic, OpenAI, OpenRouter or local Ollama β plus local embeddings
Tantivy
AI & language
Rank documents by BM25 relevance, tokenize text, and stem words with Snowball stemmers for many languages