Skip to content

Index memory tags in FTS (#58) - #69

Merged
7vignesh merged 1 commit into
mainfrom
fix/index-tags-in-fts
Oct 26, 2026
Merged

7vignesh merged 1 commit into
mainfrom
fix/index-tags-in-fts

Conversation

@7vignesh

Copy link
Copy Markdown
Owner

Closes #58 (and the duplicate #4).

What

Index memories.tags in the FTS5 table so tag text contributes to keyword recall. Previously the external-content table was fts5(repo, note) only, so a query matching a tag but not the note body missed the memory.

How

  • Migration 013 (append-only) rebuilds memories_fts as fts5(repo, note, tags) and recreates the three insert/update/delete triggers, carrying new.tags / old.tags through. FTS5 has no ADD COLUMN, so the table is dropped and recreated; INSERT INTO memories_fts(memories_fts) VALUES ('rebuild') backfills every existing row.
  • The JSON array string stored in tags (e.g. ["git","release"]) tokenizes straight into the tag words under the FTS5 default tokenizer, so no transform is needed. Verified.
  • fts.ts needed no change: MATCH spans all FTS columns by default, so tags are searched automatically.
  • schema.sql reference updated to the final shape.

Measurement (per AGENTS.md)

npm run bench, FTS search surface:

metric before after
hit@1 72.7% 81.8%
hit@5 90.9% 93.9%
recall@5 85.6% 91.7%
MRR 0.794 0.864
synonym hit@5 33.3% 66.7%
misses 3 2

Snapshot committed. The numbers support keeping the change.

Out of scope (unchanged)

Tests

Added to tests/fts.test.ts: tag-only match, note-body regression, and an update-trigger regression. npm run ci green.

Tags were stored on every memory but never indexed: the external-content
FTS table was fts5(repo, note) only, so a query matching a tag but not the
note body missed the memory.

Migration 013 rebuilds memories_fts as fts5(repo, note, tags) and its three
insert/update/delete triggers, carrying new.tags / old.tags through. The JSON
array string stored in memories.tags tokenizes straight into tag words under
the FTS5 default tokenizer, so no transform is needed. The index is backfilled
for existing rows via the 'rebuild' command (FTS5 has no ADD COLUMN).

schema.sql reference updated to the final shape.

Bench (fts search surface): hit@1 72.7 -> 81.8, hit@5 90.9 -> 93.9,
recall@5 85.6 -> 91.7, MRR 0.794 -> 0.864; synonym category 33.3 -> 66.7;
misses 3 -> 2. Snapshot committed.
@vercel

vercel Bot commented Oct 26, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
fossel Ready Ready Preview Oct 26, 2026 12:56pm UTC

@7vignesh
7vignesh merged commit 87b7bc8 into main Oct 26, 2026
6 checks passed
@7vignesh
7vignesh deleted the fix/index-tags-in-fts branch October 26, 2026 13:19
@7vignesh 7vignesh mentioned this pull request Oct 27, 2026
7vignesh added a commit that referenced this pull request Oct 27, 2026
Release 2.1.0. Ships the backlog merged to main since v2.0.0, notably:
- Index memory tags in FTS (#58 / #69)
- Tag-filtered retrieval on get_context and search_memory (#59 / #71)

Pushing the v2.1.0 tag after this merges triggers the npm publish workflow,
which re-checks that the tag matches package.json before publishing.

This branch was successfully deployed

1 active deployment
Preview — 3f231dba Deployed Oct 26, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Index memory tags in FTS

1 participant