Add inert source-backed claims schema foundation#118
Conversation
Establish storage-only foundation for future source-backed claim packets. Nothing reads or writes this table yet: no extraction, queue, MCP tools, API routes, search fusion, or dashboard — existing search is untouched. - scripts/setup-db-claims*.sql: claims table across all four provider variants (1536/3072/1024/768), dimension-only diffs mirroring the insights schema pattern (inline RLS, generated FTS column, shared update_updated_at trigger). - Claims are chunk-anchored: chunk_id is NOT NULL and offsets are UTF-16 indices into chunks.content, the only basis that round-trips per src/utils/source-span.ts. embedding is a nullable vector(N) column with NO vector index in this PR (provider-safe indexes, incl. the Google 3072d HNSW question, deferred to the retrieval PR). - Light constraints only: status/state/sensitivity CHECK sets, ordered non-negative offsets, confidence in [0,1], no self-supersession. - Add Claim/ClaimStatus/ClaimState/ClaimSensitivity types. - Add claims-schema text-contract smoke test (65 assertions) that keeps the four variants in sync and asserts no vector index is present. - Document the schema in CLAUDE.md feature schema list. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SscVJjuHF4BMezAxW9by5m
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (5)
WalkthroughFour provider-specific SQL setup scripts are added ( 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@scripts/setup-db-claims.sql`:
- Around line 103-104: The CREATE POLICY statement for claims_deny_anon will
fail on subsequent script runs because the policy already exists. Add a DROP
POLICY IF EXISTS claims_deny_anon ON claims statement immediately before the
CREATE POLICY claims_deny_anon statement to make the policy creation idempotent.
This ensures the policy is safely dropped (if it exists) before being recreated
on each run.
- Around line 35-37: The table is missing a constraint to ensure that the
chunk_id actually belongs to the document_id. Currently, document_id and
chunk_id are validated independently against their respective tables, but there
is no guarantee they form a valid document-chunk pair. Add a composite foreign
key constraint that references both the document_id and chunk_id columns
together against the chunks table to enforce this relationship, ensuring that
only chunk_id values that actually belong to the specified document_id are
allowed in the table.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9866a068-cc1e-4bfb-a754-6cdecebd4b60
📒 Files selected for processing (7)
CLAUDE.mdscripts/setup-db-claims-google.sqlscripts/setup-db-claims-ollama-v2.sqlscripts/setup-db-claims-ollama.sqlscripts/setup-db-claims.sqlsrc/db/__tests__/claims-schema.test.tssrc/types/database.ts
…/chunk FK - Make RLS policy creation rerunnable: DROP POLICY IF EXISTS before CREATE POLICY claims_deny_anon, so re-applying the script no longer errors (the rest of the script was already idempotent). - Enforce provenance pair integrity at the schema level: a claim's (document_id, chunk_id) must be a real pair, not two independently valid ids. Replace the standalone chunk_id FK with a composite FOREIGN KEY (document_id, chunk_id) REFERENCES chunks(document_id, id) ON DELETE CASCADE. The required unique index on chunks(document_id, id) is created by the claims script itself (chunks.id is already unique, so it always builds), keeping the base setup-db*.sql ingestion path untouched for deployments that don't enable claims. - Extend the schema smoke test to assert the composite FK, its unique index target, and the idempotent policy across all four variants. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SscVJjuHF4BMezAxW9by5m
Summary
Establishes a storage-only foundation for future source-backed claim packets, the next step after the merged source-span resolver (
src/utils/source-span.ts).This PR is deliberately inert: nothing reads from or writes to the new table yet. No extraction (LLM), queue, MCP tools, API routes, search fusion, or dashboard — existing search behavior is untouched and no new tools are registered.
What's included
scripts/setup-db-claims.sql(1536),-google.sql(3072),-ollama.sql(1024),-ollama-v2.sql(768). Mirrors the insights schema pattern: inline RLS (deny anon/authenticated), generated weighted FTS column (claim > question > quote), and reuse of the sharedupdate_updated_at()trigger.Claim,ClaimStatus,ClaimState,ClaimSensitivityinsrc/types/database.ts.src/db/__tests__/claims-schema.test.ts— a pure text-contract smoke test (65 assertions) modeled onuploads-schema.test.ts, keeping the four variants in sync and asserting that no vector index is present.Key design decisions
chunk_idNOT NULL,ON DELETE CASCADE). The offsets are UTF-16 indices intochunks.content— the only basis that round-trips per the source-span resolver. A claim cannot exist without its anchoring chunk.document_idis kept (NOT NULL, CASCADE) as a denormalized convenience.embedding vector(N)with NO vector index. No embedding pipeline writes claims yet. Provider-safe vector indexes — including the pgvector >2000-dim HNSW question on the Google 3072d variant — are deferred to the future retrieval PR. The schema test enforces the absence of anyhnsw/ivfflatindex.superseded_byself-FK withON DELETE SET NULL). Avoids over-constraining before real extraction exists.Out of scope (future PRs)
LLM/claim extraction, a writer/db module, processing queue, MCP tools, API routes, search/retrieval fusion, visual retrieval, and the project-wide Google 3072d HNSW story.
Verification
pnpm verify:fastpasses locally: lint, typecheck, 416 tests (65 new), security, docs, and tool-sync checks all green. Confirmed inert — no runtimesrc/code references the table.🤖 Generated with Claude Code