One shop, every kind of query
One schema, a game shop's products, reviews and the items bought together. Every statement runs unchanged on a file in your app or on one server, and all but the graph queries and ON CONFLICT run through a cluster's coordinator too.
Three tables in one file
Products with text, columns, JSON and an embedded vector; reviews placed by customer; bought_with is a table and a graph.
CREATE TABLE products ( id KEYWORD PRIMARY KEY, title TEXT, features TEXT, brand KEYWORD, category KEYWORD, platforms KEYWORD[], price FLOAT, rating FLOAT, ratings INT, in_stock BOOL DEFAULT TRUE, released TIMESTAMP, attrs JSON OPTIONS(text = true), emb VECTOR OPTIONS(embed = 'title, features', model = 'potion-retrieval-32M') ); CREATE TABLE reviews ( id KEYWORD PRIMARY KEY, usr KEYWORD NOT NULL, item KEYWORD NOT NULL REFERENCES products, stars INT, body TEXT, ts TIMESTAMP ) OPTIONS(shard_by = 'usr', cluster_by = 'usr'); CREATE TABLE bought_with ( id KEYWORD PRIMARY KEY, src KEYWORD NOT NULL REFERENCES products, dst KEYWORD NOT NULL REFERENCES products, w FLOAT DEFAULT 0 ) OPTIONS(edges = 'src, dst, w');
A search box
Words, typos and synonyms
BM25 over the title, typos and synonyms, under ordinary filters.
SELECT id, title, price, score() FROM products WHERE MATCH(title, 'controler~ OR gamepad', synonyms => 1) AND price BETWEEN 20 AND 60 AND in_stock ORDER BY bm25(title, 'controller gamepad') DESC LIMIT 10;
Facets beside the results
Facet counts are one more statement on the same snapshot.
SELECT brand, COUNT(*), AVG(rating), MIN(price) FROM products WHERE MATCH(title, :q) GROUP BY brand HAVING COUNT(*) >= 3 ORDER BY 2 DESC LIMIT 8;
Autocomplete from what people searched
Each search counts itself, and the box completes from those counts, typos forgiven.
CREATE TABLE queries (id KEYWORD PRIMARY KEY, n INT DEFAULT 0) OPTIONS(cluster_by = 'id'); INSERT INTO queries (id, n) VALUES (:q, 1) ON CONFLICT (id) DO UPDATE SET n = n + 1; SELECT id, n FROM queries WHERE PREFIX(id, :typed, fuzzy => 'auto') ORDER BY n DESC, id LIMIT 8;
Vectors and hybrid
Search by meaning
Pass text; the database embeds it with the field's own model.
db.query("""SELECT id, title FROM products
WHERE category = 'Accessories' AND price < 40
ORDER BY similarity(emb, :v) DESC LIMIT 10""",
v={"embed": "something to keep my console cool"})
Words and meaning, fused
Weighted scores, or rank fusion with no weights to tune.
-- weighted, on scores scaled to 0..1 SELECT id, title, score() FROM products WHERE in_stock ORDER BY 0.5 * minmax(bm25(title, :q)) + 0.5 * minmax(similarity(emb, :v)) DESC LIMIT 10; -- by rank, with no weights to tune SELECT id, title, score() FROM products WHERE in_stock ORDER BY rrf(bm25(title, :q), similarity(emb, :v)) DESC LIMIT 10;
More like this one
-- :v = {"vector_of": "B07XYZ", "field": "emb"}
SELECT id, title FROM products WHERE id != 'B07XYZ'
ORDER BY similarity(emb, :v) DESC LIMIT 10;
Ranking
Any expression of scores and columns
Relevance, rating and age in one order.
SELECT id, title, score() FROM products WHERE MATCH(title, :q)
ORDER BY ln(1 + bm25(title, :q)) * (1 + 0.2 * coalesce(rating, 0))
+ decay(released, now(), 2592000) DESC LIMIT 10;
A cheap first phase, then a reranker
A cheap first phase keeps twenty rows; a cross-encoder orders the top ten. A server reranks at most 20 rows unless started with --max-rerank.
WITH top AS (
SELECT * FROM products
ORDER BY rrf(bm25(title, :q), similarity(emb, :v)) DESC LIMIT 20
)
SELECT id, title, score() FROM top
ORDER BY cross_encoder('ms-marco-MiniLM-L-6-v2', title, features, :q) DESC LIMIT 10;
A ranking with a name
A named ranking the app asks for, changed in one place.
CREATE RANK PROFILE shop ON products AS
WITH top AS (SELECT * FROM products ORDER BY bm25(title, :q) DESC LIMIT 200)
SELECT * FROM top ORDER BY bm25(title, :q) * (1 + :pop * ln(1 + ratings)) DESC
WITH (pop => 0.1);
SELECT id, title FROM products WHERE in_stock
ORDER BY rank_profile('shop', q => :q) LIMIT 10;
Recommendations
A recommendation is a query, not a pipeline.
What this customer will want next
A sequence model turns recent reviews into a vector; at most two per brand.
SELECT id, title, brand FROM products WHERE in_stock
ORDER BY similarity(emb, encode('next',
(SELECT item, ts FROM reviews WHERE usr = :u ORDER BY ts DESC LIMIT 200)))
DESC MAX 2 PER brand LIMIT 10;
Bought together, walked from the basket
Personalised PageRank from the items reviewed last.
SELECT id, title, score() FROM products WHERE in_stock ORDER BY ppr(bought_with, (SELECT item FROM reviews WHERE usr = :u ORDER BY ts DESC LIMIT 20)) DESC LIMIT 10;
All three signals at once
SELECT id, title FROM products WHERE in_stock AND MATCH(title, :q)
ORDER BY rrf(
bm25(title, :q),
similarity(emb, encode('next', (SELECT item, ts FROM reviews WHERE usr = :u ORDER BY ts DESC LIMIT 200))),
ppr(bought_with, (SELECT item FROM reviews WHERE usr = :u ORDER BY ts DESC LIMIT 20))
) DESC MAX 2 PER brand LIMIT 10;
Graphs
Two steps out, either direction
SELECT id, title, hops() FROM products WHERE REACHABLE(bought_with, 'B07XYZ', hops => 2, dir => 'both') AND in_stock ORDER BY hops(), id LIMIT 20;
Start the walk from a search
SELECT id, title FROM products WHERE REACHABLE(bought_with, (SELECT id FROM products ORDER BY similarity(emb, :v) DESC LIMIT 3)) LIMIT 50;
Analytics, JSON and plain SQL
A join with aggregates
SELECT p.brand, COUNT(*) AS reviews, AVG(r.stars) AS stars FROM reviews r JOIN products p ON r.item = p.id WHERE r.ts >= '2026-01-01' GROUP BY p.brand ORDER BY reviews DESC LIMIT 10;
Keys no schema names
JSON paths are indexed as they arrive, and their strings are searchable.
SELECT id, title, attrs.dims.w FROM products
WHERE attrs.voltage >= 5 AND attrs.certs = 'UL'
ORDER BY attrs.dims.w DESC LIMIT 10;
SELECT attrs.color, COUNT(*), AVG(price) FROM products GROUP BY attrs.color;
SELECT id, title FROM products WHERE MATCH(attrs, 'usb charger')
ORDER BY bm25(attrs, 'usb charger') DESC LIMIT 10;
SELECT * FROM json_paths('products', 'attrs');
Each customer's latest review
SELECT DISTINCT ON (usr) usr, item, stars, ts FROM reviews ORDER BY ts DESC, id;
Each brand's three best, and a customer's streak
Window functions rank rows without grouping them; QUALIFY filters by them.
SELECT id, title, brand, rating FROM products
WHERE category = 'Headsets'
QUALIFY ROW_NUMBER() OVER (PARTITION BY brand ORDER BY rating DESC, id) <= 3;
SELECT item, stars, ts,
COUNT(*) OVER (ORDER BY ts) AS nth,
stars - LAG(stars) OVER (ORDER BY ts) AS change
FROM reviews WHERE usr = :u ORDER BY ts;
In stock, and not yet reviewed by this customer
SELECT id FROM products WHERE category = 'Headsets' AND in_stock EXCEPT SELECT item FROM reviews WHERE usr = :u;
Change the schema in place
ALTER TABLE products ADD COLUMN stock INT NOT NULL DEFAULT 0; ALTER TABLE products RENAME COLUMN ratings TO rating_count;
See the plan
EXPLAIN SELECT id FROM products WHERE MATCH(title, :q) AND price < 40 ORDER BY rrf(bm25(title, :q), similarity(emb, :v)) DESC LIMIT 10;
Rows by key, and rows that expire
Any table with a primary key is a key-value store, with a time to live per row.
A cart that expires in a week
CREATE TABLE carts ( id KEYWORD PRIMARY KEY, usr KEYWORD, items KEYWORD[], until TIMESTAMP ) OPTIONS(expire_by = 'until');
curl -s -X PUT localhost:7700/v1/kv/carts/c-u7 -H 'content-type: application/json' \
-d '{"usr": "u7", "items": ["B0C1"], "until": "2026-11-09T00:00:00Z"}'
curl -s localhost:7700/v1/kv/carts/c-u7 # one row, no SQL
curl -s localhost:7700/v1/kv/get -H 'content-type: application/json' -d '{"table": "products", "keys": ["B0C1", "B0C2"]}'
The same from Python
db.get("B0C1", table="products") # a dict, or None
db.get_many(["B0C1", "B0C2"], table="products") # in the keys' order
db.expire() # in your process; a server deletes expired rows every few seconds
Data in and out
SQLite files in as tables, and any table back out.
From SQLite
chloedb-server import --db shop.chloedb shop.sqlite # a new file from SQLite's tables curl -s -X POST 'localhost:7700/v1/import?format=sqlite&plan=true' \ -H 'content-type: application/vnd.sqlite3' --data-binary @shop.sqlite # what it would make curl -s 'localhost:7700/v1/export' -o copy.sqlite # and back out
From Python
import chloedb
chloedb.from_sqlite("shop.sqlite", "shop.chloedb")
db = chloedb.open("shop.chloedb")
db.insert([{"id": "B0C1", "title": "Cooling stand", "brand": "Kiwi", "price": 29.0}], table="products")
db.import_file("reviews.jsonl", table="reviews")
Out to pandas, polars and DuckDB
Columns come back as Arrow arrays.
r = db.query_arrow("SELECT brand, price, rating FROM products WHERE price < :p", p=50)
df = r.to_polars() # or r.to_pyarrow(), r.to_pandas()
duckdb.sql("SELECT brand, avg(rating) FROM r GROUP BY brand")
A consistent copy while it serves
curl -s localhost:7700/v1/admin/checkpoint -H 'content-type: application/json' \
-d '{"name": "shop-2026-11-01.chloedb"}'
The same query from every client
In-process and over the network take the same SQL and methods.
import chloedb
db = chloedb.open("shop.chloedb")
rows = db.query(
"SELECT id, title FROM products WHERE in_stock "
"ORDER BY rrf(bm25(title, :q), similarity(emb, :v)) DESC LIMIT 10",
q="wireless controller", v={"embed": "wireless controller"}).rows
import chloedb
db = chloedb.connect("http://127.0.0.1:7700") # one server, or a cluster's coordinator
rows = db.query(
"SELECT id, title FROM products WHERE in_stock "
"ORDER BY rrf(bm25(title, :q), similarity(emb, :v)) DESC LIMIT 10",
q="wireless controller", v={"embed": "wireless controller"}).rows
curl -s localhost:7700/v1/query -H 'content-type: application/json' -d '{
"sql": "SELECT id, title FROM products WHERE in_stock ORDER BY rrf(bm25(title, :q), similarity(emb, :v)) DESC LIMIT 10",
"params": {"q": "wireless controller", "v": {"embed": "wireless controller", "field": "emb"}}
}'
use std::path::Path;
use chloedb::{db::Db, query::Params, storage::DbOptions, value::Value};
let db = Db::open(Path::new("shop.chloedb"), DbOptions::default())?;
let q = Value::Str("wireless controller".into());
let rs = db.query(
"SELECT id, title FROM products WHERE MATCH(title, :q) ORDER BY bm25(title, :q) DESC LIMIT 10",
&Params::new().set("q", q),
)?;
for row in &rs.rows { println!("{row:?}"); }
chloedb shop.chloedb "SELECT id, title FROM products WHERE MATCH(title, 'wireless controller') LIMIT 10" chloedb shop.chloedb "SELECT id FROM products WHERE price < 40 ORDER BY rating DESC LIMIT 5" --plan