sqlite-vec adds vector search to SQLite, so an agent's memory can live in one file with no server. We stored 16 notes with local embeddings and asked 10 questions: the right note came first all 10 times. Four questions with no stored answer still got a "nearest" note, and no distance cutoff told them apart from real hits.
The human step: a person decides which facts the agent may store, reads what it recalls before acting on it, and deletes notes that should not be kept. In this test our script did the storing and the one deletion.
Based on sqlite-vec, by Alex Garcia and contributors, under the MIT licence or the Apache-2.0 licence, your choice, using its KNN queries. Checked 2026-10-31 with sqlite-vec v0.1.9.
Why put memory in SQLite
An agent's memory is often a few hundred notes, too few to justify a vector database server. sqlite-vec is a SQLite extension: pip install sqlite-vec, load it into Python's sqlite3, and query vectors with SQL. The package was 176 KB installed. The project says it is pre-v1 and to expect breaking changes, so pin the version.
Embeddings came from nomic-embed-text in our local Ollama (768 numbers per text). The model card says to start stored texts with search_document: and questions with search_query: , so we ran everything twice: without and with those prefixes. The Ollama library page lists the model under Apache-2.0.
The memory module
Four functions: open, remember, recall, forget. Distance is cosine: 0 is identical, larger is less alike. The Python guide shows the same load and serialize_float32 steps.
# Agent memory in one SQLite file: notes embedded by a local Ollama model, searched with sqlite-vec.
import json, sqlite3, sys, urllib.request
import sqlite_vec
from sqlite_vec import serialize_float32
def embed(texts):
body = json.dumps({"model": "nomic-embed-text", "input": texts}).encode()
req = urllib.request.Request("http://127.0.0.1:11434/api/embed", body, {"Content-Type": "application/json"})
return json.load(urllib.request.urlopen(req))["embeddings"]
def open_memory(path):
db = sqlite3.connect(path)
db.enable_load_extension(True)
sqlite_vec.load(db)
db.enable_load_extension(False)
db.execute("create table if not exists notes(id integer primary key, text text)")
db.execute("create virtual table if not exists vec_notes using vec0(embedding float[768] distance_metric=cosine)")
return db
def remember(db, notes, prefix):
for (note_id, text), vector in zip(notes, embed([prefix + t for _, t in notes])):
db.execute("insert into notes(id, text) values (?, ?)", (note_id, text))
db.execute("insert into vec_notes(rowid, embedding) values (?, ?)", (note_id, serialize_float32(vector)))
db.commit()
def recall(db, question, prefix, k=3):
rows = db.execute("select rowid, distance from vec_notes where embedding match ? and k = ? order by distance",
(serialize_float32(embed([prefix + question])[0]), k)).fetchall()
return [(note_id, round(distance, 3)) for note_id, distance in rows]
def forget(db, note_id):
db.execute("delete from vec_notes where rowid = ?", (note_id,))
db.execute("delete from notes where id = ?", (note_id,))
db.commit()The test
16 notes about a made-up user, 10 questions worded differently from their notes, 4 questions with no stored answer, then one deletion.
# Score recall@1 and recall@3 on 10 labelled questions and 4 with no stored answer, without and with nomic's task prefixes, then forget one note.
import os, sys
from memory import open_memory, remember, recall, forget
NOTES = [
(1, "The user's laptop is a ThinkPad X1 running Fedora 41."),
(2, "The user's phone is a Pixel 8."),
(3, "The user prefers tea to coffee in the morning."),
(4, "The user's sister Ana lives in Valencia."),
(5, "The user's brother Tomas lives in Lisbon."),
(6, "Weekly team meeting is on Tuesdays at 10:00."),
(7, "The dentist appointment was moved to 14 November at 09:30."),
(8, "The user is allergic to penicillin."),
(9, "The user's car is a 2019 Toyota Corolla, plate ending 482."),
(10, "The project repository uses Python 3.12 and pytest."),
(11, "The user wants replies in British English."),
(12, "Rent is paid on the 1st of each month by bank transfer."),
(13, "The user runs on Saturday mornings, about 8 km."),
(14, "The office wifi network is called North-5G."),
(15, "The user's passport expires in March 2028."),
(16, "The user's partner is vegetarian."),
]
QUESTIONS = [
("What computer do I use?", 1),
("Where does my sister live?", 4),
("When is my dentist visit?", 7),
("Which antibiotic should I avoid?", 8),
("What should I drink when I wake up?", 3),
("When do we have the team sync?", 6),
("Which spelling style do I want?", 11),
("What test framework does the repo use?", 10),
("Can we book a steakhouse for dinner with my partner?", 16),
("Is my travel document still valid next year?", 15),
]
UNKNOWN = ["What is my blood type?", "What is my dog called?", "When does my gym membership renew?", "Which bank holds my savings?"]
for label, doc_prefix, query_prefix in (("no prefix", "", ""), ("nomic prefixes", "search_document: ", "search_query: ")):
path = f"memory-{label.replace(' ', '-')}.db"
if os.path.exists(path):
os.remove(path)
db = open_memory(path)
remember(db, NOTES, doc_prefix)
top1 = top3 = 0
for question, want in QUESTIONS:
hits = recall(db, question, query_prefix)
ids = [note_id for note_id, _ in hits]
top1 += ids[0] == want
top3 += want in ids
print(f"{label:14} {'HIT ' if ids[0] == want else ('TOP3' if want in ids else 'MISS')} want={want:2} got={hits} {question}")
print(f"{label}: recall@1 {top1}/10, recall@3 {top3}/10")
for question in UNKNOWN:
print(f"{label:14} NO ANSWER STORED, nearest={recall(db, question, query_prefix, k=1)} {question}")
forget(db, 8)
print("after forget(8):", recall(db, "Which antibiotic should I avoid?", "search_query: "),
"rows left:", db.execute("select count(*) from notes").fetchone()[0], db.execute("select count(*) from vec_notes").fetchone()[0])#!/bin/sh
# Ollama 0.40.13 on 127.0.0.1:11434 is already running with nomic-embed-text; build and score two memory files.
./venv/bin/python -c "import sqlite3, sqlite_vec; db = sqlite3.connect(':memory:'); db.enable_load_extension(True); sqlite_vec.load(db); print('sqlite', sqlite3.sqlite_version, 'sqlite-vec', db.execute('select vec_version()').fetchone()[0])"
./venv/bin/python eval.py
ls -l *.db | awk '{print $5, $NF}'What happened
| Set-up | Right note first | Right note in top 3 | Distance of right notes | Nearest note for unknown questions |
|---|---|---|---|---|
| No prefix | 10 of 10 | 10 of 10 | 0.245 to 0.455 | 0.437 to 0.554 |
| nomic prefixes | 10 of 10 | 10 of 10 | 0.197 to 0.415 | 0.385 to 0.482 |
Ranking was perfect at this size. Every question found its note first, with and without the prefixes. The prefixes made right answers closer but changed no ranking.
Unknown questions still got an answer. "When does my gym membership renew?" found the passport note at 0.437 without prefixes and 0.385 with them. That is closer than the right answer to "Which antibiotic should I avoid?" (0.455 and 0.401). So no distance cutoff keeps all 10 hits and drops all 4 unknowns. An agent trusting the top hit would answer with the passport date.
Forgetting worked. After forget(8), both tables had 15 rows and the antibiotic question returned other notes, the nearest at 0.486. Delete from both tables, or the vector stays behind.
The file is not tiny. Each database was 3,190,784 bytes for 16 notes. We did not test how it grows.
What this test does not show
- Scale. 16 notes, 14 questions. With thousands of notes, near misses get more common.
- Other embedding models. One model, one language.
- Speed. vec0 does an exact search. We did not time large tables.
What to set up
- Pin sqlite-vec to the version you tested, since it is pre-v1.
- Store the note text and the vector under the same id, and delete both together.
- Do not trust the top hit alone. Give the agent the note text and the distance, and tell it to say "I don't know" when the note does not answer the question.
- Keep personal memory files on the user's machine and out of shared folders.
Takeaway
sqlite-vec gave a local agent working vector memory in one SQLite file with a 176 KB install, and it ranked the right note first for all 10 test questions. What it cannot do is tell you when memory has no answer: every question gets a nearest note, and in our test no distance cutoff separated real hits from unknowns.
Next step: put 20 of your agent's real notes into a vec0 table, write 10 questions you know the answers to and 5 you know it cannot answer, and look at the distances before you let the agent act on what it recalls.
How we check the tools we list is on our verification page.
Good setups, worth keeping. Request email updates on the home page, then confirm by email. No subscription starts until you confirm. Or find an agent for the job.
