Skip to main content

Memory Types

memharness provides 9 distinct memory types, each optimized for specific retrieval patterns and use cases. Understanding the memory taxonomy helps you choose the right type for your agent's needs.

Memory Taxonomy

Agent memory follows a hierarchical taxonomy based on duration and purpose:

Short-Term Memory

Short-term memory exists only during a session and is lost afterward:

TypeWhat it storesExample
Semantic CacheVector search + cached LLM responses for similar queries"Weather in Delhi?" → reuse cached response
Working MemoryLLM context window + session-based memory (scratchpad)Chain-of-thought reasoning, intermediate results

Short-term memory is like RAM — gone when you shut down.

Long-Term Memory

Long-term memory persists across sessions and survives restarts. memharness implements three categories:

Procedural Memory (How to do tasks)

TypeWhat it storesExample
WorkflowStep-by-step procedures that worked"Called API A → parsed → triggered B"
ToolboxTool configurations and capabilitiessearch_arxiv(query: str, k: int) → "Search papers"

Semantic Memory (Facts & knowledge)

TypeWhat it storesExample
EntityPeople, organizations, systems"Ayush works at SAP", "Kafka uses partitions"
KnowledgeDomain knowledge, documentsarXiv papers, product docs, reference material
FileDocument references/docs/architecture.pdf

Episodic Memory (Experiences & history)

TypeWhat it storesExample
PersonaAgent identity and behavioral patterns"I am a helpful coding assistant"
SummaryCompressed past conversations30 messages → 1 paragraph
ConversationalComplete chat history[user] "Book the first one for 7pm"
Tool LogTool execution audit trailsearch_arxiv({query:"flash"}) → 5 results (success)

The 9 Memory Types

memharness implements the long-term memory types:

Memory TypeOne-LinerStorageWhat Gets Stored
ConversationalChat history per threadSQLrole, content, timestamp per message
KnowledgeDomain knowledge & factsVectorDocuments, papers, reference material + embeddings
Workflow"How did I do this before?"VectorSteps taken + outcome for a task
ToolboxAvailable tools & capabilitiesVectorTool name, description, parameters, signature
EntityPeople, places, systemsVectorName, type (PERSON/PLACE/SYSTEM), description
SummaryCompressed older conversationsVectorCondensed context when chat history gets too long
Tool LogRaw tool execution audit trailSQLTool name, args, result, status, timestamp
FileDocument referencesVectorFile path, content snippets, metadata
PersonaAgent identityVectorBehavioral patterns, style, preferences

Storage Strategy: SQL vs Vector

Different memory types use different storage strategies based on their access patterns:

StorageUsed ForWhyAccess Pattern
SQLConversational, Tool LogExact match by thread_id, chronological ordering — no semantic search neededTime-ordered retrieval by thread
VectorEverything elseSemantic similarity search — find relevant content by meaning, not exact keywordsTop-K similarity search

Why Two Storage Types?

The decision is driven by how you need to retrieve the memory:

  • SQL = "Give me exact match on thread_id, ordered by timestamp"
  • Vector = "Find me stuff similar to this query based on semantic meaning"

Different tools for different jobs.

SQL Tables: Conversational & Tool Log

These memories need exact-match retrieval and chronological ordering:

CREATE TABLE conversational_memory (
id VARCHAR PRIMARY KEY,
thread_id VARCHAR NOT NULL,
role VARCHAR NOT NULL, -- 'user' or 'assistant'
content TEXT NOT NULL,
timestamp TIMESTAMP NOT NULL,
summary_id VARCHAR, -- Links to summary when compacted
metadata JSONB
);

CREATE INDEX idx_thread_time ON conversational_memory(thread_id, timestamp);

Vector Stores: Everything Else

These memories need semantic similarity search:

  • Each memory unit is embedded using an embedding model
  • Embedding + metadata → stored in vector store
  • Query is embedded → top-K similarity search finds closest matches
  • Results ranked by cosine similarity (or other distance metrics)

Vector indexes (HNSW, IVF) enable fast retrieval without scanning all rows.

Quick Reference

Memory TypeExampleWhen to Use
Conversational[user] "Book the first one for 7pm"Chat history, multi-turn context
KnowledgearXiv papers, product docsFacts the agent should ground responses in
EntityDr. Sarah Chen (PERSON): MIT, efficient attentionTrack people, places, organizations
WorkflowQuery → arXiv search → filter → summarize → ✅Reusable procedures that worked
Toolboxsearch_arxiv(query, k=5) → "Search arXiv papers"Tool discovery and selection
Summary30 messages → 1 paragraph summaryCompress old conversations
Tool Logsearch_arxiv({query:"flash"}) → 5 results (success)Audit trail, debugging
File/path/to/report.pdfDocument tracking
Persona"I am a helpful coding assistant"Agent identity

Workflow vs Tool Log

A common point of confusion:

Workflow MemoryTool Log
PurposeReusable patternsRaw audit trail
Content"What strategy worked""What exactly happened"
AnalogyRecipeKitchen CCTV
SearchSemantic (find similar workflows)Exact match (by thread_id/time)

Next Steps