Build with an AI agent
Every example on this page runs in CI against the code it documents (docs/guide/run.py).
These docs follow main, which can be ahead of the latest release, 0.3.11 (its docs): a change made after it says so where it is described.
On this page
An agent such as Claude Code can do most of what this documentation describes for you. It can load a file, make it searchable by words and by meaning, answer questions from your rows with citations, write the search page or the code of your app, find out why a query is slow, and look after a server. This page shows how to connect one, the prompts that work, and what a good agent does with each, so you can tell when it goes wrong. The server gives your agent the same prompts as slash commands, and the documentation it needs as a tool.
Connect your agent#
Start a server, if one is not running yet. With no flags it serves chloedb.chloedb in the current directory, at http://127.0.0.1:7700:
chloedb-server > server.log 2>&1 & until curl -sf http://127.0.0.1:7700/livez > /dev/null; do sleep 0.2; done
Then add it to your agent as an MCP server. For Claude Code:
claude mcp add --transport http chloedb http://127.0.0.1:7700/v1/mcp
A server with a token needs a key in the header: --header "Authorization: Bearer $CHLOEDB_KEY". A client that starts its MCP servers as commands (Claude Desktop, Cursor and most others) runs chloedb-server mcp, which passes each message on to the server:
{
"mcpServers": {
"chloedb": {
"command": "chloedb-server",
"args": ["mcp", "--url", "http://127.0.0.1:7700"],
"env": {"CHLOEDB_KEY": "your key, or leave it out for a server without a token"}
}
}
}
What the agent can change is decided by the key it connects with, not by what you ask it: a read key explores, a write key loads rows, and an admin key also makes tables (agents over MCP). Even with an admin key, an agent cannot drop a table or delete every row on its own. The server refuses, and the agent files the change for you to approve (agents and administration).
The server tells a connected agent the prompts below. In Claude Code they are slash commands, such as /mcp__chloedb__load-a-file data/movies.csv, each with the steps listed under it. You can also list them yourself:
curl -s http://127.0.0.1:7700/v1/mcp -H 'content-type: application/json' \
-d '{"jsonrpc": "2.0", "id": 1, "method": "prompts/list"}' \
| python3 -c 'import json, sys; print("\n".join(p["name"] for p in json.load(sys.stdin)["result"]["prompts"]))'
explore load-a-file search answer-with-citations search-page app-code change-a-table slow-query check-the-server
Prompts that work#
Each prompt below is written as you would type it. Under it is what a good agent does, and the server sends those steps along when you use the slash command. Words in braces, such as {path}, are yours to fill in.
Explore what is there#
Look at what is in my ChloeDB and tell me what I could search for, with an example query for each table.
whoamisays what the key may do, andlist_tablesgives each table'sCREATE TABLEstatement, its key, its vector fields and their models.- A few rows of each table (
SELECT * FROM t LIMIT 3), and the values of itsKEYWORDfields (SELECT genre, COUNT(*) FROM t GROUP BY genre). - For each table, a search by its words (
MATCHandbm25over itsTEXTfields) and, when it has an embeddedVECTORfield, one by meaning (similarity), each run once so the example is known to work. - ChloeDB's SQL is its own dialect, not Postgres. Before writing anything unusual, the agent looks up the syntax with
search_docsand checks the statement withcheck_sql.
Load a file and search it by meaning#
Load {path} into ChloeDB as a table I can search by words and by meaning.
- It looks at the file's first lines and its size, and names the table after the file unless you said otherwise.
- A file of up to a few megabytes goes through the
importtool, its text asdata, withcreate: true. The table is made from the file's columns: numbers becomeINTorFLOAT, short labelsKEYWORD, and proseTEXT. A cell that says it has no value (N/A,null,-) in a column of numbers or dates isNULL, so nothing needs cleaning first. A table with prose also getsemb, a vector of that prose bypotion-retrieval-32M, which the server downloads once (about 130 MB) and fills in. The answer'screate_tableis the statement it made. - A larger file is sent from the shell instead, which needs an admin key on a server with a token:
curl -s --data-binary @{path} -H 'content-type: text/csv' 'http://127.0.0.1:7700/v1/import?table=NAME'. The content type istext/tab-separated-valuesfor TSV andapplication/x-ndjsonfor JSON Lines. With the server stopped,chloedb-server import {path} --db chloedb.chloedbdoes the same (loading rows). - Search by meaning works once the model has arrived. Until then such a query answers 503
unavailable, saying how far the download is, or, when it failed, when the server tries again by itself. The agent waits, andlist_modelsshows the download, rather than fetching the model itself. Search by words works at once. - It ends with one search by words and one by meaning, so you see the table work.
Search, and say why each row matched#
Search the {table} table for "{question}", by meaning and by words together, and tell me why each result matched.
- Words and meaning fused:
SELECT ... FROM {table} ORDER BY rrf(bm25(body, :q, fuzzy => 'auto'), similarity(emb, :q)) DESC LIMIT 10, with:qthe text itself, which the server embeds with the field's own model.bodystands for the table'sTEXTfields, andembfor its vector field (list_tablesnames both). fuzzy => 'auto'takes typos: a word in no row is read as the words near it.- A condition on structured fields goes in
WHERE(genre = 'scifi' AND year > 2000), not in the text. - To say why a row matched, the agent runs
explainwithhits, which gives each top row's scores, or compares the row's words with the question's (ranking). MATCH(field, 'a b c')keeps only rows with every word. When it finds nothing, the answer'shintsuggestsORormin => 2.
Answer a question from my rows, with citations#
Answer this from the rows in my ChloeDB, citing the rows each claim comes from: {question}
- It finds the rows as in the search above, eight or so, with their keys.
- It answers from those rows only, marking each claim with its row as
[1],[2], and lists the rows cited with their keys. When the rows do not answer the question, it says so rather than answering from what it knows. - In your own code, Python's
db.ask(question, table=...)does the same in one call. It returns the answer with itssources, written by a language model through the query'sllm(), withANTHROPIC_API_KEY(Python). A whole pipeline, with documents split into chunks and grounded claims, is in Retrieval for RAG.
Build a search page#
Build me a search page for the {table} table: a search box that forgives typos and finds things by meaning, with filters, that I open in my browser.
- The page cannot call chloedb-server from the browser. The server refuses requests from a page on another origin, a page opened from a file included, and sends no CORS headers. A page written to
fetchthe server's/v1/querytherefore fails with a CORS error. The page calls a small app instead, and the app calls the server (why). - The app can be Python's standard library and
chloedb(pip install chloedb):chloedb.connect("http://127.0.0.1:7700")and anhttp.serverhandler that serves the page and answers/search?q=withdb.search(q, table="{table}", where=..., limit=20).db.searchfuses words and meaning and forgives typos. Build a search page is that app in full, with highlights, "did you mean", filters with counts, and "more like this". - In a JavaScript app, the route does the same with the
chloedbpackage's client (a search box in a web app). - Filters come from the table's
KEYWORDfields, with their counts (SELECT genre, COUNT(*) FROM {table} WHERE MATCH(...) GROUP BY genre). - It starts the app, opens the page (or fetches it with
curl), runs a search with a typo in it, and gives you the address.
Write the code of my app#
Write {language} code that uses ChloeDB to {task}.
- It chooses between the database in the app's own process (
chloedb.open(path)in Python,open()in JavaScript,Dbin Rust) and a client of a running server (chloedb.connect(url)). It uses the server when more than one process uses the data, or when the command center should show it. - It looks up the client's methods in that language's page, and does not guess them from other databases: Python, JavaScript, Rust, Java.
- Queries take named parameters (
:q) bound in a mapping, never values pasted into the SQL. - It runs the code once against a real database and shows what it printed.
Change a table#
In ChloeDB, change the {table} table: {change}.
- It reads the table's statement (
describe_table) and finds the syntax withsearch_docs(ALTER TABLE ... ADD, a field's options, an embedded field). - It checks the statement with
check_sqlbefore running it withexecute. An added field fills in for the rows already there, and an embedded vector field computes its vectors in the background. - It does not drop a table or a field, or delete or update every row, on its own: the server refuses an agent that tries (
change_request_required). It asks you, or files the change for an admin to approve withpropose_change.
Find out why a query is slow#
This ChloeDB query is slow. Find out why and make it faster: {sql}
explainshows how the query runs: the plan of each segment, the rows a filter kept, and whether ranking stopped early (MaxScore).queriesshows the latest and slowest statements, with their times.- The usual cause is a condition the indexes cannot answer, which tests every row the other conditions keep: a function or arithmetic of a column (
lower(brand) = 'acme'), aLIKE '%tent%'or anILIKEon a field without a substring index, or a comparison of aTEXTfield's stored text (statement shape). Others are a ranking by an expression that every row must compute, and aLIMITmuch larger than the page shows. - It changes one thing at a time, and times the query before and after with the same parameters.
Check the server#
Check my ChloeDB server's health and tell me what needs attention, and what to do about each thing.
health,alertsandevents(with an admin,opsorproposekey) say how the server is and what has changed.- For each problem,
runbookfinds what to do. - It acts only within what its key allows alone: a contain rule, a cancelled query, an alert silenced for a while, each with a reason. Anything bigger it files with
propose_changefor a person to approve (agents and administration).
What every agent should know#
The server tells a connected agent these at the start. They are written here for an agent that reads this page instead.
- The SQL is ChloeDB's own.
MATCH(field, 'words')filters by text,ORDER BY bm25(field, 'words') DESCranks by it,similarity(emb, :q)ranks by meaning, andrrf(...)fuses rankings.search_docsfinds the syntax of anything else in the SQL reference, andcheck_sqlchecks a statement without running it. - Errors say what to do. Every error has a stable
error_code, whether trying again can work (retryable), ahint, and the documentation section that explains it (docs). A retryable error is waited out, not worked around (error codes). - Meaning comes by itself. A table made from a file with prose gets a vector of it, which the server fills in once its model has downloaded. Nothing needs to be fetched or configured by hand.
- Pages call an app, not the server. See Build a search page above.
- Writes are safe to send again with a key. A write through a coordinator that answers
write_in_doubtis sent again with the answer'sidempotency_key(failover). - Ask before anything that loses data. The server holds such a change for a person anyway.
Tell your coding agent about ChloeDB#
A coding agent working on your app, with no MCP server, reads the documentation as text:
- llms.txt lists every page with a line on what it covers.
- llms-full.txt is the whole documentation in one file.
For a project that uses ChloeDB, a few lines in its CLAUDE.md or AGENTS.md keep the agent on the right path:
This project uses ChloeDB (https://chloetech-ai.github.io/chloedb/llms.txt), a search database with its own SQL dialect, not Postgres: MATCH and bm25 for words, similarity for meaning, rrf to fuse them. Look up syntax in its SQL reference rather than guessing. The server runs at http://127.0.0.1:7700 (MCP: /v1/mcp). Browser pages call our app's routes, never the server.