Skip to content

Knowledge Graph

Every memory is a node in the knowledge graph:

FieldDescription
idUnique identifier for this memory version
entity_idGroups all versions of the same entity
contentThe knowledge, as natural language text
layerSemantic layer (0=Domain, 1=Concept, 2=Fact, 3=Episode)
parent_idLink to the parent memory in the hierarchy
valid_from / valid_toWhen this information was true

The entity_id groups memory versions. When retain decides that new content updates an existing memory, the new version gets the same entity_id. The old version gets a valid_to timestamp; the new one becomes current.

Query all versions of an entity:

GET /api/v1/entities/alice-location/history

Memories are connected by typed, weighted edges:

FieldDescription
source_idOrigin memory
target_idTarget memory
typeRelationship kind (e.g., “is_about”, “related_to”, “part_of”)
strengthConnection strength, 0.0 to 1.0

Relationship types are not prescribed — the LLM infers appropriate types during retain. Common types include related_to, is_about, part_of, contradicts, and supports.

The parent_id field creates a tree mirroring the semantic layers:

Domain (layer 0)
└── Concept (layer 1)
└── Fact (layer 2)
└── Episode (layer 3)

Orphaned memories (no parent_id) are candidates for organization by reflect.

MemLayer maintains a pre-computed transitive closure of the parent-child hierarchy. This makes hierarchical queries like “find all memories under the Programming domain” a single lookup instead of recursive traversal.

Semantic search finds entry points. Graph traversal discovers related memories that wouldn’t match the query directly:

  • Parent: A broader concept providing context
  • Siblings: Related facts under the same parent
  • Relationships: Explicitly linked memories
  • Children: More specific details

A query for “technical skills” might match “experienced with Haskell”. Graph traversal then discovers the parent concept “Functional Programming”, siblings like “has used Erlang”, and children like “gave a talk on monads”.

Each agent has a completely isolated namespace — its own knowledge graph, relationships, and hierarchy. One agent’s operations have no effect on another’s data.