Environment:23blocks OS Ai maestro CozoDB
| Knowledge Sources | |
|---|---|
| Domains | Database, Memory, Search |
| Last Updated | 2026-10-26 18:00 GMT |
Overview
Embedded CozoDB (cozo-node) with SQLite storage backend, providing per-agent databases for conversations, vector embeddings, knowledge graphs, and full-text search.
Description
Each agent gets its own embedded CozoDB database at `~/.aimaestro/agents/{agentId}/agent.db`, using the SQLite storage backend (`new CozoDb('sqlite', dbPath)`). The database holds ~45 tables across four schema groups: base tracking, RAG (embeddings/terms/code-graph), long-term memory (cards/relations), and Phase 5 (transcripts/playback/export). Schemas are auto-migrated on first open via `ensureRagSchema`, `ensureMemorySchema`, and `ensurePhase5Schema`.
A schema-initialisation cache (`initialisedSchemas`) keyed by file identity (inode + birth time) skips the ~45-table check on repeated opens of the same database file in the same process. Failed migrations are retried on the next open (not cached). Read-only connections skip schema migration entirely to avoid taking the write lock from the agent's own connection.
= Usage
Use this environment for all memory and search operations: delta conversation indexing, memory consolidation (classify-reinforce-link), hybrid RAG search (lexical + semantic), entity graph queries, and transcript playback. Required by the subconscious (indexing, memory consolidation, inbox polling) that runs on the host where the agent lives.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | Linux / macOS | cozo-node native module |
| Disk | Per-agent `agent.db` file | Grows with conversation history; place on SSD |
| Memory | One connection per agent | Read-only connections for per-prompt recall are short-lived |
Dependencies
Node Packages
- `cozo-node` >= 0.7.6
System Packages
- None (SQLite is embedded in cozo-node)
Credentials
No credentials required. CozoDB is embedded; each database file is local to the agent's directory.
Quick Install
yarn install # cozo-node is a dependency in package.json
Code Evidence
Database creation with SQLite backend from `lib/cozo-db.ts:79`:
this.db = new CozoDb('sqlite', this.dbPath)
Schema-init cache by file identity from `lib/cozo-db.ts:25-31`:
function fileIdentity(p: string): string | null {
try {
const st = fs.statSync(p)
return `${st.ino}:${st.birthtimeMs}`
} catch { return null }
}
Read-only mode (no schema migration) from `lib/cozo-db.ts:85`:
if (this.readOnly) return
Failed migration retry logic from `lib/cozo-db.ts:109-111`:
if (!this.schemaFailed) {
const after = fileIdentity(this.dbPath)
if (after) initialisedSchemas.set(this.dbPath, after)
}
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `Database not initialized. Call initialize() first.` | `run()` called before `initialize()` | Always use `createAgentDatabase()` factory which calls `initialize()` |
| `Failed to ensure RAG schema` | Schema migration error | Non-fatal; database works without RAG features. Check logs. |
| Query fails with `relation does not exist` | Schema not yet migrated | Ensure the agent database was initialized; read-only connections skip migration |
| Concurrent write lock contention | Multiple write connections to same DB | Use a single write connection; short reads use `readOnly: true` |
Compatibility Notes
- Storage backend: Always SQLite (`'sqlite'`). No MemFS or HTTP backends in production.
- Read-only connections: Short-lived per-prompt memory recall connections set `readOnly: true` to avoid taking the write lock. They skip metadata writes and schema migrations.
- Schema migration: RAG, Memory, and Phase 5 schemas are auto-migrated on first open. A failed migration is retried on the next open (not cached), so a transient error self-heals.
- File identity: The schema cache keys on inode + birth time, so a deleted-and-recreated database file (new inode) is re-initialised correctly.