feat: add persistent memory with SQLite, embeddings, and hybrid retrieval#10
Conversation
…eval Implement Step 5 of the architecture — persistent memory backed by SQLite (pure Go, no CGO) with OpenAI embeddings and hybrid vector+FTS retrieval using reciprocal rank fusion. Replace the context budget stub with real rolling summarization. New packages/files: - internal/memory/ — SQLite DB layer, OpenAI embedding backend, memory store (MemoryRetrieval), session store, vector/FTS retrieval with RRF - internal/tool/memory_search.go — memory_search tool (ReadOnly) - internal/tool/memory_save.go — memory_save tool (SideEffecting) Modified: - RegisterBuiltins now accepts optional MemoryRetrieval for memory tools - AgentRuntime gains SetMemory() for persistent conversation history and real summarization when context budget is exceeded - Session gains CompactWithSummary() for context window compaction - CLI wires memory DB, embedder, session store, and tools 11 new tests covering all memory operations, all passing with -race. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Review Summary by QodoAdd persistent memory with SQLite, embeddings, and hybrid retrieval
WalkthroughsDescription• Implement persistent memory system with SQLite, OpenAI embeddings, and hybrid retrieval • Add rolling summarization to compact conversation history when context budget exceeded • Introduce memory_search (ReadOnly) and memory_save (SideEffecting) LLM tools • Wire memory DB, embedder, session store into CLI and runtime with graceful degradation Diagramflowchart LR
A["CLI run command"] -->|opens| B["SQLite DB"]
A -->|creates| C["OpenAI Embedder"]
A -->|initializes| D["Memory Store"]
A -->|creates| E["Session"]
D -->|hybrid search| F["Vector + FTS Results"]
F -->|RRF fusion| G["Ranked Chunks"]
H["Agent Runtime"] -->|stores events| D
H -->|checks budget| I["Summarization"]
I -->|compacts| J["Session with Summary"]
K["memory_search tool"] -->|queries| D
L["memory_save tool"] -->|persists| D
File Changes1. internal/memory/sqlite.go
|
Code Review by Qodo
1.
|
Summary
modernc.org/sqlite) with WAL mode, FTS5 full-text search, and OpenAItext-embedding-3-smallvector embeddingscheckContextBudget()stub with real rolling summarization that compacts conversation history when context budget is exceededmemory_search(ReadOnly) andmemory_save(SideEffecting) tools for LLM-driven memory operationsruncommandNew files
internal/memory/sqlite.gointernal/memory/embedding.gointernal/memory/embedding_openai.goopenai-goSDKinternal/memory/retrieval.gointernal/memory/store.goMemoryRetrievalimplementationinternal/memory/session_store.goSessionStoreCRUD backed by SQLiteinternal/memory/memory_test.gointernal/tool/memory_search.gomemory_searchtoolinternal/tool/memory_save.gomemory_savetoolDesign decisions
OPENAI_API_KEYfalls back to FTS-only; memory init failure continues without memoryTest plan
go build ./...passesgo vet ./...passesgo test ./internal/memory/ -race -count=1— 11/11 tests passgo test ./... -race -count=1— all packages passyantra run "Remember my favorite language is Go"thenyantra run "What is my favorite language?"(requires API keys).yantra/memory.dbis created with correct schema🤖 Generated with Claude Code