GIVENALITY injects Tanzanian statute context into every chat turn via a fail-soft RAG helper
Two commits add a generic RAG injection layer -- env-gated, gracefully degrading -- that fetches Tanzanian legal context from GIVENALITY's Leksa corpus and prepends it to the LLM system prompt. The helper is portable; the system-prompt rewrites and seeded workflow templates are not.
The first commit (0c2eb990) puts a fetchLegalContext() call directly in projectChat.ts. On each turn it POSTs the latest user message to ${LEKSA_RAG_URL}/rag/retrieve, formats the returned chunks as a ## Tanzanian Legal Context markdown block, and appends it to the system prompt. The 5-second AbortSignal.timeout and a try/catch around the whole thing mean the chat proceeds normally if the RAG service is down or LEKSA_RAG_URL is unset.
The second commit (d5b14f75) lifts that function into backend/src/lib/leksaRag.ts and extends coverage to tabular.ts. The full-review SSE path fetches context once up-front from all column prompts concatenated, with topK = min(columns*3, 20), before SSE headers go out. The single-cell path calls fetchLegalContext per column prompt, which adds a 5-second timeout HTTP round-trip per cell for large reviews. The same commit also rewrites extraction system prompts to reference Tanzanian law and reframes flag values from "standard/favorable" to "compliant/non-compliant." A seedWorkflows.ts script adds four is_system=true tabular workflow templates (Employment Contract, SPA, Loan Agreement, Court Pleading) whose column prompts cite the Employment and Labour Relations Act 2004, the Limitation Act, BRELA, FCC, and Bank of Tanzania rate guidance.
Two import risks are worth flagging. The system-prompt rewrites -- "specialising in Tanzanian law," compliance/non-compliance flag framing -- are unconditional. Any deployment without LEKSA_RAG_URL set ends up with an analyst claiming Tanzanian expertise against a corpus it can't see. The per-cell fetchLegalContext call in queryTabularCell also adds latency at scale; a 30-column review would trigger 30 sequential RAG fetches at up to 5 seconds each.
The leksaRag.ts module itself is clean. To adapt it to a different corpus: set LEKSA_RAG_URL to your endpoint and confirm the response shape {chunks, sources, intent, language} matches.
Spotted something wrong? Or know the PR text has fresher detail than the writeup above?