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

Create entities and a relationship
import Rekall from '@rekall/sdk';
const rekall = new Rekall({ apiKey: 'rk_your_api_key' });
// Create entities
const 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 relationship
await 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.

FieldTypeRequiredDescription
namestringYesThe entity name. Must be unique within its type.
typestringYesEntity type (e.g., "person", "technology", "project", "concept").
attributesobjectNoArbitrary key-value pairs for entity properties.

Relationships

Relationships are directed edges connecting two entities. They carry a type label and optional metadata.

FieldTypeRequiredDescription
sourcestringYesThe source entity ID.
targetstringYesThe target entity ID.
typestringYesRelationship label (e.g., "knows", "depends_on", "works_at").
metadataobjectNoArbitrary 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.

Traverse the knowledge graph
// Find everything Sarah knows
const 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);
}

Search for entities by name, type, or attributes. Supports partial matching and attribute filters.

Search entities
// Search by type and attributes
const results = await rekall.semantic.entities.search({
type: 'technology',
attributes: { category: 'programming_language' },
query: 'Python',
});
// Find all relationships for an entity
const 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.

Rekall
rekall