Skip to content

feat: add FTS5 full-text search for memory retrieval#2

Open
sergi-rz wants to merge 1 commit intocodejunkie99:masterfrom
sergi-rz:feat/memory-search-fts5
Open

feat: add FTS5 full-text search for memory retrieval#2
sergi-rz wants to merge 1 commit intocodejunkie99:masterfrom
sergi-rz:feat/memory-search-fts5

Conversation

@sergi-rz
Copy link
Copy Markdown

@sergi-rz sergi-rz commented Apr 16, 2026

Problem

The memory system can surface the top-k entries by salience score (context_budget.py), but there's no way to search by topic or keyword. If an agent needs to recall what it learned about deploys, or a specific past failure, it has no retrieval path — it only sees whatever happens to score highest globally.

Solution

A lightweight memory_search.py that builds a SQLite FTS5 index over all .md and .jsonl files in .agent/memory/. It:

  • Auto-rebuilds when any source file is newer than the index
  • Falls back to grep if FTS5 isn't compiled into the Python installation
  • Indexes JSONL entries by extracting action, reflection, detail, and skill fields into searchable text
  • Returns ranked results with context snippets highlighting matches

Usage

python3 .agent/memory/memory_search.py "deploy failure"
python3 .agent/memory/memory_search.py --status
python3 .agent/memory/memory_search.py --rebuild

What's changed

  • New file: .agent/memory/memory_search.py — the search tool (~170 lines, zero dependencies beyond stdlib)
  • .gitignore — excludes .agent/memory/.index/ (derived, auto-rebuilt)
  • memory-manager/SKILL.md — documents the search command so the agent knows it exists

No existing code is modified. This is purely additive.

Context

I'm building Claudia OS, a personal AI assistant on top of Claude Code. I adopted your episodic memory architecture, dream cycle, and salience scoring (credited in my ATTRIBUTION.md). While adapting it, I needed keyword search over memory — the salience-only retrieval wasn't enough when the agent needed to recall something specific. This FTS5 approach solved it cleanly without adding infrastructure.

🤖 Generated with Claude Code

Currently the memory system can only surface top-k entries by salience
score, but cannot search by topic or keyword. This adds a lightweight
SQLite FTS5 search tool that indexes all .md and .jsonl files under
.agent/memory/ and returns ranked results with context snippets.

- memory_search.py: FTS5 index with auto-rebuild and grep fallback
- .gitignore: exclude derived .index/ directory
- memory-manager SKILL.md: document the search command

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codejunkie99 codejunkie99 self-assigned this Apr 16, 2026
@codejunkie99 codejunkie99 added the enhancement New feature or request label Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants