A SqliteBrain instance whose async StorageAdapter methods are used for all queries.
Insert or update a knowledge entity.
If entity.id is provided and exists, the row is updated (INSERT OR REPLACE).
If omitted, a new UUID is generated.
Extended fields (ownerId, tags, metadata, updatedAt) are packed into the
properties JSON column as underscore-prefixed keys to avoid collisions
with user-supplied properties.
Retrieve a single entity by its ID.
Returns undefined if the entity does not exist.
Query entities with optional filters.
Supports filtering by entity type, tags, owner, minimum confidence, full-text search, pagination (limit/offset), and time ranges.
Optional options: KnowledgeQueryOptionsInsert or update a knowledge relation (edge).
Extended edge fields (label, properties, confidence, source, validFrom,
validTo) are packed into the metadata JSON column.
Get all relations for a given entity.
The entity whose relations to retrieve.
Optional options: { Optional filters: direction ('outgoing'|'incoming'|'both'), types.
Optional direction?: "both" | "outgoing" | "incoming"Optional types?: RelationType[]Record an episodic memory.
Memories are stored as knowledge_nodes with type = 'memory'. The
memory-specific fields are packed into the properties JSON column.
Get an episodic memory by ID.
Looks up the knowledge_node with the given ID and type = 'memory',
then unpacks the memory-specific fields from the properties JSON.
Query episodic memories with optional filters.
Supports filtering by memory sub-type, participants, minimum importance, time range, and result limit.
Optional options: { Optional types?: ("error" | "success" | "discovery" | "conversation" | "task" | "interaction")[]Optional participants?: string[]Optional minOptional timeOptional from?: stringOptional to?: stringOptional limit?: numberRecall relevant memories via keyword search against summaries.
Performs a case-insensitive substring match on the label (which contains the summary text). Increments accessCount and updates lastAccessedAt for each returned memory (Hebbian reinforcement).
Full semantic (embedding-based) recall requires the Memory facade.
Optional topK: numberTraverse the graph from a starting entity using BFS.
Uses a recursive CTE (Common Table Expression) to walk the graph up to
maxDepth hops from the start node. Results are grouped by depth level.
ID of the entity to start traversal from.
Optional options: TraversalOptionsOptional: maxDepth, relationTypes, direction, minWeight, maxNodes.
Find the shortest path between two entities using a bidirectional BFS implemented via a recursive CTE.
Returns an ordered array of { entity, relation? } steps from source to
target, or null if no path exists within maxDepth hops.
Optional maxDepth: numberGet the neighbourhood of an entity — all entities and relations within
depth hops.
Centre entity.
Optional depth: numberMaximum number of hops (default 1).
Semantic search across entities and/or memories.
Loads all embeddings from knowledge_nodes, computes cosine similarity
against the query embedding (if present in options), and returns the
top-K results above the minimum similarity threshold.
NOTE: This implementation requires the caller to provide a query embedding via a pre-processing step. If no nodes have embeddings, an empty array is returned. For full text-to-embedding semantic search, use the Memory facade.
Extract entities and relations from text.
This operation requires an LLM and is not supported at the store level. Use the Memory facade for LLM-powered extraction.
Optional _options: { Optional extractOptional entityAlways — extraction requires an LLM.
Merge multiple entities into one primary entity.
All relations (edges) pointing to or from the non-primary entities are re-linked to the primary entity. The non-primary entities are then deleted.
All entity IDs involved in the merge.
The ID that survives the merge.
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.
Optional decayFactor: numberMultiplicative factor in (0, 1). Default 0.95.
The number of memory nodes whose confidence was reduced.
Get aggregate statistics about the knowledge graph.
Returns counts of entities, relations, memories, breakdowns by type, average confidence, and oldest/newest entry timestamps.
Persistent knowledge graph backed by SQLite via SqliteBrain.
Implements the full
IKnowledgeGraphinterface using theknowledge_nodesandknowledge_edgestables. Extended entity/relation fields that don't have dedicated columns are serialized into the JSONproperties/metadatacolumns.Example