Week 03: Memory & Context Management

Build: Personalized AI assistant with persistent long-term memory
Overview
Topics
Weekly Build
Resources
Homework

What You'll Learn

Memory is where most agents break in production. You'll learn when to use in-context memory vs vector retrieval vs external storage, and how to build systems that remember what matters without ballooning costs.

Session Schedule

DayTimeFocus
Saturday8:00 - 11:00 PM WATMemory Architecture & Vector DBs
Sunday8:00 - 11:00 PM WATPersistent Memory Build

Pre-Requisites

  • Weeks 01-02 completed
  • Docker Desktop installed (for PGVector)
  • Understanding of embeddings concept

Topics Covered

Short vs Long-Term Memory

ConversationBufferMemory, ConversationSummaryMemory, token budgets. Understanding the tradeoffs between remembering everything and remembering what matters.

Buffer Memory Summary Memory Token Budget

Context Window Management

Sliding window, summarization chains, priority-based context selection. How to keep your agent informed without blowing through your token budget.

Sliding Window Summarization Context Selection

FAISS & Vector Similarity Search

Embeddings, cosine similarity, FAISS index creation, k-NN retrieval. Building fast, local vector search from scratch.

FAISS Embeddings Cosine Similarity

PGVector with PostgreSQL

Docker setup, pgvector extension, CRUD operations, hybrid queries. Production-grade vector storage that scales with your application.

PGVector PostgreSQL Docker

Memory Summarization Strategies

Entity extraction, fact storage, cross-session persistence, memory decay. Building memory systems that get smarter over time, not just bigger.

Entity Extraction Persistence Memory Decay

Weekly Build: Personalized AI Assistant

Build an assistant that remembers user preferences, past conversations, and extracted entities across sessions using Redis + PostgreSQL.

Architecture

User Message
    |
    v
Context Loader
    ├── Redis: Last 6 messages (session)
    ├── PostgreSQL: Entity store (cross-session)
    └── FAISS: Relevant past conversations
    |
    v
LLM (with full context)
    |
    v
Response + Memory Update
    ├── Update Redis session
    ├── Extract & store entities
    └── Index conversation in FAISS

Key Files

FilePurpose
main.pyCLI entry point
memory/session.pyRedis sliding window
memory/entities.pyPostgreSQL entity store
memory/vector.pyFAISS retrieval
assistant.pyMain assistant logic

Resources

Required Reading

  • LangChain Memory documentation
  • FAISS wiki — Getting Started
  • PGVector GitHub README & usage guide

Code Repository

Switch to the week-03 branch:

git checkout week-03

Session Recording

Recording will be available within 24 hours after the live session. Check the WhatsApp group for the link.

Homework

Due before Week 4 live session.

  1. Complete the personalized assistant build — push your code to the bootcamp repo
  2. Add memory decay — implement a strategy that deprioritizes old, unused memories
  3. Benchmark FAISS vs PGVector — compare retrieval speed and relevance on 1,000+ stored messages
  4. Write a 1-page reflection on memory tradeoffs — when is more memory actually worse? Share in the WhatsApp group