Class SqlKnowledgeGraph

Persistent knowledge graph backed by SQLite via Brain.

Implements the full IKnowledgeGraph interface using the knowledge_nodes and knowledge_edges tables. Extended entity/relation fields that don't have dedicated columns are serialized into the JSON properties / metadata columns.

Example

const brain = await Brain.openSqlite('/tmp/agent-brain.sqlite');
const graph = new SqlKnowledgeGraph(brain);
await graph.initialize();

const entity = await graph.upsertEntity({
type: 'person',
label: 'Alice',
properties: { role: 'engineer' },
confidence: 0.95,
source: { type: 'user_input', timestamp: new Date().toISOString() },
});

Implements

Constructors

Methods

  • Delete the memory nodes that copy the filter's traces or scopes, with the relations that name them, as deleteEntity deletes an entity's. A trace's copy is deleted by its key; the first delete by trace id of this instance first gives the copies an older release recorded their key (rekeyOlderCopies), and a copy whose move failed in that pass is deleted by its node id. While that pass fails as a whole, a delete by trace id reads the trace's copies held under another node id by the text their stored JSON holds (olderCopyIds) and deletes them too. A scope's copies are read by the text their stored JSON holds (LIKE with an escape clause, which on SQLite also matches the text in other letter cases) and matched exactly in code, so a malformed properties value is skipped rather than failing the delete.

    Parameters

    Returns Promise<number>

  • Query episodic memories with optional filters.

    Supports filtering by memory sub-type, participants, minimum importance, time range, and result limit.

    Parameters

    • Optional options: {
          types?: ("error" | "success" | "discovery" | "conversation" | "task" | "interaction")[];
          participants?: string[];
          minImportance?: number;
          timeRange?: {
              from?: string;
              to?: string;
          };
          limit?: number;
      }
      • Optional types?: ("error" | "success" | "discovery" | "conversation" | "task" | "interaction")[]
      • Optional participants?: string[]
      • Optional minImportance?: number
      • Optional timeRange?: {
            from?: string;
            to?: string;
        }
        • Optional from?: string
        • Optional to?: string
      • Optional limit?: number

    Returns Promise<EpisodicMemory[]>

  • Decay the confidence of all memory-type nodes by a multiplicative factor.

    This simulates the Ebbinghaus forgetting curve — memories that are not accessed (reinforced) gradually fade.

    Parameters

    • Optional decayFactor: number

      Multiplicative factor in (0, 1). Default 0.95.

    Returns Promise<number>

    The number of memory nodes whose confidence was reduced.