Overview

A RAG system that chunks legal documents, stores embeddings in PostgreSQL (pgvector), retrieves relevant clauses via cosine similarity, and generates cited LLM answers grounded only in uploaded contracts.

Role
AI / backend engineer
Team
Solo developer
Timeline
Featured work
My contribution
Built the RAG pipeline from chunking and embeddings through cited LLM answers.

Problem

Long contracts make clause lookup slow, and generic LLM answers invent details that are not in the document.

  • Accurate clause retrieval across long legal documents
  • Preventing hallucinated answers outside source contracts
  • Efficient embedding and search at document scale

Product

Upload an agreement, ask a question, and get an answer that points back to the clauses it used.

  • Legal document chunking and embedding pipeline
  • pgvector storage with cosine similarity retrieval
  • Cited LLM answers grounded in uploaded contracts
  • Contract Q&A interface for legal agreement review

Approach

Retrieval quality came first. The model only answers from retrieved context, and every response expects citations.

  • Structured chunking with pgvector cosine similarity search
  • Citation-required LLM responses limited to retrieved context
  • FastAPI backend for scalable document ingestion and querying

What changed

Contract review becomes a grounded Q&A loop instead of scrolling for the right clause or trusting an uncited answer.

Stack

Python, FastAPI, PostgreSQL, pgvector, and LLM APIs.

PythonFastAPIPostgreSQLpgvectorLLM APIs

More projects

Explore other work in the portfolio

View all