The challenge
Legal researchers working across statutes and court judgments need exact statutory wording and relevant precedent before they can assess a question. Generic chatbots rely on model memory, miss jurisdiction-specific phrasing, and lose track of follow-up questions.
What we built
We engineered a multi-stage Arabic RAG pipeline paired with session-managed API endpoints. Incoming questions—including conversational follow-ups—are rewritten into precise legal search queries before retrieving relevant laws and judgments.
Responses are synthesized directly from the retrieved legal text, while session endpoints maintain research context cleanly and let users reset state whenever they move to a new matter.
Handling legal phrasing & follow-ups
In Arabic legal research, everyday phrasing in a user’s question often differs from formal statutory terminology. Adding dedicated query rewriting before retrieval bridged that gap and kept follow-up questions anchored to the right legal context.
How it helps researchers
Researchers reach relevant articles and rulings in seconds and explore follow-up angles naturally—grounded in actual legal texts rather than unverified model recall.
System architecture
Core engineering modules
- Context-aware query rewriting
- Translates conversational and follow-up Arabic questions into precise search queries tuned for legal text.
- Statute & judgment retrieval
- Searches indexed laws and court decisions to pull relevant legal passages into context before generation.
- Source-grounded answers
- Generates responses anchored to retrieved legal material instead of relying on general model memory.
- Managed research sessions
- API endpoints preserve multi-turn conversation history per matter with clean session reset controls.
Lessons from the build
Key engineering & product takeaways
- Query rewriting is essential when everyday user questions meet formal legal or technical terminology.
- Multi-turn RAG fails unless follow-up questions rewrite cleanly against conversation history before searching.
- Grounding every answer in retrieved statutes keeps specialist tools focused and dependable.
- Clean session boundaries prevent context bleed when researchers switch from one case to the next.

