Vector, graph and document. One embedded engine.
TriviumDB is SQLite for AI applications: a Rust engine that keeps embeddings, JSON payloads and graph edges under one node ID, on one machine, in one transaction.
pip install triviumdb One embedded engine, taken apart into its five layers.
- node ID for vector, JSON payload and graph edges
- 1
- native bindings: Python, Node.js and Rust
- 3
- graph algorithms callable inside TQL queries
- 15+
- servers to deploy. It runs in your process.
- 0
01The problem
Three databases. One fragile memory.
Agent memory usually lives in three places: a vector index for recall, a document store for state, a graph for relations. Each is correct on its own. Keeping them consistent is left to your code.
Before Three ID spaces, held together by sync code.
With TriviumDB One node, one ID, one transaction.
02The model
One ID binds three kinds of data.
Every node holds a dense vector, a JSON document and its graph edges under one u64 ID. They share one write-ahead log and one lifecycle, so there is nothing to keep in sync.
Dense embedding for similarity search: cosine for f32 and f16, Hamming for u64.
Any JSON document, filterable with Hash, ordered ART, composite and bitmap indexes.
Typed relations for traversal, spreading activation and graph algorithms.
-
Atomic by construction
A node and its vector, payload and edges commit together or not at all. Deletes remove all three.
-
Typed on disk
Since 0.9 the file header records dtype and element width, so a vector of the wrong type is rejected before it is written.
-
Text on the same ID
Optional BM25 and Aho-Corasick text indexes attach to the same node, ready for hybrid recall.
03Query
Store once. Query it any way.
Call search() for the default path, or write TQL to chain vector recall, document filters, graph patterns, graph algorithms and paths in one query.
hits = db.search(query_vec, top_k=5, expand_depth=2, min_score=0.3)
db.index_text(alice, "Alice works on embedded databases")
db.build_text_index()
hits = db.search_hybrid(query_vec, "embedded database",
top_k=5, expand_depth=2, hybrid_alpha=0.7)
for hit in hits:
print(hit.id, round(hit.score, 3), hit.payload) Vector anchors first, then spreading activation over weighted edges. Add a text query to blend in BM25.
SEARCH VECTOR [0.12, -0.45, 0.78] TOP 100 AS seed
WITH seed
EXPAND seed [:cites*1..2] AS related
WITH related
pagerank related AS scored
WITH scored
RETURN scored, graph_score(scored) AS score
ORDER BY score DESC LIMIT 10 Seed with vectors, expand the graph, then score the result with PageRank. Each WITH stage is a named node set.
MATCH (paper)-[:belongs_to]->(topic)
WHERE topic.name == "Database"
RANK paper BY VECTOR [0.12, -0.45, 0.78] TOP 10
RETURN paper Match a graph structure first, then compute exact vector ranking only inside that set.
DOCUMENTS {
operation: "search",
query: {text: "memory checkpoint", max_documents: 10, hits_per_document: 2}
}
RETURN document.document_id AS source, document.evidence AS evidence,
document.score AS score Return matching evidence together with the source document ID and score.
GRAPH {graph_ids: ["events"]}
SEARCH PELORUS {vector: [0.12, 0.0], options: {top_k: 5}}
RETURN _.id AS id, similarity(_) AS score
ORDER BY score DESC, id Search a configured Poincaré index within the events graph. A higher score means a shorter geodesic distance.
- Cascades optimizer with EXPLAIN ANALYZE
- Prepared queries with strict parameters
- 15+ graph algorithms inside queries
- Same TQL in Rust, Python, Node.js and the CLI
04QuIVer index
Exact while small. Fast as it grows.
QuIVer is the default ANN for semantic embeddings. It navigates a compact graph and reranks candidates. Use exact search for synthetic vectors and handcrafted features.
When does QuIVer switch on?
QuIVer takes over at 834 nodes.
Threshold = ceil(666,667 ÷ dimension), clamped to 209–834 nodes.
Hot and cold memory
Anonymous heap memory, used on every query.
Rerank with original vectors or centered INT8 / INT4 codes in hot memory or on SSD.
For fixed-curvature Poincaré ball embeddings, select Pelorus explicitly to rank by geodesic distance.
Pelorus · arXiv ↗Vectors and payloads are memory-mapped from sidecar files, so large databases open without loading into RAM.
-
memory.tdbHeader with dtype and CRC, node slots, edges, BQ metadata -
memory.tdb.vecMemory-mapped vectors -
memory.tdb.pld.<gen>Published JSON payloads, one file per generation -
memory.tdb.flush_okCheckpoint marker with generation, sizes and integrity digests -
memory.tdb.walWrite-ahead log -
memory.tdb.idxIndexes, registered text and index definitions
Rom loads vectors and payloads from the main file. Use the snapshot API to back up the complete file group.
-
memory.tdbVectors, payloads, edges and metadata in one file -
memory.tdb.walWrite-ahead log -
memory.tdb.idxIndexes, registered text and index definitions
05Storage and recovery
Files you can reason about.
Both layouts publish a database file group. Use create_snapshot to copy it, verify_snapshot to check it and restore_snapshot to restore it.
What a commit does
- 01 Validate
Dry-run IDs, dimensions, payload size and edge targets. A rejected transaction leaves no trace.
- 02 Log
Append TxBegin, records and TxCommit to the WAL. Every frame carries a CRC32.
- 03 Apply
Update memory and indexes. If the log write failed, the writer is isolated instead.
- 04 Checkpoint
Write temporary files, fsync, then publish with an atomic rename.
- 05 Recover
On open, replay complete transactions. An unfinished tail is dropped; a corrupted frame fails closed and keeps the log.
Durability follows the sync mode: full, normal (default) or off.
06Build
Runs inside your process.
No server, no port, no config file. Install a package, open a path, and your agent has memory. Prebuilt binaries mean there is nothing to compile.
import triviumdb
with triviumdb.TriviumDB("agent-memory.tdb", dim=3) as db:
alice = db.insert([0.12, -0.45, 0.78], {"type": "memory", "text": "Alice works on databases"})
cafe = db.insert([0.08, -0.52, 0.81], {"type": "place", "name": "Blue Bottle"})
db.link(alice, cafe, label="visited", weight=0.8)
for hit in db.search([0.10, -0.48, 0.80], top_k=5, expand_depth=2, min_score=0.1):
print(hit.id, hit.score, hit.payload) const { TriviumDB } = require('triviumdb')
const db = new TriviumDB('agent-memory.tdb', { dim: 3 })
const alice = db.insert([0.12, -0.45, 0.78], { type: 'memory', text: 'Alice works on databases' })
const cafe = db.insert([0.08, -0.52, 0.81], { type: 'place', name: 'Blue Bottle' })
db.link(alice, cafe, 'visited', 0.8)
for (const hit of db.search([0.10, -0.48, 0.80], 5, 2, 0.1)) {
console.log(hit.id, hit.score, hit.payload)
}
db.close() use serde_json::json;
use triviumdb::Database;
let mut db = Database::<f32>::open("agent-memory.tdb", 3)?;
let alice = db.insert(&[0.12, -0.45, 0.78], json!({ "type": "memory" }))?;
let cafe = db.insert(&[0.08, -0.52, 0.81], json!({ "type": "place" }))?;
db.link(alice, cafe, "visited", 0.8)?;
for hit in db.search(&[0.10, -0.48, 0.80], 5, 2, 0.1)? {
println!("{} {:.3} {:?}", hit.id, hit.score, hit.payload);
} - Linux x64 · ARM64
- macOS Intel · Apple Silicon
- Windows x64
- Python 3.9–3.12
- Node.js
- Rust stable
-
tdb CLI
Run TQL, import and export, repair and compact. Includes a REPL and a terminal UI with a graph view.
-
Embedded Console
New in 0.9Drive an open database with JSON requests from Rust, Python or Node.js. Sessions are read-only by default.
-
HTTP server
PreviewAn optional Axum server with a writer actor, group commit and optimistic concurrency.
-
Hooks
Load C, C++ or Rust plugins at six points of the search pipeline.
07Start building
Give your agent one memory.
Open source under Apache-2.0. One package for Python, Node.js and Rust.
- pip install triviumdb
- npm install triviumdb
- cargo add triviumdb