AgentKV — The SQLite of Agent Memory
A single-file, embeddable vector + graph store for AI agents. No server required.
pip install agentkv
Quickstart (5 lines)
from agentkv import AgentKV
import numpy as np
db = AgentKV("brain.db", size_mb=50, dim=768)
db.add("Paris is the capital of France", np.random.rand(768).astype(np.float32))
results = db.search(np.random.rand(768).astype(np.float32), k=3)
print(db.get_text(results[0][0])) # "Paris is the capital of France"
What's New in v0.9.0
- SIMD distance (AVX2): SIMD-accelerated distance computation on supported platforms to improve search throughput.
- Multiple metrics:
cosineandl2both supported and validated. - Batch insert:
add_batchsupports bulk inserts (example usage: insert 100 nodes in one call). - Metadata filtering: Search with
where={'color':'red'}filters results by metadata tags. - Delete / Update: Tombstone + re-insert workflow; deletes decrement the count.
- Count / Iteration:
len(db),db.keys(),db.items(),get_all_metadata(offset)supported. - Windows support: Native Windows wheels produced; CI includes Windows builds.
API Highlights
AgentKV(path, size_mb=100, dim=1536, metric="cosine")— create/open DBadd(text, vector, relations=None, metadata=None) -> offsetadd_batch(contents, vectors, metadatas=None) -> List[offsets]search(query_vector, k=5, ef_search=50, where=None)—whereis metadata filterdelete(offset),update(old_offset, content, vector, metadata=None)len(db),db.keys(),db.items(),get_vector(offset),get_text(offset),get_all_metadata(offset)- Context helpers:
observe(node_id),build_context(node_offsets, max_tokens=2048)
Example (using new features)
import numpy as np
from agentkv import AgentKV
db = AgentKV("demo.db", size_mb=10, dim=128, metric="l2")
# Batch insert 100 random vectors with metadata
texts = [f"item-{i}" for i in range(100)]
vecs = np.random.rand(100, 128).astype(np.float32)
metas = [{"color": "red" if i % 2 == 0 else "blue"} for i in range(100)]
offsets = db.add_batch(texts, vecs, metadatas=metas)
# Search only red items
q = np.random.rand(128).astype(np.float32)
results = db.search(q, k=5, where={"color": "red"})
# Delete + update
db.delete(offsets[0])
new_offset = db.update(offsets[1], "updated text", vecs[1], metadata={"color":"green"})
print(len(db), db.keys(), db.get_all_metadata(new_offset))
Why AgentKV?
| Problem | AgentKV Solution |
|---|---|
| Vector DBs need a server (Qdrant, Milvus) | Single file, no Docker, no network |
| FAISS has no persistence or text storage | mmap persistence + string arena + graph edges |
| RAG retrieves disjointed facts | Graph + vector for episodic continuity |
| Python GIL blocks concurrent search | C++ core, GIL released during search |
| Agent memory is stateless between runs | Persistent — memories survive restarts |
Comparison
| Feature | AgentKV | FAISS | Chroma | Qdrant |
|---|---|---|---|---|
pip install |
Yes | Yes | Yes | No (server) |
| Persistence | mmap | Manual | SQLite | Server |
| Text storage | Built-in | No | Yes | Yes |
| Graph edges | Yes | No | No | No |
| Crash recovery | CRC + rollback | No | Partial | Yes |
| GIL-free search | Yes | Yes | No | N/A |
| Zero-copy vectors | mmap to NumPy | Yes | No | No |
Installation
pip install agentkv # core only
pip install agentkv[ollama] # + Ollama embeddings/chat
pip install agentkv[all] # + Ollama + web search
From source:
git clone https://github.com/DarkMatterCompiler/agentkv.git
cd agentkv && pip install -e ".[dev]"
Requires: Python 3.9+, C++20 compiler, CMake 3.15+
Performance
| Metric | Result | Config |
|---|---|---|
| Insert | 292 us/node | 768-dim, HNSW |
| Search | 130 us | k=5, ef=50 |
| Recall@5 | 98.4% | 500 nodes |
| Recall@5 | 91.2% | 2000 nodes |
| Persistence | 0.00% delta | Close + reopen |
| Concurrency | 100W + 387R / 0.10s | 1 writer, 4 readers |
API
from agentkv import AgentKV
db = AgentKV(path, size_mb=100, dim=768) # Create or open
offset = db.add(text, vector) # Store + auto-index
results = db.search(query_vec, k=5) # K-NN search -> [(offset, dist)]
text = db.get_text(offset) # Retrieve text
vec = db.get_vector(offset) # Zero-copy NumPy view
context = db.observe(offset) # Predict related context
Examples
See the examples/ directory:
local_rag.py— Offline RAG with Ollama embeddingsagent_memory.py— Persistent memory across restartschatbot.py— Interactive CLI with web search
Architecture
Python Agent / LangGraph
|
agentkv.AgentKV (High-level Python API)
|
agentkv_core (nanobind C++ extension — zero-copy, GIL-free)
|
C++ Engine
+-- mmap Storage (single-file persistence, string arena for text + metadata)
+-- Metadata Store (key/value tags, efficient multi-key filters)
+-- HNSW Index (vector search) — SIMD-accelerated distance kernels (SSE/AVX2)
+-- Distance Metrics: Cosine, L2, Inner-Product (selectable)
+-- Batch Insert / WriteGuard (atomic bulk insert; serialized writers)
+-- Property Graph (directed edges) + SLB (predictive context)
+-- Tombstone + Update model (delete=tombstone + re-insert)
+-- Crash Recovery (CRC checksums, header rollback)
+-- Thread-safety (GIL released during search; reader-friendly; concurrent writers serialized)
+-- Platform helpers (`mmap_platform.h`, `simd.h`) — cross-platform (Linux/macOS/Windows)
License
MIT — see LICENSE.
Built with nanobind + scikit-build-core. HNSW algorithm: Malkov & Yashunin (2018).
Release files for agentkv 0.9.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| agentkv-0.9.1.tar.gz | 68.4 kB | Details |
Built distributions (wheels)
Total release size: 1.2 MB
Release files / agentkv-0.9.1.tar.gz
| Download URL | agentkv-0.9.1.tar.gz |
|---|---|
| Size | 68.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
df6b192a2e83508fc2f4366dc60149104830e0997df153d7286ea7e9bf3a6f01
|
|
BLAKE2b-256 checksum How to use checksums |
8a63bcb939deaeb2aabbfbe465573580461dc00e62c0d420c76706424e524205
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.8.10
|
Release files / agentkv-0.9.1-cp313-cp313-win_amd64.whl
| Download URL | agentkv-0.9.1-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 95.1 kB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
92711ba9d99dbdae9364f6aea4cb16b8b1ea3714fa0b4ad32080363c032e8e07
|
|
BLAKE2b-256 checksum How to use checksums |
9aa5de4a408379c4188e28422dc2f3d5ecd8bf142bd6e7160f583932cba63ab4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / agentkv-0.9.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | agentkv-0.9.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 134.3 kB |
| Tags | CPython 3.13 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
bf7479c90ad0f35884978a54e1eae545b710fddd63be0a57ee510a8bbeabd8e6
|
|
BLAKE2b-256 checksum How to use checksums |
e5de42578dec082db15b7b4a07360bd24c99bea5acc2f14943c54c6a93415b93
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / agentkv-0.9.1-cp312-cp312-win_amd64.whl
| Download URL | agentkv-0.9.1-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 95.1 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
ead8070420f06ec9bec8d33e18a27e3e70c22d5c7ca770f758b744dda9bf46fd
|
|
BLAKE2b-256 checksum How to use checksums |
f2cbc325a74a0cafdb0ac44cc643372c7a823c7c8fbe7ba2d0d7b8680ea43a85
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / agentkv-0.9.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | agentkv-0.9.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 134.4 kB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
b05921e2cd3e08e49d121b7bfe654cfb470e32514ea1cb649ff82e56148800b4
|
|
BLAKE2b-256 checksum How to use checksums |
9c5a3b058e45fe304ed578a4f2520bc854080044d3ba9f51ca7a974a6f08afb8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / agentkv-0.9.1-cp311-cp311-win_amd64.whl
| Download URL | agentkv-0.9.1-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 95.6 kB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
3e70af8ffc8ac317a418979edd1926dbf0516f3ecf7dac498f2ae36ce4c736be
|
|
BLAKE2b-256 checksum How to use checksums |
533c5076d9f83b2621f34e47ed24c599904367bdb80def6fe94b6ad36e8259b6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / agentkv-0.9.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | agentkv-0.9.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 135.5 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
9fbecfda80000e01133d6a51d31d023a58edf351ce86e21b8f32d7749418b4b4
|
|
BLAKE2b-256 checksum How to use checksums |
014c3b03af8a753715beabf1d7ae40ebc79b299e1dc26c08372f6f1510b86282
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / agentkv-0.9.1-cp310-cp310-win_amd64.whl
| Download URL | agentkv-0.9.1-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 95.4 kB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
5cb870b32106e3bf62fbb089cad81c4787f7354c423275cef814ce405361d0f7
|
|
BLAKE2b-256 checksum How to use checksums |
1472701d72d66b69d1fac09adc2fb5f89d6b9d41dc19fe45376043dff0480953
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / agentkv-0.9.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | agentkv-0.9.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 135.2 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
3c43d48c1571b45bb3cbfc3974a13463617156d349d3146d0ef1a71537f38e21
|
|
BLAKE2b-256 checksum How to use checksums |
4e41bab229fdb5b71d8f28bfac51d304d977d1a978d2706c949174ab9820f220
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / agentkv-0.9.1-cp39-cp39-win_amd64.whl
| Download URL | agentkv-0.9.1-cp39-cp39-win_amd64.whl |
|---|---|
| Size | 95.7 kB |
| Tags | CPython 3.9 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
c12b999e7316a34ba439f05492ebd460766670a87c3ba8d8ed80ee119decd219
|
|
BLAKE2b-256 checksum How to use checksums |
09f87bafbb147af5fac810344f858dc3f910e2e541eb6243f32c23b3242991fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / agentkv-0.9.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | agentkv-0.9.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 135.4 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
a3bf9b9823ebf420026b3ab57b03044ecd0926e081d626c30bb7ab4cdd45b7ce
|
|
BLAKE2b-256 checksum How to use checksums |
4de9b2a9908dffcd4762ffd33a9fc038ad2995721148b7ecc956f18be48569dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|