Backends
db0 uses a pluggable backend system. Both backends implement the same Db0Backend interface, so you can switch between them without changing application code.
SQLite
Local-first. No network calls. Default for development.
import { createSqliteBackend } from "@db0-ai/backends-sqlite"
// in-memory (ephemeral)
const backend = await createSqliteBackend()
// file-persisted
const backend = await createSqliteBackend({ dbPath: "./agent.db" })
Uses sql.js — pure JavaScript, no native dependencies. Works in any Node.js environment.
Features:
- Embeddings stored as Float32Array blobs
- Full-text search via FTS5
- External file modification detection (multi-process safe)
- Zero configuration
PostgreSQL
Production-ready. Cross-device sync. Requires the pgvector extension.
import { createPostgresBackend } from "@db0-ai/backends-postgres"
const backend = await createPostgresBackend({
connectionString: "postgresql://user:pass@host:5432/db",
})
Features:
- Native vector operations via pgvector
- Cross-device and multi-agent sync
- Standard PostgreSQL backup and replication
- Connection pooling compatible
Backend interface
Both backends implement Db0Backend with these methods:
Memory operations
| Method | Description |
|---|---|
memoryWrite(entry) |
Write a memory entry |
memorySearch(opts) |
Vector search with filters |
memoryList(opts) |
List memories with filters |
memoryGet(id) |
Get a specific memory |
memoryDelete(id) |
Delete a memory |
memoryAddEdge(edge) |
Add a relationship edge |
memoryGetEdges(id) |
Get edges for a memory |
memoryDeleteEdge(id) |
Delete an edge |
State operations
| Method | Description |
|---|---|
stateCheckpoint(opts) |
Save a checkpoint |
stateRestore(id) |
Restore to a checkpoint |
stateList(opts) |
List checkpoints |
stateGetCheckpoint(id) |
Get a specific checkpoint |
Log operations
| Method | Description |
|---|---|
logAppend(entry) |
Append a log entry |
logQuery(opts) |
Query log entries |
Meta KV store
| Method | Description |
|---|---|
metaGet(key) |
Get a value |
metaSet(key, value) |
Set a value |
Lifecycle
| Method | Description |
|---|---|
close() |
Close the backend connection |