Inspiration

Navigating the Indian legal landscape is notoriously complex, especially with the recent transition from the IPC to the Bharatiya Nyaya Sanhita (BNS). Startups, small businesses, and everyday citizens often sign contracts filled with legal jargon, completely unaware if certain clauses violate Indian law or put them at risk. Hiring a corporate lawyer for every NDA, employment contract, or vendor agreement is expensive and slow.

We were inspired to build Nyaya Sahayak (by team Indiabricks) to democratize legal compliance. We wanted to create an AI-powered, highly accessible legal assistant that understands the nuances of Indian law, speaks your language, and doesn't just tell you what's wrong with a contract—but actively fixes it for you.

What it does

Nyaya Sahayak is a multimodal, full-stack Legal AI agent designed for the Indian legal ecosystem. It acts as a conversational legal assistant and a proactive contract auditor:

Multimodal Chat: Users can type or use voice notes (in Indian languages/English) to ask complex legal questions. The AI searches legal precedents and delivers highly accurate advice.

Automated Contract Auditing: Users upload a contract (PDF, DOCX, TXT). The system parses the document, isolates every single clause, and audits it in real-time against BNS/IPC laws.

Compliance Scoring: Clauses are visually flagged as SAFE (compliant), WARNING (gray area), or CRITICAL (illegal).

"Self-Healing" Documents: For problematic clauses, the AI instantly drafts a legally compliant alternative. Users can click "Accept Change" right in the UI, and the platform generates a brand-new, safely formatted PDF contract with the original illegal text struck through and replaced.

How we built it

We built Nyaya Sahayak using a powerful, enterprise-grade architecture anchored by the Databricks ecosystem and Sarvam AI:

Backend Vector Search via Databricks: We bypassed slow local embeddings by utilizing Spark SQL and Databricks Model Serving. We use ai_query pointing to databricks-gte-large-en to instantly generate high-quality vector embeddings.

Databricks Auto Loader: Implementing Auto Loader to seamlessly ingest new contracts dropped into our cloud storage directly into the vector database without manual triggers. We also implemented a web scraper to continuously update our database with newly updated laws. 

MLOps & Observability: Because legal tech requires strict auditability, we deeply integrated Databricks MLflow. Every step of the pipeline—from transcription to vector retrieval to generation—is wrapped in @mlflow.trace for real-time monitoring of latency, token usage, and pipeline health.

LLM & Voice Engine: We leveraged the Sarvam AI API (saaras:v1 for speech-to-text and sarvam-m for generation) because it is specifically optimized for Indian contexts and legal nuances.

Advanced RAG Pipeline: We implemented a two-stage retrieval process. After Databricks handles the semantic search, we use a local BAAI/bge-reranker-v2-m3 Cross-Encoder to rerank the top chunks, ensuring zero hallucinations and absolute precision.

Frontend & Document Processing: The sleek UI was built in Gradio, with pymupdf4llm for clean Markdown extraction from documents and ReportLab to dynamically compile the final "healed" PDFs.

Challenges we ran into

Taming the LLM for Strict JSON: In our auditing pipeline, the LLM needed to evaluate a clause and return only a strictly formatted JSON verdict (SAFE/WARNING/CRITICAL, reason, law section). Forcing the model to output valid JSON without conversational preamble required heavy prompt engineering and robust Regex fallback parsing.

High-Speed Vector Math: Computing cosine similarity/dot products for active user sessions in real-time could easily bottleneck. We overcame this by loading the Databricks embeddings into a highly optimized, in-memory NumPy matrix (np.dot), achieving lightning-fast retrievals without waiting for database round-trips.

Nuances of Indian Law: Ensuring the AI correctly differentiated between the old IPC and the new BNS guidelines required carefully curating the vector database and tweaking the Cross-Encoder top-K parameters so only the most up-to-date precedents were fed to the LLM.

Accomplishments that we're proud of

The "Self-Healing" PDF Engine: Getting the UI to stream clause-by-clause analysis, allowing the user to seamlessly accept AI rewrites, and then dynamically compiling a beautifully formatted, color-coded PDF using ReportLab is a massive technical win.

Enterprise-Grade Tracing: Successfully wrapping our entire complex, multi-API pipeline (Audio -> Databricks RAG -> BGE Rerank -> Sarvam LLM) into clean, observable MLflow traces. We built a prototype that is genuinely ready for production scaling.

A Fluid Multimodal UI: Making a dense subject like legal auditing feel incredibly intuitive and visual for a non-technical end user.

What we learned

Reranking is Non-Negotiable in Legal RAG: Standard semantic search isn't enough for the law. We learned that injecting a Cross-Encoder step drastically improved the quality of the context fed to the LLM, reducing false positives in clause auditing.

Databricks simplifies AI Infrastructure: Using ai_query within Spark SQL completely changed how we viewed embedding pipelines. It allowed us to treat AI models like standard database queries, simplifying our architecture immensely.

What's next for indiabricks

Databricks Vector Search Migration: We plan to migrate our current in-memory NumPy index into a fully managed, serverless Databricks Vector Search index to support thousands of massive legal documents.

Regional Language Contracts: Utilizing Sarvam AI to translate and audit legal documents entirely in Hindi, Tamil, Telugu, and other regional languages.

Built With

Share this project:

Updates