Harness

The harness is the entry point to db0. It scopes all memory, state, and log operations to a specific agent, session, and user.

Creating a harness

import { db0 } from "@db0-ai/core"

const harness = db0.harness({
  agentId: "my-agent",
  sessionId: "session-1",
  userId: "user-123",
  backend,
  profile: PROFILE_AGENT_CONTEXT,   // optional
  embeddingFn,                       // optional
  batchEmbeddingFn,                  // optional
  extraction,                        // optional
  summarizeFn,                       // optional
})

Configuration

Field Type Required Description
agentId string yes Identifies this agent
sessionId string yes Identifies the current session
userId string no Identifies the user — enables user-scoped memory
backend Db0Backend yes Storage backend (SQLite or PostgreSQL)
profile Db0Profile no Tuning profile for scoring, extraction, retrieval
embeddingFn (text) => Promise<number[]> no Custom embedding function
batchEmbeddingFn (texts) => Promise<number[][]> no Batch embedding for bulk operations
extraction object no Extraction strategy config
summarizeFn (text) => Promise<string> no Custom summarization function

Methods

Method Returns Description
memory() Memory Access the memory component
state() State Access the state component
context() Context Access the context component
log() Log Access the log component
spawn(config) Harness Create a child harness
close() Promise<void> Close the backend (root only)

Embedding migration

When you switch embedding providers, existing vectors become incompatible. db0 tracks the active embedding provider and can re-embed all memories:

// check current status
const status = harness.embeddingStatus("gemini-001")

// re-embed all active memories with a new provider
await harness.migrateEmbeddings(
  newEmbeddingFn,
  newBatchEmbeddingFn,
  "gemini-001"
)