Decisions as expressions
truth, truth_score, choose and decide are ordinary SQL expressions. Use them in WHERE, JOIN and GROUP BY. A vector of up to 2048 rows is already a batch.
truthchoosedecidePre-release · community install coming soon
Decisions, lazy decision trees, embeddings and MCP as ordinary expressions in DuckDB 2.0+. One extension. One OpenRouter key. No gateway.
$ git clone --recurse-submodules https://github.com/ryrobes/rvbbitduck.gitLOAD rvbbit;
CREATE SECRET rvbbit (TYPE openrouter, KEY 'sk-or-...');
-- or export OPENROUTER_API_KEY=sk-or-...
SELECT id
FROM tickets
WHERE rvbbit.truth(body, 'The customer explicitly asks to cancel');
SELECT rvbbit.choose(body,
['billing', 'technical problem', 'cancellation', 'other'])
FROM tickets;What you get
A port of the decision core and the main text operators from rvbbit 1.2.3, Ryan's Postgres extension. The Postgres parser could not host real words like MEANS or a CREATE DECISION TREE statement. DuckDB 2.0 can, and a vector of up to 2048 rows is already a batch.
truth, truth_score, choose and decide are ordinary SQL expressions. Use them in WHERE, JOIN and GROUP BY. A vector of up to 2048 rows is already a batch.
truthchoosedecideA tree is validated before any call, and only the path taken is judged. Every run returns a status, a label and the path it walked.
branchsave_treerun_treeSeeded from Calliope 1.2.3: means, about, summarize, classify, extract, sentiment, redact, headline and more. Define your own with create_operator.
summarizeclassifyextractembed returns a FLOAT[] that works with DuckDB NEAREST and array_cosine_similarity. When vss is loaded, embed_index builds a cosine HNSW index.
embednearest_labelknn_textclassify_collection, summarize_collection, consensus and collection_themes are real GROUP BY aggregates, not per-row calls in disguise.
GROUP BYconsensusthemesimage_part packs PNG or JPEG bytes. locate returns top, bottom, left, right and confidence. truth_rank picks the best level from a list you supply.
locateimage_parttruth_rankEach OpenRouter call and each cache hit becomes a row: model, tokens, cost, latency, status. The total in spend() is the exact sum. Your key is never stored.
ledger()spend()Point chat and embeddings at a vLLM or llama.cpp server with an rvbbit_provider secret, or name a raw http://host:port/model address. OpenRouter stays the default.
vLLMllama.cppgpu:modelAttach any MCP server over HTTP or stdio. Call tools, read rows, wrap them as macros, or use FROM MCP. Mutations are guarded and never cached.
mcp_callmcp_rowsmcp_wrapIn practice
The function form is the source of truth. The grammar is sugar that desugars to the same functions, so nothing about the API changes when you turn it on.
truth is a boolean. truth_score is the number behind it. choosepicks a label. Decisions are answered by Jev through OpenRouter's decisions endpoint.
SELECT rvbbit.truth_score(body, 'The customer explicitly asks to cancel') AS score
FROM tickets;
SELECT rvbbit.choose(body, ['billing', 'technical problem', 'cancellation', 'other'])
FROM tickets;SELECT rvbbit.semantic_case(
body,
['The customer explicitly asks to cancel', 'The request is about billing'],
['retention', 'finance'],
[0.8, 0.5],
'triage')
FROM tickets;Constructors are pure. A tree is validated before any call, and an unreachable leaf is never judged. Prior judgments travel down the path as interpretations, not new evidence. The result is a struct with label, status, path and friends.
completeunavailablebudget_exhaustedcontext_limitmissing_inputSave one with save_tree, run it by name with run_tree. Rows in a vector are scheduled in waves, so a normal SELECT already batches.
Illustrative walk through the churn tree from the quickstart.
SELECT rvbbit.save_tree('churn', rvbbit.branch(
'Does this customer show meaningful churn risk?',
yes := rvbbit.branch(
'Is an unresolved service problem the main concern?',
yes := rvbbit.leaf('service intervention'),
no := rvbbit.leaf('relationship review'),
threshold := 0.7),
no := rvbbit.leaf('routine follow-up')));
SELECT customer_id,
(rvbbit.run_tree('churn', recent_messages)).label
FROM customer_contexts;DuckDB 2.0's grammar extension API lets rvbbitduck add real words: MEANS, ABOUT, NEAR, ABOVE, SUPPORTS, CONTRADICTS, IMPLIES, SEMANTIC CASE, CREATE DECISION TREE and DECIDE name FOR state. The transform returns a normal DuckDB AST node, so there is no new physical operator.
It is off until you run SET active_grammar_extensions = ['rvbbit']. The new words are unreserved, so column names keep working. Read the syntax notes, including the forms that did not fit.
SET active_grammar_extensions = ['rvbbit'];
SELECT * FROM tickets
WHERE body MEANS 'customer wants to cancel' ABOVE 0.8;
CREATE DECISION TREE churn AS
BRANCH 'Does this customer show meaningful churn risk?'
YES 'retention'
NO 'routine follow-up';
SELECT (DECIDE churn FOR recent_messages).label
FROM customer_contexts;SELECT SEMANTIC CASE ON body
WHEN 'The customer explicitly asks to cancel' ABOVE 0.8 THEN 'retention'
WHEN 'The request is about billing' THEN 'finance'
ELSE 'triage'
END
FROM tickets;embed returns a FLOAT[]at 1024 dimensions by default, with a cache and per-chunk dedupe. Cast it and use DuckDB's own NEAREST and array_cosine_similarity. nearest_label maps text to the closest of your labels.
embed_index fills a FLOAT[N] column and, when the vss extension is loaded, creates a cosine HNSW index. Otherwise it tells you, and NEAREST stays a brute-force join.
SELECT d.text
FROM (
SELECT rvbbit.embed('cancel my subscription')::FLOAT[1024]
AS embedding
) q
JOIN docs d
NEAREST 1 BY SIMILARITY
array_cosine_similarity(q.embedding, d.embedding);SELECT rvbbit.nearest_label(
body, ['cancel the subscription', 'thanks for the help'], ['billing', 'praise'], 'other')
FROM tickets;
SELECT rvbbit.embed_index('tickets', 'body');Collection operators are real GROUP BY aggregates. A group keeps at most 48 distinct texts, and larger groups are reduced in chunks. locate returns a box for what you describe in an image. And spend() is the exact sum of ledger().
A repeated question is a cache hit, which costs 0 and still gets a ledger row. Your API key is never stored there.
SELECT region, rvbbit.classify_collection(body, 'billing,shipping,other')
FROM tickets
GROUP BY region;SELECT rvbbit.truth('please cancel the appointment', 'the customer wants to cancel');
SELECT rvbbit.truth('please cancel the appointment', 'the customer wants to cancel');
SELECT http_requests, cache_hits, cost FROM rvbbit.spend();SELECT (rvbbit.locate('[' || rvbbit.image_part(photo) || ']', 'the visible damage')).top
FROM listings;How it works
HTTP runs inside the extension through libcurl. No sidecar, no gateway, and LOAD rvbbit does not need httpfs.
Plain functions, or opt-in words that desugar to them.
Dedupes a vector, checks the cache, batches the rest, and walks only the tree path taken.
Or your own GPU, through one provider resolver.
Results in your query. A ledger row for every call.
Each vector dedupes identical bodies and posts them together, bounded by rvbbit_max_concurrency (default 8). Requests share a connection cache and ask for HTTP/2.
429 and 5xx retry with backoff (rvbbit_max_retries, default 3), honoring Retry-After up to 5 seconds.
An in-memory LRU of 10000 entries by default. Set rvbbit_cache_path and judgments and trees persist in a DuckDB file.
Inside one chunk, questions about the same state share a single decisions request, up to 8. A rejected fused call is sent again as separate requests.
A connection failure or a non-retryable 4xx raises. It never silently becomes NULL.
Decision calls prefix the same evidence boundary Calliope uses on every non-box question.
OpenRouter is the default. Every POST goes through one resolver: a bare id stays on OpenRouter, name:model uses a provider secret, and http://host:port/model is a raw address. That is the shape for a vLLM or llama.cpp server.
API 'openai' has no decisions endpoint unless you add DECISIONS true. Without it, a decision or locate call names the provider and says a chat structured-output fallback is not implemented yet. ledger() adds provider and base_host.
CREATE SECRET gpu (
TYPE rvbbit_provider,
BASE_URL 'http://3090:8000',
API 'openai',
KEY 'optional',
MAX_CONCURRENCY 2
);
SET rvbbit_chat_model = 'gpu:llama';
SET rvbbit_embed_model = 'gpu:bge-m3';
SELECT rvbbit.embed('cancel the order');Model Context Protocol
Primitives and grammar, inside the extension. HTTP (streamable, plus legacy SSE) and stdio both run in-process. The secret type is rvbbit_mcp, not duckdb_mcp's attach form.
CREATE SECRET gh (TYPE rvbbit_mcp, TRANSPORT 'http', URL 'https://mcp.example/mcp', TOKEN '...');
SELECT rvbbit.mcp_attach('gh', 'gh');
SELECT rvbbit.mcp_text('gh', 'search', '{"q":"cancel"}');rvbbit_mcp_allow_in_txn is set.rvbbit_mcp_max_mutations caps mutations per query (default 100).rvbbit_mcp_policy allows or denies server tools for read and mutate, as JSON.rvbbit_mcp_allowed_commands. Empty denies all stdio.SET lock_configuration = true.WITH IDEMPOTENCY. Tokens and env values are not stored in the audit log.A tool is a read when rvbbit_mcp_read_toolsmatches it, else when the secret's READ_TOOLS does (and MUTATE_TOOLS does not), else when the server sent readOnlyHint. No hint means a mutation. mcp_tools() shows the choice in mode and source.
mcp_rows calls the tool once at bind and freezes the columns. An array, or an object that holds one array, becomes columns. An object with no array is one row. Otherwise each content block is a row.
mcp_wrap creates a scalar and a table macro per tool in mcp_<server>. A mutation returns STRUCT(result, is_error), matching CALL MCP. The mode and policy still apply when the macro runs.
Function reference
So nothing collides with other extensions. apart, for example, already owns an unqualified decision_tree. The full catalog has arguments, defaults, return types and an example for each function, and CI fails if it drifts from duckdb_functions().
rvbbit.truthrvbbit.truth_scorervbbit.chooservbbit.decidervbbit.truth_questionrvbbit.choice_questionrvbbit.semantic_caservbbit.prompt| Setting | Default | Role |
|---|---|---|
rvbbit_transport | live | mock answers locally. Tests use this. |
rvbbit_max_concurrency | 8 | In-flight HTTP cap for OpenRouter, and the fallback when a provider secret omits MAX_CONCURRENCY. Each provider has its own cap. |
rvbbit_max_retries | 3 | Extra attempts after 429 or 5xx. |
rvbbit_retry_base_ms | 200 | First backoff. Later attempts double it, capped at 2s. |
rvbbit_cache_size | 10000 | LRU entries. |
rvbbit_cache_path | empty | DuckDB file for judgments and trees. |
rvbbit_base_url | empty | Overrides the OpenRouter origin. Named providers and raw addresses keep their own origin. |
rvbbit_decision_model | empty | Jev model. A bare id stays on OpenRouter. name:model uses a provider secret. http://host:port/model is a raw address. |
rvbbit_chat_model | empty | Chat model. Same three forms as rvbbit_decision_model. |
rvbbit_embed_model | empty | Embeddings model. Same three forms. Empty uses the secret or mongodb/voyage-4. voyageai/voyage-4 is rewritten only on OpenRouter. |
rvbbit_vision_model | empty | locate's model. Empty keeps typesafe/jev-1.14 on OpenRouter. Same three forms. |
rvbbit_embed_dim | 0 | 0 uses the secret or 1024. Any other value is the list length embed returns and the dimensions field sent to OpenRouter. |
rvbbit_reasoning | disabled | disabled sends {"enabled": false}. none, minimal, low, medium, and high send {"effort": ...}. enabled turns reasoning on. |
rvbbit_timeout_sec | 60 | Timeout for one POST. Connect timeout is 10 seconds. |
rvbbit_tls_verify | true | Set false only for a local certificate, as scripts/transport_smoke.sh does. |
rvbbit_ignore_env | false | Ignore OPENROUTER_API_KEY. |
rvbbit_mcp_allowed_commands | empty | Exact absolute paths allowed to spawn for stdio MCP. Empty denies all stdio. lock_configuration freezes it. |
rvbbit_mcp_policy | empty | JSON, or a path to JSON, allowing or denying server tools for read and mutate. Empty allows every attached tool. lock_configuration freezes it. |
rvbbit_mcp_max_mutations | 100 | MCP mutations allowed in one query. lock_configuration freezes it. |
rvbbit_mcp_allow_in_txn | false | Permit a mutation inside BEGIN. lock_configuration freezes it. |
rvbbit_mcp_server_concurrency | 4 | In-flight HTTP calls per MCP server. stdio stays at one. lock_configuration freezes it. |
rvbbit_mcp_read_tools | empty | JSON object of server name to tool globs, such as {"gh":["read_*","list_*"]}. A match forces a read. lock_configuration freezes it. |
Install
Pinned to DuckDB 2.0.1 through the official C++ extension template. The community descriptor draft lives in the repo, and is not in duckdb/community-extensions until that submission is approved.
Available now
git clone --recurse-submodules https://github.com/ryrobes/rvbbitduck.git
cd rvbbitduck
sudo apt-get install -y ninja-build build-essential python3 libcurl4-openssl-dev pkg-config # once
GEN=ninja make release./build/release/duckdb links rvbbit, so LOAD rvbbit works there. A stock DuckDB binary loads the shared library by path:
LOAD 'build/release/extension/rvbbit/rvbbit.duckdb_extension';Coming soon
After the submission is accepted, a DuckDB 2.0.1 build installs it with:
INSTALL rvbbit FROM community;
LOAD rvbbit;
SELECT rvbbit.version();The draft targets linux_amd64, linux_arm64, osx_amd64, osx_arm64 and windows_amd64. WASM builds are not part of it. Windows builds OpenRouter HTTP, and MCP on Windows raises and names the reason.
Create an OpenRouter secret, or export OPENROUTER_API_KEY. Want to look around without a key? SET rvbbit_transport = 'mock' answers locally.
CI never calls OpenRouter. scripts/live_smoke.sh exits immediately unless OPENROUTER_API_KEY is set, and the Linux workflow fails if that variable is present, so a secret cannot be spent by accident.
LOAD rvbbit;
SET rvbbit_transport = 'mock'; -- no key needed, nothing leaves the process
SELECT rvbbit.version();
SELECT rvbbit.truth('please cancel the appointment', 'the customer wants to cancel');How it differs
What you get here that those do not: a lazy tree with prior-judgment context, evidence binding, an audited path, and wave batching across the rows of a vector. SQL that composes in WHERE, JOIN and GROUP BY. And opt-in words that desugar to those functions.
| Extension | What it is | What it does not do |
|---|---|---|
decide | decision, decision_prob, decision_choice, decision_score over OpenAI Decisions / Jev. Small batches, low concurrency. | No trees, no grammar, no shared chat operators. |
jev | jev, jev_prob, jev_choice, jev_score, jev_eval. | Scalar judgments only. |
querio_jev | OpenRouter, a disk cache, dedupe, httpfs. | No lazy tree, no path trace. |
typed_ai | typed_is, typed_pick, typed_score, typed_box, budgets. | No tree walk. |
anofox_decide | Many backends, including ONNX, plus calibration metrics. | No OpenRouter tree language. |
dc | A fast path and a slow path. | No grammar and no decision tree. |
ai | A wide LLM suite, including ai_jev / ai_decide, many providers. | Not a port of rvbbit's tree contract. |
flock | llm_complete, filter, reduce, embeddings, and MODEL/PROMPT objects. | Objects are prompts, not a lazy judged tree. |
apart | A numeric affine decision_tree. | Name collision only. Different function, different schema. |
Straight talk
This is a young extension. These are the edges in the README today, so you do not find them by surprise.
takes.nodes execution.M and ef_construction.LivePostMany.FAQ
No. The extension makes its own OpenRouter calls through libcurl. By default it posts to https://openrouter.ai. You would only point rvbbit_base_url at Hutch or another gateway if that gateway serves /api/alpha/decisions, /api/v1/chat/completions and /api/v1/embeddings.
An OpenRouter key. Create a secret with CREATE SECRET (TYPE openrouter, KEY '...') or set OPENROUTER_API_KEY. If both exist, the secret is used first: the environment variable is the fallback when no secret is present.
No. HTTP is the extension's own bundled libcurl client, which shares a connection cache and asks for HTTP/2. LOAD rvbbit works without httpfs.
SET rvbbit_transport = 'mock' answers locally without OPENROUTER_API_KEY. The extension's test suite runs on that transport and never leaves the process. A live call needs a key.
No. Everything works as plain functions. MEANS, ABOUT, SEMANTIC CASE, CREATE DECISION TREE, DECIDE, FROM MCP and CALL MCP are opt-in sugar: SET active_grammar_extensions = ['rvbbit']. They desugar to the same functions.
SELECT * FROM rvbbit.ledger() has one row per call and per cache hit. rvbbit.spend() totals requests, cache hits, tokens and cost. Cache hits cost 0. Calls to other providers cost 0 unless the response reports usage.cost.
429 and 5xx responses retry with backoff and honor Retry-After up to 5 seconds. A connection failure raises, and so does a non-retryable 4xx such as 401 or 403. Neither comes back as NULL.
Yes, mutations are first-class. They are never cached, they are refused inside an explicit transaction unless you set rvbbit_mcp_allow_in_txn, and rvbbit_mcp_max_mutations caps them per query. A tool counts as a read only when your settings or the server's readOnlyHint say so. No hint means a mutation.
There is no WASM build yet: the native client is libcurl. Windows builds support OpenRouter HTTP, and MCP on Windows raises with the reason. The community draft targets linux_amd64, linux_arm64, osx_amd64, osx_arm64 and windows_amd64.
Not yet. The descriptor draft is in the repo and is not in duckdb/community-extensions until its submission is approved. Until then, build it from source.
Open source, MIT, and one OpenRouter key away. Star it, build it, and file what breaks.
rvbbitduck is MIT licensed. Copyright 2026 Ryan Robitaille. It ports the decision core of rvbbit 1.2.3.