Multi-tenant contract-analysis RAG application with human-in-the-loop approval for high-value actions.
[2-3 sentences: ingest contracts → chunk/embed → tenant-scoped retrieval → grounded agent answers with an honesty rule → gated legal-alert tool with human approval.]
- Laravel 11 (PHP 8.4), Docker
- Postgres + pgvector (vector(1536), cosine distance)
- laravel/ai SDK — LLM: gpt-5.4; embeddings: text-embedding-3-small
- Queue + cache: database driver
- Ingestion: [ContractChunker → embeddings → IngestContract job]
- Retrieval: tenant-scoped nearest-neighbour (filter before distance)
- Agent: ContractAnalyst — three-part prompt, answers only from context
- Tools: FlagHighValueContract, SendLegalAlert (approval-gated)
- Production: cost tracking, provider failover, semantic cache, tenant isolation
- Eval: harness + LLM-as-judge with keyword gating
- HITL: persisted conversations; SendLegalAlert requires human approve/reject/edit
[Verify against your actual docker-compose + .env.example:]
cp .env.example .envand set: OPENAI_API_KEY, ANTHROPIC_API_KEY, DB_*docker compose up -dphp artisan migrate- [ingestion command — verify the actual signature]
[Verify each command signature against app/Console/Commands:]
- Ask:
php artisan docupulse:ask "question" --tenant_id=1 - List approvals:
php artisan docupulse:approvals - Resolve:
php artisan docupulse:resolve <conv> <toolCall> approve|reject|edit - API:
POST /api/ask,GET /api/approvals,POST /api/approvals/resolve