Try it in 5 minutes
In five minutes you will index three small pages, run two searches, repeat one in Python, and see how an agent plugs in. You need Python 3.12 or later and a terminal. Nothing else is installed, and no account is needed.
Step 1: install the package
$ pip install duckdb-vectors$ uv add duckdb-vectorsThe install brings the duckdb-vectors command and the Python package. The first index downloads a small embedding model once. After that, everything runs offline.
Step 2: write three pages
Paste this block in a terminal. It creates a ./kb/ folder with three Markdown pages: a policy, a how-to and a FAQ. The policy page declares kind: policy in its front matter. Your own pages can carry any attributes.
$ mkdir -p kb
$ cat > kb/retention-policy.md <<'MD'
---
kind: policy
---
# Retention policy
We keep invoices and contracts for seven years. After that, the finance team deletes them.
Support tickets are kept for two years.
MD
$ cat > kb/rotate-keys.md <<'MD'
---
kind: how-to
---
# Rotate an access key
Create a new key, update the service that uses it, then disable the old key.
Delete the old key after one week.
MD
$ cat > kb/faq.md <<'MD'
---
kind: faq
---
# Frequently asked questions
## What is the RTO?
The RTO, or recovery time objective, is four hours. It is the longest outage we accept.
MDStep 3: index the pages
$ duckdb-vectors index ./kb
$ duckdb-vectors statusThe first command splits each page into chunks, embeds them and writes everything into one file, vectors.duckdb. The second one tells you what landed in it.
You should see:
{
"files": 3,
"chunks": 3,
"embedded": 3,
"reused": 0,
"written": 3,
"pruned": 0
}
{
"manifest": null,
"database": {
"path": "vectors.duckdb",
"embeddings": "local:minishlab/potion-multilingual-128M",
"dimensions": 256,
"chunks": 3,
"tag_fields": []
},
"next": "duckdb-vectors search QUERY"
}The output of status has a few more lines, which you can ignore for now. Add --sources to list the indexed pages. No manifest exists yet. To write the settings once, run duckdb-vectors init kb and see the manifest reference.
Step 4: search by meaning, then by exact token
The first question shares no word with the policy page. It says "old invoices" and "how long", while the page says "keep" and "seven years".
$ duckdb-vectors search "how long do we keep old invoices?" --top-k 2You should see the policy page first. Each result carries its text, its source and its metadata, trimmed here:
[
{
"chunk": {
"chunk_id": "retention-policy.md:0",
"text": "We keep invoices and contracts for seven years. ...",
"source": "retention-policy.md",
"title": "Retention policy",
"metadata": { "kind": "policy", ... }
},
"score": 0.0328,
...
},
...
]The second question is an acronym. Meaning alone can miss a short code, so the search also matches exact words.
$ duckdb-vectors search "RTO" --top-k 1You should see the FAQ chunk that answers "What is the RTO?", with the text "The RTO, or recovery time objective, is four hours."
Step 5: search from Python
The same search takes five lines. The filter keeps only the chunks whose front matter says kind: policy.
from duckdb_vectors import VectorStore
store = VectorStore()
for hit in store.query("how long do we keep old invoices?", top_k=3, filter={"kind": "policy"}):
print(round(hit.score, 3), hit.chunk.source, hit.chunk.title)You should see:
0.033 retention-policy.md Retention policyOnly one line comes out, because only one page is a policy.
Step 6: let an agent call it
Any client of the Model Context Protocol can start duckdb-vectors mcp and call its search and report tools. The entry looks the same in most clients, with a small difference in the name of the file that holds it:
{
"mcpServers": {
"knowledge-base": {
"command": "duckdb-vectors",
"args": ["mcp", "--database", "/absolute/path/to/vectors.duckdb"]
}
}
}Use an absolute path, because the client starts the server from its own folder.
A larger corpus
To try a real set of pages, index the documentation of this project:
$ git clone --depth 1 https://github.com/bernard357/duckdb-vectors.git
$ duckdb-vectors index ./duckdb-vectors/documentation --database docs.duckdb
$ duckdb-vectors search "how do I plug a knowledge base into my editor?" --database docs.duckdb --top-k 3Next steps
- Put the index in a container image with Your first agent.
- Wire it to your harness in the Connect group of the sidebar, for example the Docker Agent guide.
- Learn the vocabulary of chunks, embeddings and hybrid search in Core concepts.