Add authorization-filtered PostgreSQL lexical search (I03, #19) #63
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
primatekuntech/rag-rust!63
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/19-lexical-search"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Refs #19 (I03). Implementation plan:
docs/superpowers/plans/2026-10-27-lexical-search.md; guide:docs/operations/lexical-search.md.What
rag-retrieval:LexicalSearch,LexicalQuery(NFC, trimmed, ≤512 chars, no NUL),ResultLimit(1..=50, refused not clamped),LexicalHit(chunk id, version id, score only), payload-freeSearchError.0013_lexical_index.sql: generatedtsv(to_tsvector('simple', text)), GIN index, RLS select policy andSELECT (id, version_id, organization, tsv)forrag_app(nevertext). The startup guard now allows exactly those four columns and rejects anything else.PostgresStoreimplementsLexicalSearch: one parameterized statement applies the whole scope (organization, statusactive, policy version, classification, group, compartments, need-to-know) mirroringpolicy.rs; scope expiry is checked first; 2 s statement timeout; errors carry no database detail.scripts/test-postgres.shandscripts/coverage.shdid not list the three new suites; they do now, so CI runs them.Review
Per-task reviews (spec + quality) approved all four tasks. Whole-branch dual pass: ponytail Must-fix list empty; Opus correctness review found no Critical issues and two Important documentation points (below), fixed in
4fbc4f2. Kept despite a ponytail suggestion: the score clamp, because rank fusion (#23) will rely on non-negative scores.Coverage
Workspace line coverage 94.56% (
TEST_DATABASE_URL=… bash scripts/coverage.sh rust, gate 80%);lexical.rs100%.fmt,clippy -D warningsandgitleaksclean.Read before merging
active; group, classification, compartments and need-to-know are applied in the application SQL.rag.organization_idis set by the session itself, so a bug or a compromisedrag_appcredential could read the near-content lexeme stream (tsv) of every active chunk of any marking in any organization. Nothing isactiveyet, so there is no exposure today. #21 must clear this with the security authority before it activates versions; the alternative is a laterSECURITY DEFINERfunction returning ids and scores only.document_chunksunder ACCESS EXCLUSIVE. Measured on a scratch database: 200k chunks (243 MB) took 8.6 s and the table grew 43%. A real corpus needs a maintenance window with the ingest worker drained and ~1.4× the table size in disk headroom.document_versions.status = 'active'. #21 must require the ingestion job statesucceededbefore activating (the #18 deviation);rag_appcannot read jobs, so it is not checked here.Unavailableat runtime.Not in this PR
HTTP route, rank fusion (#23), phase timing for NFR-PERF-002, a shared contract suite (add with a second implementation), accent folding and stemming.
🤖 Generated with Claude Code