Semantic Memory
A knowledge graph of entities and typed relationships. Store facts, skills, preferences, and the connections between concepts.
What Is Semantic Memory?
Semantic memory models structured knowledge as a graph. Entities represent things (people, projects, technologies, concepts) with typed attributes, and relationships connect entities with labeled edges carrying their own metadata.
Unlike episodic memory, which captures events over time, semantic memory represents enduring facts and relationships: "User knows Python", "ProjectA depends on LibraryB", "Sarah works at Acme Corp".
When to Use
- •Storing structured knowledge about users, projects, and technologies
- •Tracking skills, competencies, and expertise areas
- •Modeling dependencies between systems, libraries, and services
- •Building organizational knowledge maps
- •Representing domain-specific ontologies
Quick Example
import Rekall from '@rekall/sdk';const rekall = new Rekall({ apiKey: 'rk_your_api_key' });// Create entitiesconst user = await rekall.semantic.entities.create({name: 'Sarah',type: 'person',attributes: {role: 'Senior Engineer',company: 'Acme Corp',},});const python = await rekall.semantic.entities.create({name: 'Python',type: 'technology',attributes: {category: 'programming_language',version: '3.12',},});// Create a relationshipawait rekall.semantic.relationships.create({source: user.id,target: python.id,type: 'knows',metadata: {proficiency: 'expert',years: 8,},});
Entities
Entities are the nodes of your knowledge graph. Each entity has a name, a type, and arbitrary attributes.
| Field | Type | Required | Description |
|---|---|---|---|
| name | string | Yes | The entity name. Must be unique within its type. |
| type | string | Yes | Entity type (e.g., "person", "technology", "project", "concept"). |
| attributes | object | No | Arbitrary key-value pairs for entity properties. |
Relationships
Relationships are directed edges connecting two entities. They carry a type label and optional metadata.
| Field | Type | Required | Description |
|---|---|---|---|
| source | string | Yes | The source entity ID. |
| target | string | Yes | The target entity ID. |
| type | string | Yes | Relationship label (e.g., "knows", "depends_on", "works_at"). |
| metadata | object | No | Arbitrary metadata for the relationship edge. |
Advanced Usage
Graph Traversal
Traverse the knowledge graph from any entity to discover connected knowledge. Specify direction, relationship types, and traversal depth.
// Find everything Sarah knowsconst graph = await rekall.semantic.traverse({entityId: user.id,relationshipTypes: ['knows', 'uses'],direction: 'outgoing',depth: 2,});for (const node of graph.nodes) {console.log(node.name, node.type);}for (const edge of graph.edges) {console.log(edge.source, '->', edge.type, '->', edge.target);}
Entity Search
Search for entities by name, type, or attributes. Supports partial matching and attribute filters.
// Search by type and attributesconst results = await rekall.semantic.entities.search({type: 'technology',attributes: { category: 'programming_language' },query: 'Python',});// Find all relationships for an entityconst rels = await rekall.semantic.relationships.list({entityId: user.id,type: 'knows',});
Use Cases
User Skill Profiles
Model users and the technologies they know with proficiency levels. Query "who on the team knows Kubernetes?" by traversing the graph.
Dependency Mapping
Track which projects depend on which libraries. When a library has a security vulnerability, traverse to find all affected projects.
Organizational Knowledge
Model teams, projects, and people. Who works on what, who reports to whom, which projects serve which business functions.
Domain Ontologies
Build domain-specific concept maps. In a medical agent, link symptoms, conditions, and treatments. In a legal agent, connect statutes, cases, and precedents.
Best Practices
Entity naming conventions
Use consistent, descriptive names. Prefer "Python 3.12" over "py". Consistent naming prevents duplicate entities and improves search quality.
- 1.Define a type vocabulary. Standardize entity types ("person", "technology", "project") and relationship types ("knows", "depends_on", "works_at") early.
- 2.Deduplicate entities. Before creating a new entity, search for existing ones. Use the upsert pattern to update attributes rather than creating duplicates.
- 3.Add metadata to relationships. Include context like proficiency level, confidence, or when the relationship was established.
- 4.Keep traversal depth shallow. For most use cases, depth 2-3 is sufficient. Deep traversals can return large result sets.
- 5.Link episodic memories. When an episodic memory mentions an entity, create a cross-reference. This connects events to structured knowledge.
Related
Semantic entities can be referenced by episodic memories and are a key part of cross-memory relationships.
