AI & Agents · Intermediate
Chatbot That Remembers You
Build a chat assistant that persists facts about each user across sessions and recalls them in later conversations.
Most chatbots forget everything the moment a session ends. This project teaches you to build a chat assistant that extracts facts from what the user says, stores them as vector embeddings in Postgres, and retrieves the most relevant ones to inject into the system prompt on every new conversation. The result is an assistant that genuinely knows its users over time, without ballooning the context window with raw chat history.
What you build
- Chat interface powered by the Vercel AI SDK with streaming responses
- Automatic memory extraction: the LLM pulls user facts from each message and upserts them to a memories table
- Semantic retrieval: incoming messages are embedded and the top-K most relevant memories are fetched via pgvector cosine similarity
- Per-user memory namespacing so memories never bleed across accounts
- Memory management UI that lets users view and delete stored facts
- Session-agnostic persistence backed by Postgres so memories survive across devices and restarts
What it teaches
- Vector similarity search with pgvector and cosine distance indexing
- Retrieval-augmented generation (RAG) applied to personal memory rather than documents
- LLM-as-extractor pattern: using a structured prompt to pull typed facts from free-form conversation
- Context window management: injecting only the top-K most relevant memories instead of raw history
- Per-user data isolation and safe deletion in a multi-tenant Postgres schema
- Streaming chat responses with the Vercel AI SDK and Next.js App Router route handlers
How it works
- 1
User sends message
- Chat UI
- User session ID
↓ embed
- 2
Recall memories
- pgvector cosine search
- Top-K facts returned
↓ inject
- 3
Build prompt
- System prompt + memories block
- Current message
↓ stream
- 4
LLM responds
- OpenRouter / Groq
- Streamed tokens
↓ extract
- 5
Extract and save facts
- Fact extraction prompt
- Embed + upsert to Postgres
Sign in to open the build guide
Free account. Get the step-by-step build and every resource link.
Take it further
- Add a forgetting curve: apply a last_accessed timestamp and decay memories that have not been retrieved recently, mimicking human memory
- Layer in a graph-style deduplication pass that merges or overwrites older conflicting facts before writing new ones, using an LLM as the merge judge
- Expose an MCP-compatible memory tool so the same store can be plugged into any tool-calling agent, not just the chat UI


