Skip to content

LLM

Call LLMs from SQL — Anthropic, OpenAI, OpenRouter or local Ollama — plus local embeddings

Connector software
Free and open source
Service credentials
Optional
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/llm/index.md to help me query LLM 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.

Find documents by meaning with local embeddings

Example output · captured
Connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
WITH docs(doc) AS (VALUES ('DuckDB is an in-process analytical SQL database'), ('Paris is the capital of France'), ('Kittens are young cats'), ('PostgreSQL is a client-server relational database')), q AS (SELECT llm.main.ai_embed('embedded database for analytics') AS v) SELECT doc, ROUND(llm.main.ai_similarity(llm.main.ai_embed(doc), q.v), 3) AS score
FROM docs,
     q
ORDER BY score DESC
LIMIT 2
Result
doc score
DuckDB is an in-process analytical SQL database 0.784
PostgreSQL is a client-server relational database 0.712

Quick start

Choose where to run LLM, 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.

setup.sql
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;

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 'llm' AS llm (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-llm-worker'
);

3. Add service credentials (optional)

Local embeddings and Ollama need no key; add provider keys for hosted models. Replace the placeholders with your service settings.

llm credentials

Provider keys for vgi-llm (one field per backend: Anthropic / OpenRouter / OpenAI / Ollama).

Get these credentials →
secret.sql
CREATE SECRET llm (
    TYPE llm,
    anthropic_api_key  '<ANTHROPIC_API_KEY>',  -- secret
    openrouter_api_key '<OPENROUTER_API_KEY>',  -- secret
    openai_api_key     '<OPENAI_API_KEY>',  -- secret
    ollama_host        '<ollama_host>'
);
Credential fields and requirements →

4. Run a query

query.sql
WITH docs(doc) AS (VALUES ('DuckDB is an in-process analytical SQL database'), ('Paris is the capital of France'), ('Kittens are young cats'), ('PostgreSQL is a client-server relational database')), q AS (SELECT llm.main.ai_embed('embedded database for analytics') AS v) SELECT doc, ROUND(llm.main.ai_similarity(llm.main.ai_embed(doc), q.v), 3) AS score
FROM docs,
     q
ORDER BY score DESC
LIMIT 2
More example queries →
Technical details
Verified connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
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 'llm' AS llm (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-llm-worker'
);

Overview

AI SQL functions for DuckDB over a pluggable LLM provider (Anthropic/OpenRouter/OpenAI/Ollama) + keyless local embeddings (BAAI/bge-small-en-v1.5, 384-dim).

Catalog

Everything llm exposes once attached — read straight from the worker's released build.

llm 1 schema
main 14 functions

AISQL: completion, structured output, embeddings, aggregates, and utilities.

Schema examples (9)
Examples (9)

Embed text into a FLOAT[] vector (keyless local ONNX).

SELECT llm.main.ai_embed('hello world');

Cosine similarity of two embeddings (keyless).

SELECT llm.main.ai_similarity(llm.main.ai_embed('cat'), llm.main.ai_embed('kitten'));

Build a prompt string by safe template substitution (pure, no model).

SELECT llm.main.prompt('Summarize: {}', 'DuckDB is an in-process OLAP database');

Count tokens locally with tiktoken (no model call).

SELECT llm.main.ai_count_tokens('the quick brown fox');
5 more examples

Complete a prompt with the default provider.

SELECT llm.main.ai_complete('Write a haiku about DuckDB');

Classify text into a subset of the given categories.

SELECT llm.main.ai_classify('my card was declined', ['billing','bug','feature']).labels;

Semantic search (keyless): embed the search phrase once with ai_embed and rank a table of documents by ai_similarity to it, keeping the top 2. The two database sentences outrank the unrelated ones.

WITH docs(doc) AS (VALUES ('DuckDB is an in-process analytical SQL database'), ('Paris is the capital of France'), ('Kittens are young cats'), ('PostgreSQL is a client-server relational database')), q AS (SELECT llm.main.ai_embed('embedded database for analytics') AS v) SELECT doc, ROUND(llm.main.ai_similarity(llm.main.ai_embed(doc), q.v), 3) AS score
FROM docs,
     q
ORDER BY score DESC
LIMIT 2;
Result
doc score
DuckDB is an in-process analytical SQL database 0.784
PostgreSQL is a client-server relational database 0.712

Keyless zero-shot routing: embed each support ticket and each label's description with ai_embed, then pick the label with the highest ai_similarity per ticket via arg_max (billing / bug / feature, one row per ticket with its best score).

WITH tickets(ticket) AS (VALUES ('I was charged twice for my subscription this month'), ('The app crashes every time I upload a photo'), ('Please add a dark mode to the dashboard')), labels(label, hint) AS (VALUES ('billing', 'payments, invoices, refunds and charges'), ('bug', 'the software crashes or shows an error'), ('feature', 'a request for a new capability')), t AS (SELECT ticket, llm.main.ai_embed(ticket) AS v FROM tickets), l AS (SELECT label, llm.main.ai_embed(hint) AS v FROM labels) SELECT ticket, arg_max(label, llm.main.ai_similarity(t.v, l.v)) AS label, ROUND(max(llm.main.ai_similarity(t.v, l.v)), 3) AS score
FROM t,
     l
GROUP BY ticket
ORDER BY ticket;

Pre-flight cost estimate before calling a model: render one prompt per review row with prompt() and count its tokens locally with ai_count_tokens, plus the batch total (no model call, no key).

WITH reviews(id, product, review) AS (VALUES (1, 'laptop', 'Battery barely lasts two hours and the fan is loud.'), (2, 'headphones', 'Great sound, but the ear cushions started peeling after a month.'), (3, 'blender', 'Works fine.')) SELECT id, llm.main.ai_count_tokens(llm.main.prompt('Summarize this {} review in one sentence: {}', product, review)) AS prompt_tokens, SUM(prompt_tokens) OVER () AS total_tokens
FROM reviews
ORDER BY id;
Scalar functions
ai_classify (input VARCHAR, categories VARCHAR[], model VARCHAR) +1 overload 2 examples

Classify text into a subset of the given categories; returns STRUCT{labels LIST}.

Arguments
input VARCHAR
Text to classify.
categories VARCHAR[]
The set of category labels to choose from.
model VARCHAR
Provider-prefixed model to route to; the leading path segment picks the backend, empty uses the default.
Overloads
ai_classify(input VARCHAR, categories VARCHAR[]) → STRUCT(labels VARCHAR[])ai_classify(input VARCHAR, categories VARCHAR[], model VARCHAR) → STRUCT(labels VARCHAR[])
ReturnsSTRUCT(labels VARCHAR[])
Examples (2)

Classify text against a category list

SELECT llm.main.ai_classify('my card was declined', ['billing','bug','feature']).labels;

Classify with an explicit provider/model

SELECT llm.main.ai_classify(t, ['billing','bug'], 'ollama/llama3.2').labels
FROM (VALUES ('my card was declined')) AS x(t);
Link
ai_complete (prompt VARCHAR, model VARCHAR) +1 overload 2 examples

LLM text completion for each prompt row (default model); NULL on empty input, errors raise.

Arguments
prompt VARCHAR
Prompt text to complete.
model VARCHAR
Provider-prefixed model to route to; the leading path segment picks the backend, empty uses the default.
Overloads
ai_complete(prompt VARCHAR) → VARCHARai_complete(prompt VARCHAR, model VARCHAR) → VARCHAR
ReturnsVARCHAR
Examples (2)

Complete a prompt with the default model

SELECT llm.main.ai_complete('Write a haiku about DuckDB');

Complete a prompt with an explicit provider/model

SELECT llm.main.ai_complete('Summarize DuckDB in one line', 'ollama/llama3.2');
Link
ai_complete_details (prompt VARCHAR, model VARCHAR) +1 overload 2 examples

LLM completion returning a STRUCT of text + model + token usage + finish reason.

Arguments
prompt VARCHAR
Prompt text to complete.
model VARCHAR
Provider-prefixed model to route to; the leading path segment picks the backend, empty uses the default.
Overloads
ai_complete_details(prompt VARCHAR) → STRUCT of 5 fieldsai_complete_details(prompt VARCHAR, model VARCHAR) → STRUCT of 5 fields
ReturnsSTRUCT of 5 fields
STRUCT 5 fields
  • textVARCHAR
  • modelVARCHAR
  • input_tokensBIGINT
  • output_tokensBIGINT
  • finish_reasonVARCHAR
Examples (2)

Completion with token/metadata envelope

SELECT llm.main.ai_complete_details('Explain MVCC in one sentence').text;

Completion details with an explicit provider/model

SELECT llm.main.ai_complete_details('Explain MVCC', 'openrouter/anthropic/claude-sonnet-5').output_tokens;
Link
ai_complete_image (prompt VARCHAR, image BLOB, model VARCHAR) +1 overload 2 examples

Multimodal LLM completion over a text prompt + an image BLOB (default model).

Arguments
prompt VARCHAR
Instruction/question about the image.
image BLOB
Image bytes to analyze (PNG/JPEG/GIF/WebP).
model VARCHAR
Provider-prefixed model to route to; the leading path segment picks the backend, empty uses the default.
Overloads
ai_complete_image(prompt VARCHAR, image BLOB) → VARCHARai_complete_image(prompt VARCHAR, image BLOB, model VARCHAR) → VARCHAR
ReturnsVARCHAR
Examples (2)

Describe an image column with the default model

SELECT llm.main.ai_complete_image('What is in this image?', '\x89PNG'::BLOB);

Describe an image with an explicit vision model

SELECT llm.main.ai_complete_image('Describe it', '\x89PNG'::BLOB, 'openai/gpt-4o');
Link
ai_count_tokens (input VARCHAR, model VARCHAR) +1 overload 3 examples

Count tokens per text with a local tiktoken tokenizer (no network); BIGINT.

Arguments
input VARCHAR
Text to count tokens for.
model VARCHAR
Model whose tokenizer to use (OpenAI models are exact).
Overloads
ai_count_tokens(input VARCHAR) → BIGINTai_count_tokens(input VARCHAR, model VARCHAR) → BIGINT
ReturnsBIGINT
Examples (3)

Count the tokens in a text

SELECT llm.main.ai_count_tokens('the quick brown fox');

Pre-flight cost estimate before calling a model: render one prompt per review row with prompt() and count its tokens locally with ai_count_tokens, plus the batch total (no model call, no key).

WITH reviews(id, product, review) AS (VALUES (1, 'laptop', 'Battery barely lasts two hours and the fan is loud.'), (2, 'headphones', 'Great sound, but the ear cushions started peeling after a month.'), (3, 'blender', 'Works fine.')) SELECT id, llm.main.ai_count_tokens(llm.main.prompt('Summarize this {} review in one sentence: {}', product, review)) AS prompt_tokens, SUM(prompt_tokens) OVER () AS total_tokens
FROM reviews
ORDER BY id;

Count tokens with a specific model's tokenizer

SELECT llm.main.ai_count_tokens('the quick brown fox', 'openai/gpt-4o');
Link
ai_embed (input VARCHAR, model VARCHAR) +1 overload 3 examples

Embed text into a 384-dim FLOAT[] with the local default model (BAAI/bge-small-en-v1.5); keyless. NULL/empty -> NULL.

Arguments
input VARCHAR
Text to embed.
model VARCHAR
Local embedding model name (e.g. 'BAAI/bge-base-en-v1.5').
Overloads
ai_embed(input VARCHAR) → FLOAT[]ai_embed(input VARCHAR, model VARCHAR) → FLOAT[]
ReturnsFLOAT[]
Examples (3)

Embed text into a FLOAT[] vector (keyless)

SELECT len(llm.main.ai_embed('hello world'));

Keyless zero-shot routing: embed each support ticket and each label's description with ai_embed, then pick the label with the highest ai_similarity per ticket via arg_max (billing / bug / feature, one row per ticket with its best score).

WITH tickets(ticket) AS (VALUES ('I was charged twice for my subscription this month'), ('The app crashes every time I upload a photo'), ('Please add a dark mode to the dashboard')), labels(label, hint) AS (VALUES ('billing', 'payments, invoices, refunds and charges'), ('bug', 'the software crashes or shows an error'), ('feature', 'a request for a new capability')), t AS (SELECT ticket, llm.main.ai_embed(ticket) AS v FROM tickets), l AS (SELECT label, llm.main.ai_embed(hint) AS v FROM labels) SELECT ticket, arg_max(label, llm.main.ai_similarity(t.v, l.v)) AS label, ROUND(max(llm.main.ai_similarity(t.v, l.v)), 3) AS score
FROM t,
     l
GROUP BY ticket
ORDER BY ticket;

Embed with an explicitly chosen local model

SELECT len(llm.main.ai_embed('hello world', 'BAAI/bge-base-en-v1.5'));
Link
ai_extract (input VARCHAR, response_format VARCHAR, model VARCHAR) +1 overload 2 examples

Extract structured JSON from text per a JSON-Schema string; returns a JSON VARCHAR.

Arguments
input VARCHAR
Text to extract structured data from.
response_format VARCHAR
JSON-Schema string describing the fields to extract.
model VARCHAR
Provider-prefixed model to route to; the leading path segment picks the backend, empty uses the default.
Overloads
ai_extract(input VARCHAR, response_format VARCHAR) → VARCHARai_extract(input VARCHAR, response_format VARCHAR, model VARCHAR) → VARCHAR
ReturnsVARCHAR
Examples (2)

Extract fields as JSON per a schema

SELECT llm.main.ai_extract('Bob is 42', '{"type":"object","properties":{"age":{"type":"integer"}}}');

Extract JSON with an explicit provider/model

SELECT llm.main.ai_extract(t, '{"type":"object"}', 'ollama/llama3.2')
FROM (VALUES ('Bob is 42')) AS x(t);
Link
ai_filter (predicate VARCHAR, input VARCHAR, model VARCHAR) +1 overload 2 examples

Evaluate a natural-language predicate over text; BOOLEAN, NULL on empty/unclear, errors raise.

Arguments
predicate VARCHAR
Natural-language condition to test for each row.
input VARCHAR
Text the predicate is evaluated against.
model VARCHAR
Provider-prefixed model to route to; the leading path segment picks the backend, empty uses the default.
Overloads
ai_filter(predicate VARCHAR, input VARCHAR) → BOOLEANai_filter(predicate VARCHAR, input VARCHAR, model VARCHAR) → BOOLEAN
ReturnsBOOLEAN
Examples (2)

Boolean predicate over text

SELECT llm.main.ai_filter('the text is a question', 'How do I reset my password?');

Boolean predicate with an explicit provider/model

SELECT llm.main.ai_filter('mentions a refund', body, 'ollama/llama3.2')
FROM (VALUES ('Please refund my order')) AS x(body);
Link
ai_sentiment (input VARCHAR, model VARCHAR) +1 overload 2 examples

Analyse sentiment; returns STRUCT{overall, categories LIST<STRUCT{name, sentiment}>}.

Arguments
input VARCHAR
Text to analyse for sentiment.
model VARCHAR
Provider-prefixed model to route to; the leading path segment picks the backend, empty uses the default.
Overloads
ai_sentiment(input VARCHAR) → STRUCT of 2 fieldsai_sentiment(input VARCHAR, model VARCHAR) → STRUCT of 2 fields
ReturnsSTRUCT of 2 fields
STRUCT 2 fields
  • overallVARCHAR
  • categoriesSTRUCT[]
    STRUCT[] 2 fields
    • nameVARCHAR
    • sentimentVARCHAR
Examples (2)

Overall + per-aspect sentiment

SELECT llm.main.ai_sentiment('The food was great but service was slow').overall;

Sentiment with an explicit provider/model

SELECT llm.main.ai_sentiment(review, 'ollama/llama3.2').overall
FROM (VALUES ('The food was great but service was slow')) AS x(review);
Link
ai_similarity (a VARCHAR, b VARCHAR, model VARCHAR) +2 overloads 4 examples

Cosine similarity of two FLOAT[] vectors, in [-1, 1] (pure arithmetic); NULL on mismatch.

Arguments
a VARCHAR
First embedding vector.
b VARCHAR
Second embedding vector.
model VARCHAR
Local embedding model name (e.g. 'BAAI/bge-small-en-v1.5').
Overloads
ai_similarity(a FLOAT[], b FLOAT[]) → DOUBLEai_similarity(a VARCHAR, b VARCHAR) → DOUBLEai_similarity(a VARCHAR, b VARCHAR, model VARCHAR) → DOUBLE
ReturnsDOUBLE
Examples (4)

Cosine similarity between two embeddings

SELECT llm.main.ai_similarity(llm.main.ai_embed('cat'), llm.main.ai_embed('kitten'));

Semantic search (keyless): embed the search phrase once with ai_embed and rank a table of documents by ai_similarity to it, keeping the top 2. The two database sentences outrank the unrelated ones.

WITH docs(doc) AS (VALUES ('DuckDB is an in-process analytical SQL database'), ('Paris is the capital of France'), ('Kittens are young cats'), ('PostgreSQL is a client-server relational database')), q AS (SELECT llm.main.ai_embed('embedded database for analytics') AS v) SELECT doc, ROUND(llm.main.ai_similarity(llm.main.ai_embed(doc), q.v), 3) AS score
FROM docs,
     q
ORDER BY score DESC
LIMIT 2;
Result
doc score
DuckDB is an in-process analytical SQL database 0.784
PostgreSQL is a client-server relational database 0.712

Cosine similarity of two texts (embedded locally)

SELECT ROUND(llm.main.ai_similarity('cat', 'kitten'), 3) AS score;
1 more example

Cosine similarity of two texts with a chosen model

SELECT ROUND(llm.main.ai_similarity('cat', 'kitten', 'BAAI/bge-small-en-v1.5'), 3) AS score;
Link
ai_summarize (input VARCHAR, model VARCHAR) +1 overload 2 examples

Summarize each text into a short summary (default model); NULL on empty input, errors raise.

Arguments
input VARCHAR
Text to summarize.
model VARCHAR
Provider-prefixed model to route to; the leading path segment picks the backend, empty uses the default.
Overloads
ai_summarize(input VARCHAR) → VARCHARai_summarize(input VARCHAR, model VARCHAR) → VARCHAR
ReturnsVARCHAR
Examples (2)

Summarize a text

SELECT llm.main.ai_summarize('DuckDB is an in-process SQL OLAP database ...');

Summarize with an explicit provider/model

SELECT llm.main.ai_summarize(body, 'ollama/llama3.2')
FROM (VALUES ('DuckDB is an in-process OLAP database.')) AS x(body);
Link
prompt (template VARCHAR, args ANY) 1 example

Safely substitute positional args into a template ({} / {n}); pure, no model call.

Arguments
template VARCHAR
Template with positional {} placeholders.
args ANY
Values substituted into the template (one or more columns).
ReturnsVARCHAR
Example

Fill a template with positional arguments

SELECT llm.main.prompt('Translate {} into {}', 'hello', 'French');
Link
Aggregate functions
ai_agg (value VARCHAR, task VARCHAR) 1 example

Aggregate a group's text rows by applying a task via chunked LLM map-reduce; VARCHAR per group.

Arguments
value VARCHAR
Text column to aggregate over the group.
task VARCHAR
Natural-language task to apply across the group. · default ""
ReturnsVARCHAR
Example

Reduce a group's rows to one answer with a task

SELECT llm.main.ai_agg(comment, 'List the top complaints')
FROM (VALUES ('too slow'), ('buggy UI')) AS t(comment);
Link
ai_summarize_agg (value VARCHAR) 1 example

Summarize all of a group's text rows into one summary via chunked map-reduce; VARCHAR per group.

Arguments
value VARCHAR
Text column to summarize over the group.
ReturnsVARCHAR
Example

Summarize all of a group's rows into one summary

SELECT llm.main.ai_summarize_agg(note)
FROM (VALUES ('login failed'), ('disk full')) AS t(note);
Link

Credentials

The secret type llm declares, as reported by the worker itself.

llm

How to get these credentials

Provider keys for vgi-llm (one field per backend: Anthropic / OpenRouter / OpenAI / Ollama).

secret.sql
CREATE SECRET llm (
    TYPE llm,
    anthropic_api_key  '<ANTHROPIC_API_KEY>',  -- secret
    openrouter_api_key '<OPENROUTER_API_KEY>',  -- secret
    openai_api_key     '<OPENAI_API_KEY>',  -- secret
    ollama_host        '<ollama_host>'
);
Key Type Required Description
anthropic_api_key secret VARCHAR — Anthropic API key (sk-ant-...) from console.anthropic.com > API Keys
openrouter_api_key secret VARCHAR — OpenRouter API key (sk-or-...) from openrouter.ai/keys
openai_api_key secret VARCHAR — OpenAI API key (sk-...) from platform.openai.com/api-keys
ollama_host VARCHAR — Base URL of a local Ollama daemon, e.g. http://localhost:11434 (no key needed)

The worker doesn't mark which keys are required.

Needed by ai_completeai_complete_detailsai_complete_imageai_classifyai_filterai_extractai_sentimentai_summarizeai_aggai_summarize_agg

Create the secret in the same session, after attaching llm — the worker registers its secret types at ATTACH. Keys marked secret are masked in duckdb_secrets(); angle-bracket values are placeholders. Read credentials from your environment or secret store in your application and pass them through your SQL client’s parameter bindings. Keep real values out of saved SQL and history. Native DuckDB and Haybarn do not provide a SQL getenv() function.

Settings

Attaching llm registers 6 DuckDB settings. Change one with SET for the session (or SET GLOBAL), read it back with current_setting('…'), and the worker's functions pick the new value up on the next query.

llm_max_tokensBIGINT
Max output tokens per completion (default 4096). default 4096
llm_max_workersBIGINT
Max concurrent provider calls per batch (default 8). default 8
llm_modelVARCHAR
Global default model when a call's model arg is empty ('' = none).
llm_temperatureDOUBLE
Sampling temperature (0-2); < 0 means unset/not sent. default -1.0
llm_timeoutDOUBLE
Per-request provider timeout in seconds (default 60). default 60.0
llm_top_pDOUBLE
Nucleus-sampling top_p (0-1); < 0 means unset/not sent. default -1.0
settings.sql
SET llm_max_tokens = 4096;
SET llm_max_workers = 8;
SET llm_model = '';
SET llm_temperature = -1.0;
SET llm_timeout = 60.0;
SET llm_top_p = -1.0;
SELECT current_setting('llm_max_tokens');

Try these queries

embed_dimension — Embed a string into a fixed-length FLOAT[] with the local default model (keyless).

SELECT len(llm.main.ai_embed('hello world')) AS dim;

Uses ai_embed

self_similarity — A phrase is maximally similar to itself (keyless).

SELECT ROUND(llm.main.ai_similarity(llm.main.ai_embed('database'), llm.main.ai_embed('database')), 3) AS sim;

Uses ai_similarityai_embed

prompt_template — Build a prompt string by positional substitution (pure, no model).

SELECT llm.main.prompt('Translate {} into {}', 'hello', 'French') AS p;

Uses prompt

token_estimate — Estimate a text's token count locally (no model call).

SELECT llm.main.ai_count_tokens('the quick brown fox') AS tokens;

Uses ai_count_tokens

Complete a prompt with the default provider.

SELECT llm.main.ai_complete('Write a haiku about DuckDB')

Uses ai_complete

Classify text into a subset of the given categories.

SELECT llm.main.ai_classify('my card was declined', ['billing','bug','feature']).labels

Uses ai_classify

28 more examples in the Catalog, each listed under the table or function it uses.

Questions it can answer

Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.

  • Embed the word 'database' and confirm the vector has 384 dimensions. Return a single boolean.
  • Compute the cosine similarity of the embedding of 'database' with itself, rounded to 3 decimals.
  • Is 'dog' more similar to 'puppy' than to 'airplane'? Return a single boolean.
  • Use the prompt() function to render 'Hi {}' with the value 'Sam'.
  • Estimate the number of tokens in the text 'the quick brown fox' and confirm it is positive.
  • Ask the model to reply with the single word pong and confirm a non-empty answer comes back.

LLM 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.