All projects

AI systemsCase study

Legiflow

AI for legal documents: lawyers upload case files and ask questions that are answered only from that case, with citations.

Role
Associate Software Engineer, Devsarch
Stack
FastAPI · Gemini · Next.js
IngestAskCase filesWasabi / S3Extractentities · structureChunk+ embedPostgreSQLchunks + metadataQuestionfrom the lawyerScoped retrievalrestricted to one case fileno cross-case leakageGeminianswer + citationNext.jsUIAnswers can only come from the case file in scope — the constraint is the product.

Hover or tap a box to see what it does, or press play.

The problem

Lawyers were reviewing case documents by hand. A chatbot could speed that up, but only if it never mixed one case with another: an answer drawn from the wrong case file is worse than no answer at all. So the hard requirement was that a question could only ever be answered from the case file in scope.

What I built

  • Entity extraction that pulls the structure out of each document into structured storage
  • Chunking and embeddings stored in PostgreSQL, every chunk tagged with its case file
  • Retrieval scoped to a single case file, so no passage from another case can reach the answer
  • Answers written by Gemini from the retrieved passages, each with a citation the lawyer can check
  • A FastAPI backend, a Next.js app for lawyers, and case files in Wasabi or S3 storage

How it works

  1. Case files arrive from Wasabi or S3.
  2. Entities and structure are extracted from each document.
  3. The text is split into chunks and embedded.
  4. Chunks are stored in PostgreSQL, each tagged with its case file.
  5. A lawyer asks a question about one case.
  6. Retrieval searches only that case file's chunks.
  7. Gemini answers from those chunks alone, with a citation.
  8. The answer and its citation appear in the app.
  9. Nothing outside the case file can reach the answer.

Results

  • Reduced manual review time by 40%
  • Processes 1,000+ PDFs a month
  • Every answer cites its source in the case file, so it can be verified instead of trusted

More on this in the note Keeping a RAG chatbot inside one case file.