feat: implement AI source selection and toggle for document-based knowledge (AIIA-66)

Add source scope (case/global) to documents, enabling users to select
which uploaded documents the AI considers during analysis. Includes
schema migration, API support, reusable source selection UI component,
and integration into the analyse form.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
CTO (LegalAI)
2026-04-10 19:54:23 +00:00
parent fe838d5916
commit d7bdeb7da2
10 changed files with 334 additions and 10 deletions

View File

@@ -0,0 +1,17 @@
-- Add source scope to documents table (AIIA-66)
-- Documents are either case-specific or globally available
DO $$ BEGIN
CREATE TYPE "document_source_scope" AS ENUM ('case', 'global');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
ALTER TABLE "documents"
ADD COLUMN IF NOT EXISTS "source_scope" "document_source_scope" NOT NULL DEFAULT 'case';
-- Auto-set global scope for norm documents (they are always globally available)
UPDATE "documents" SET "source_scope" = 'global' WHERE "category" = 'norm';
-- Index for efficient source scope queries
CREATE INDEX IF NOT EXISTS "documents_source_scope_idx" ON "documents" ("source_scope");