Skip to content

test(rag): guard RC9 — lexical text path must not fabricate a cosine similarity - #245

Merged
BigSimmo merged 1 commit into
mainfrom
claude/rc9-verify-guard
Jul 3, 2026
Merged

test(rag): guard RC9 — lexical text path must not fabricate a cosine similarity#245
BigSimmo merged 1 commit into
mainfrom
claude/rc9-verify-guard

Conversation

@BigSimmo

Copy link
Copy Markdown
Owner

Summary

RC9 verify (safe, offline, no live spend). RC9 was the concern that the text-only retrieval fallback fabricated a similarity (0.56 + text_rank*0.39) that downstream gates read as a real cosine, letting a pure keyword hit clear the >=0.64 "moderate/strong" evidence bar.

Audit result — already comprehensively fixed in supabase/schema.sql:

  • match_document_chunks_text sets similarity = 0 (with an inline comment naming the exact concern) and carries the lexical signal in a hybrid_score capped at least(0.5, …) — strictly below the 0.64 moderate gate — plus a separate lexical_score.
  • match_document_lookup_chunks_text and match_document_table_facts_text return only text_rank — no similarity/hybrid_score column to fabricate (the similarity() in table-facts is the pg_trgm function, not an output).
  • Code-side reads use hybrid_score ?? similarity ?? 0, and result mapping coalesces similarity to a number, so a lexical-only row contributes at most the capped hybrid_score and never a synthetic cosine.

This PR adds a regression guard (source-text assertion in tests/supabase-schema.test.ts) so the similarity = 0 + capped-hybrid_score invariant can't silently drift back. schema.sql is the canonical definition (the 20260702170000 migration is a documented no-op; live/schema reconciliation is a separate tracked item).

Test-only change: supabase-schema.test.ts 31/31 pass, prettier + typecheck clean.

🤖 Generated with Claude Code

…similarity
Verified RC9 is fully handled at the SQL layer: match_document_chunks_text sets
similarity=0 (documented inline) with the lexical signal in a hybrid_score capped at
0.5 (below the 0.64 moderate gate); match_document_lookup_chunks_text and
match_document_table_facts_text return only text_rank, with no similarity column to
fabricate. Adds a source-text regression guard so the chunks-text similarity=0 +
capped-hybrid_score invariant cannot silently drift back (the neutralized 20260702170000
migration + known hybrid-RPC drift make schema.sql the canonical definition this guards).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@BigSimmo
BigSimmo merged commit b55d6bf into mainJul 3, 2026
4 checks passed
@BigSimmo
BigSimmo deleted the claude/rc9-verify-guard branch July 3, 2026 12:17
Sign up for freeto 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.

1 participant

@BigSimmo