Skip to main content

The SQLite of agent memory — embeddable vector + graph store for AI agents

Project description

AgentKV — The SQLite of Agent Memory

A single-file, embeddable vector + graph store for AI agents. No server required.

PyPI Python 3.9+ License: MIT

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: cosine and l2 both supported and validated.
  • Batch insert: add_batch supports 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 DB
  • add(text, vector, relations=None, metadata=None) -> offset
  • add_batch(contents, vectors, metadatas=None) -> List[offsets]
  • search(query_vector, k=5, ef_search=50, where=None)where is metadata filter
  • delete(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 embeddings
  • agent_memory.py — Persistent memory across restarts
  • chatbot.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).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agentkv-0.9.1.tar.gz (68.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

agentkv-0.9.1-cp313-cp313-win_amd64.whl (95.1 kB view details)

Uploaded CPython 3.13Windows x86-64

agentkv-0.9.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (134.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

agentkv-0.9.1-cp312-cp312-win_amd64.whl (95.1 kB view details)

Uploaded CPython 3.12Windows x86-64

agentkv-0.9.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (134.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

agentkv-0.9.1-cp311-cp311-win_amd64.whl (95.6 kB view details)

Uploaded CPython 3.11Windows x86-64

agentkv-0.9.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (135.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

agentkv-0.9.1-cp310-cp310-win_amd64.whl (95.4 kB view details)

Uploaded CPython 3.10Windows x86-64

agentkv-0.9.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (135.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

agentkv-0.9.1-cp39-cp39-win_amd64.whl (95.7 kB view details)

Uploaded CPython 3.9Windows x86-64

agentkv-0.9.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (135.4 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

Details for the file agentkv-0.9.1.tar.gz.

File metadata

  • Download URL: agentkv-0.9.1.tar.gz
  • Upload date:
  • Size: 68.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for agentkv-0.9.1.tar.gz
Algorithm Hash digest
SHA256 df6b192a2e83508fc2f4366dc60149104830e0997df153d7286ea7e9bf3a6f01
MD5 e79ca882868759485bf8ea0946f23c94
BLAKE2b-256 8a63bcb939deaeb2aabbfbe465573580461dc00e62c0d420c76706424e524205

See more details on using hashes here.

File details

Details for the file agentkv-0.9.1-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: agentkv-0.9.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 95.1 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for agentkv-0.9.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 92711ba9d99dbdae9364f6aea4cb16b8b1ea3714fa0b4ad32080363c032e8e07
MD5 8d7e2f59ff53551dc62c255f64a422e0
BLAKE2b-256 9aa5de4a408379c4188e28422dc2f3d5ecd8bf142bd6e7160f583932cba63ab4

See more details on using hashes here.

File details

Details for the file agentkv-0.9.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for agentkv-0.9.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bf7479c90ad0f35884978a54e1eae545b710fddd63be0a57ee510a8bbeabd8e6
MD5 8099232d585b6ec29796376d531aad8b
BLAKE2b-256 e5de42578dec082db15b7b4a07360bd24c99bea5acc2f14943c54c6a93415b93

See more details on using hashes here.

File details

Details for the file agentkv-0.9.1-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: agentkv-0.9.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 95.1 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for agentkv-0.9.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ead8070420f06ec9bec8d33e18a27e3e70c22d5c7ca770f758b744dda9bf46fd
MD5 4371ad38800d0f3ed3a46d7f14405341
BLAKE2b-256 f2cbc325a74a0cafdb0ac44cc643372c7a823c7c8fbe7ba2d0d7b8680ea43a85

See more details on using hashes here.

File details

Details for the file agentkv-0.9.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for agentkv-0.9.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b05921e2cd3e08e49d121b7bfe654cfb470e32514ea1cb649ff82e56148800b4
MD5 8d00fd7e4b7cba09abccb369586bc225
BLAKE2b-256 9c5a3b058e45fe304ed578a4f2520bc854080044d3ba9f51ca7a974a6f08afb8

See more details on using hashes here.

File details

Details for the file agentkv-0.9.1-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: agentkv-0.9.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 95.6 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for agentkv-0.9.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3e70af8ffc8ac317a418979edd1926dbf0516f3ecf7dac498f2ae36ce4c736be
MD5 97f89703f1b8bc09b45035c1d706e21c
BLAKE2b-256 533c5076d9f83b2621f34e47ed24c599904367bdb80def6fe94b6ad36e8259b6

See more details on using hashes here.

File details

Details for the file agentkv-0.9.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for agentkv-0.9.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9fbecfda80000e01133d6a51d31d023a58edf351ce86e21b8f32d7749418b4b4
MD5 c9044369c31755ff47d495c17b0be99f
BLAKE2b-256 014c3b03af8a753715beabf1d7ae40ebc79b299e1dc26c08372f6f1510b86282

See more details on using hashes here.

File details

Details for the file agentkv-0.9.1-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: agentkv-0.9.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 95.4 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for agentkv-0.9.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 5cb870b32106e3bf62fbb089cad81c4787f7354c423275cef814ce405361d0f7
MD5 1a8eafff8f527db45b11554c9bdb8c3e
BLAKE2b-256 1472701d72d66b69d1fac09adc2fb5f89d6b9d41dc19fe45376043dff0480953

See more details on using hashes here.

File details

Details for the file agentkv-0.9.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for agentkv-0.9.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3c43d48c1571b45bb3cbfc3974a13463617156d349d3146d0ef1a71537f38e21
MD5 9e0e7984232443dd44b2baf61db715c8
BLAKE2b-256 4e41bab229fdb5b71d8f28bfac51d304d977d1a978d2706c949174ab9820f220

See more details on using hashes here.

File details

Details for the file agentkv-0.9.1-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: agentkv-0.9.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 95.7 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for agentkv-0.9.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 c12b999e7316a34ba439f05492ebd460766670a87c3ba8d8ed80ee119decd219
MD5 390bb282f1bf6f82a2c6b9b56fd468bd
BLAKE2b-256 09f87bafbb147af5fac810344f858dc3f910e2e541eb6243f32c23b3242991fb

See more details on using hashes here.

File details

Details for the file agentkv-0.9.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for agentkv-0.9.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a3bf9b9823ebf420026b3ab57b03044ecd0926e081d626c30bb7ab4cdd45b7ce
MD5 2f91e9233cf79d6c27bca456e07f40d5
BLAKE2b-256 4de9b2a9908dffcd4762ffd33a9fc038ad2995721148b7ecc956f18be48569dd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page