Long-Term Memory

Consolidated knowledge extracted from episodic memories. Features natural decay based on access frequency and importance, inspired by human memory science.

What Is Long-Term Memory?

Long-term memory stores knowledge that has been distilled from episodic experiences. Rather than remembering every individual interaction, the consolidation process extracts patterns, insights, and key facts into durable memories that persist over time.

Like human memory, long-term memories decay naturally if not accessed. Frequently retrieved memories grow stronger, while unused memories gradually fade. This ensures that the most relevant knowledge remains readily available while stale information naturally expires.

When to Use

  • Storing distilled knowledge that should persist across sessions
  • Building a knowledge base from repeated interactions
  • Maintaining key facts that are accessed regularly
  • Allowing stale knowledge to naturally expire
  • Querying consolidated insights from past experiences

Automatic vs. manual

Long-term memories are typically created by the consolidation process, but you can also create them directly via the API when you want to store durable knowledge without going through episodic memory first.

Quick Example

Create and query long-term memories
import Rekall from '@rekall/sdk';
const rekall = new Rekall({ apiKey: 'rk_your_api_key' });
// Create a long-term memory directly
const memory = await rekall.longTerm.create({
content: 'Sarah prefers Python for backend services and TypeScript for frontend. She values type safety and comprehensive test coverage.',
importance: 0.85,
source: 'consolidation', // or 'manual'
tags: ['user:sarah', 'preferences', 'languages'],
});
// Search long-term memories
const results = await rekall.longTerm.search({
query: 'What are Sarah\'s programming preferences?',
limit: 5,
minStrength: 0.3,
});
for (const mem of results) {
console.log(mem.content, mem.strength, mem.lastAccessed);
}

Consolidation Process

Consolidation runs periodically (configurable, default every 6 hours) and processes recent episodic memories to extract patterns and insights. The process:

  1. Identifies clusters of related episodic memories
  2. Extracts common themes, facts, and patterns from each cluster
  3. Checks for existing long-term memories that overlap
  4. Creates new long-term memories or strengthens existing ones
  5. Assigns importance scores based on frequency and source importance

Triggering consolidation manually

You can trigger consolidation on-demand via the API. This is useful after ingesting a large batch of episodic memories or when you need immediate knowledge extraction.

Trigger consolidation
// Trigger consolidation manually
const result = await rekall.longTerm.consolidate({
since: '2025-01-01T00:00:00Z', // Process memories since this date
dryRun: false, // Set true to preview without saving
});
console.log(result.created, 'new long-term memories');
console.log(result.strengthened, 'existing memories updated');

Decay Formula

Memory strength decays according to an Ebbinghaus-inspired forgetting curve. The formula balances initial importance, time elapsed, and access frequency:

Decay formula
strength = importance * e^(-decay_rate * time_elapsed) + access_bonus
where:
importance = initial importance score (0.0 to 1.0)
decay_rate = base decay rate (default: 0.1, configurable per context)
time_elapsed = hours since creation or last consolidation
access_bonus = log(1 + access_count) * 0.1
A memory is considered "forgotten" when strength drops below the
threshold (default: 0.05). Forgotten memories are archived, not deleted.

Decay is configurable

You can adjust the decay rate and threshold per memory context. A lower decay rate means memories persist longer. Set decay_rate to 0 to disable decay entirely for a context.

Advanced Usage

Importance Scoring

Importance determines how quickly a memory decays and whether it survives consolidation. Several factors influence the score:

FactorWeightDescription
Source episodic importance0.4Average importance of contributing episodic memories.
Frequency of occurrence0.3How often this pattern appeared in episodic memories.
Recency0.2How recently contributing episodes occurred.
Uniqueness0.1Whether this insight is distinct from existing long-term memories.

Retrieval Strengthening

Every time a long-term memory is retrieved (via search or direct access), its strength increases. This models the "testing effect" from cognitive science: retrieving information strengthens the memory trace.

Check and boost memory strength
// Get memory with strength info
const memory = await rekall.longTerm.get('mem_abc123');
console.log('Strength:', memory.strength);
console.log('Access count:', memory.accessCount);
console.log('Last accessed:', memory.lastAccessed);
// Manually boost a memory's strength
await rekall.longTerm.boost('mem_abc123', {
amount: 0.2, // Add to current strength
reason: 'User confirmed this is still accurate',
});

Use Cases

User Knowledge Base

Over many conversations, consolidation extracts durable facts about the user: their role, preferences, common questions, and communication style.

Project Insights

Repeated patterns in code reviews, bug reports, and discussions are consolidated into insights: "This codebase tends to have issues with X", "The team prefers Y approach."

Natural Knowledge Pruning

Outdated information naturally decays. If a user switches from Python to Go, the Python preference memories weaken while Go-related memories strengthen through access.

Best Practices

  • 1.Trust the consolidation process. Let episodic memories accumulate and let consolidation extract patterns. Avoid manually creating long-term memories for things that should emerge from experience.
  • 2.Set appropriate importance on source episodic memories. High-importance episodes are more likely to be consolidated into long-term knowledge.
  • 3.Monitor decay thresholds. If important knowledge is decaying too quickly, adjust the decay rate or boost specific memories.
  • 4.Use minStrength in searches. Filter out weakened memories by setting a minimum strength threshold when searching.
  • 5.Review archived memories. When memories drop below the threshold, they are archived rather than deleted. You can restore them if needed.

Related

Long-term memories are created from episodic memories via the consolidation process. See also short-term memory for session-scoped context.

Rekall
rekall