Memory Systems / AI Architecture

Semantic Memory

Intermediate [3/5]
Knowledge memory Factual memory Concept memory

Definition

Semantic Memory stores general knowledge, facts, and concepts independent of personal experience or temporal context. In AI systems, this represents the "world knowledge" that enables understanding and reasoning about concepts.

For LLMs, semantic memory includes both the knowledge encoded during pre-training and external knowledge bases accessed through RAG or similar techniques.

Key Concepts

  • Factual knowledge: Objective facts about the world
  • Conceptual relationships: How concepts relate to each other
  • Context-independence: True regardless of when/where learned
  • Knowledge graphs: Structured semantic knowledge representation

Examples

Structure
Semantic Memory Organization
SEMANTIC MEMORY TYPES: 1. FACTUAL KNOWLEDGE: - "Python was created by Guido van Rossum" - "The Earth orbits the Sun" - "HTTP status 404 means 'Not Found'" 2. CONCEPTUAL KNOWLEDGE: - "Inheritance is a type of code reuse" - "APIs enable system communication" - "Recursion involves self-reference" 3. RELATIONAL KNOWLEDGE: - "Python IS-A programming language" - "FastAPI USES Pydantic" - "Transformers IMPROVED-UPON RNNs" --- KNOWLEDGE REPRESENTATION: FLAT (Simple key-value): { "python_creator": "Guido van Rossum", "python_year": 1991, "python_type": "programming language" } HIERARCHICAL (Taxonomy): Programming Languages ├── Compiled │ ├── C │ ├── Go │ └── Rust └── Interpreted ├── Python ├── JavaScript └── Ruby GRAPH (Knowledge graph): ┌─────────┐ created_by ┌───────────────┐ │ Python │─────────────→│ Guido van │ └────┬────┘ │ Rossum │ │ └───────────────┘ │ is_a ▼ ┌─────────────────────┐ │ Programming Language │ └──────────┬──────────┘ │ has_feature ▼ ┌─────────────────────┐ │ Dynamic Typing │ └─────────────────────┘ VECTOR (Embeddings): "Python" → [0.23, -0.45, 0.12, ..., 0.89] "JavaScript" → [0.21, -0.42, 0.15, ..., 0.85] (Similar concepts = similar vectors)
Implementation
Semantic Memory in LLM Systems
SEMANTIC MEMORY SOURCES IN LLMs: 1. PARAMETRIC MEMORY (Built-in): - Knowledge encoded in model weights - Learned during pre-training - Fixed after training (can't update) LLM: "Python was created in 1991" (Knows this from training data) 2. NON-PARAMETRIC MEMORY (External): - Knowledge bases, databases - Retrieved at inference time - Can be updated independently RAG: [Query] → [Retrieve docs] → [Augment prompt] (Gets current info from external source) --- COMBINING MEMORY TYPES: User: "What's the latest Python version?" Parametric (may be outdated): "Python 3.11 is the latest" (training cutoff) + Non-parametric (current): [Retrieved: "Python 3.12 released Oct 2023"] Combined answer: "Python 3.12 is the current stable release." --- SEMANTIC MEMORY SYSTEM ARCHITECTURE: ┌─────────────────────────────────────────────┐ │ USER QUERY │ └──────────────────┬──────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────┐ │ QUERY UNDERSTANDING │ │ Extract: entities, intent, concepts │ └──────────────────┬──────────────────────────┘ │ ┌──────────┴──────────┐ ▼ ▼ ┌───────────────┐ ┌───────────────────────┐ │ KNOWLEDGE │ │ VECTOR │ │ GRAPH │ │ DATABASE │ │ │ │ │ │ Structured │ │ Semantic similarity │ │ relationships │ │ search │ └───────┬───────┘ └───────────┬───────────┘ │ │ └──────────┬─────────────┘ ▼ ┌─────────────────────────────────────────────┐ │ KNOWLEDGE FUSION │ │ Combine retrieved facts + relationships │ └──────────────────┬──────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────┐ │ LLM GENERATION │ │ Generate response using fused knowledge │ └─────────────────────────────────────────────┘ KNOWLEDGE UPDATE STRATEGIES: - Vector DB: Add new embeddings - Knowledge graph: Add new triples - Parametric: Requires fine-tuning (expensive)

Interactive Exercise

Classify Memory Types

Classify each piece of information as Semantic or Episodic memory:

1. "React is a JavaScript library"
2. "User asked about React yesterday"
3. "useState is a React hook"
4. "User prefers functional components"
5. "JSX is syntactic sugar for React.createElement"

Pro Tips
  • LLM parametric knowledge has a cutoff date - use RAG for current info
  • Knowledge graphs excel at structured queries and relationships
  • Vector stores excel at fuzzy/semantic matching
  • Combine both for comprehensive semantic memory systems

Related Terms