diff --git a/backend/migrations/0005_chunk_indexes.sql b/backend/migrations/0005_chunk_indexes.sql new file mode 100644 index 0000000..670ad1f --- /dev/null +++ b/backend/migrations/0005_chunk_indexes.sql @@ -0,0 +1,6 @@ +-- enrich.embed looks up claims and documents without a chunk on every batch. chunk_uniq is an expression index +-- (COALESCE(...)), which those lookups can't use, so each batch scanned the whole table: after the history +-- backfill (over a million claims) a run took hours and blocked the other enrichers. Built CONCURRENTLY by hand on +-- 2026-11-14; IF NOT EXISTS makes this a no-op there. +CREATE INDEX IF NOT EXISTS chunk_claim_idx ON chunk (claim_id) WHERE claim_id IS NOT NULL; +CREATE INDEX IF NOT EXISTS chunk_document_idx ON chunk (document_id) WHERE document_id IS NOT NULL;