Skip to content

Memory Types

contextdb models cognitive memory types with different decay rates. This is primarily useful in agent_memory namespaces where different kinds of knowledge should fade at different speeds.

The four types

TypeConstantAlphaHalf-lifeWhat it models
Workingcore.MemoryWorking999.0~secondsCurrent task context, scratch state
Episodiccore.MemoryEpisodic0.08~8.7 hoursSpecific events and interactions
Semanticcore.MemorySemantic0.02~34.7 hoursGeneralized facts and knowledge
Proceduralcore.MemoryProcedural0.001~29 daysLearned skills and workflows
Generalcore.MemoryGeneral0.05~13.9 hoursUntyped (default)

Using memory types

Set MemType on writes to control how fast a memory decays:

go
// This interaction happened just now: will fade in hours
ns.Write(ctx, client.WriteRequest{
    Content: "User asked about deployment",
    SourceID: "agent:self",
    Vector:   embedding,
    MemType:  core.MemoryEpisodic,
})

// This is a learned fact: will persist for days
ns.Write(ctx, client.WriteRequest{
    Content: "The production database is on us-east-1",
    SourceID: "agent:self",
    Vector:   embedding,
    MemType:  core.MemorySemantic,
})

// This is a learned procedure: will persist for weeks
ns.Write(ctx, client.WriteRequest{
    Content: "To deploy: build, push image, helm upgrade",
    SourceID: "agent:self",
    Vector:   embedding,
    MemType:  core.MemoryProcedural,
})

Decay mechanics

The decay function is:

recency_score = exp(-alpha * age_in_hours)

After one half-life, the recency score drops to 0.5. After two half-lives, it's 0.25. The memory doesn't disappear. It just ranks lower in retrieval results.

Hours elapsedWorkingEpisodicSemanticProcedural
1~0.000.920.981.00
8~0.000.530.850.99
24~0.000.150.620.98
168 (1 week)~0.00~0.000.030.85
720 (1 month)~0.00~0.00~0.000.49

When to use which type

Working memory: For ephemeral context that's only relevant during the current task. Think "the user just said X" or "I'm currently working on Y". Drops off almost immediately.

Episodic memory: For specific interactions and events. "The deploy failed at 3pm" or "User asked to increase the timeout". Important for a few hours, then fades.

Semantic memory: For generalised facts extracted from episodes. "The API uses JWT auth" or "Deploys take about 5 minutes". Persists across sessions.

Procedural memory: For learned skills and workflows. "To fix a broken deploy: check logs, rollback, redeploy". These should persist for weeks or months.

Released under the MIT License.