Skip to content

feat(search): add a tags_all filter that requires every tag - #8

Merged
springfall2008 merged 1 commit into
springfall2008:mainfrom
chalfontchubby:feat/search-tags-all
Nov 9, 2026
Merged

springfall2008 merged 1 commit into
springfall2008:mainfrom
chalfontchubby:feat/search-tags-all

Conversation

@chalfontchubby

Copy link
Copy Markdown
Collaborator

Posted by Claude on behalf of @chalfontchubby.

Why

search's tags filter keeps memories with at least one of the tags given. So "my open work" (status:open AND an owner tag) can't be asked in one query: you fetch on one tag and filter the rest on the client. With limit capped at 100, that silently misses rows once the store grows. We hit exactly this migrating the Predbat memories into predbat-devs: an owner-tag sweep returned 100 of ~160 rows, and the open ones were split across the cut.

What

  • search gains tags_all: keep only memories that carry every tag given.
    • It combines with tags (any-of AND all-of).
    • An empty list means no filter, as for tags.
  • New migration 20261109120000_search_tags_all.sql:
    • It adds a 10-argument search_memories with p_tags_all. The @> predicate sits in each arm (keyword, semantic, hybrid kw and sem), before that arm's LIMIT, like the existing filters.
    • The body is otherwise the original one.
    • The 9-argument function becomes a thin SQL wrapper (grants kept). Neither overload has defaults, so calls are never ambiguous.
  • TS: SearchFilters.tagsAll, passed through PgMemoryStore.search and exposed as tags_all on the tool.
  • Docs: a README paragraph; the design spec's filter list now includes tags_all.

Deploy order

Run db push before functions deploy. The wrapper keeps the currently deployed function working on the new schema. The new function calls the 10-argument overload, so it needs the migration first. That is the order setup.ts and the README's manual install already use.

Tests

All run locally with Supabase CLI 3.0.0, as CI pins it:

Check Result
deno task check passes
deno task test:unit 86 passed
supabase db reset + supabase test db 11 files, 397 tests, PASS
deno task test:int 91 passed

New tests:

  • supabase/tests/database/11_search_tags_all.test.sql:
    • tags_all in each mode;
    • the filter applying before LIMIT in keyword, semantic and both hybrid arms, with filler rows that outrank the target on both keyword rank and vector distance;
    • combining with tags;
    • an unknown tag, an empty list, and an unreadable scope;
    • grants for the member, anon and authenticated;
    • the 9-argument wrapper.
  • An integration test through PgMemoryStore.
  • Unit tests:
    • the handler passes tags_all through;
    • the registered search tool's schema accepts tags_all, so a rename can't be dropped silently by zod.

Not in this PR

A review suggested a created_by / "mine" filter for the "my work" case. The server already knows who wrote each row, so it would not depend on agents tagging themselves. It would also mean deciding what an update by someone else does to "mine", so I've left it for you to decide. tags_all is useful on its own for any combination, such as repo + status.

🤖 Generated with Claude Code

search's tags filter matches memories with at least one of the tags given, so "status:open AND owner:me" could not
be asked in one query: an agent had to fetch with one tag and filter the rest client-side, and with results capped at
100 that silently missed rows once the store grew.

tags_all keeps only memories that carry every tag given. It can be combined with tags (any-of AND all-of), and an
empty list means no filter, as for tags.

A new migration adds a 10-argument search_memories with p_tags_all, applied inside each arm before its LIMIT like the
other filters. The 9-argument function becomes a SQL wrapper, so the deployed Edge Function keeps working once the
migration is applied. The new Edge Function calls the 10-argument overload, so the migration must be applied first.

Tests: a pgTAP file (every mode, before-LIMIT in each arm, combination with tags, empty list, RLS, grants, the 9-argument
wrapper), an integration test through PgMemoryStore, and unit tests for the handler and the registered tool schema.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@springfall2008
springfall2008 merged commit cfb0419 into springfall2008:main Nov 9, 2026
1 check passed
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.

2 participants