# rimil11/legal-rag architecture

> Architecture diagram of the GitHub repository rimil11/legal-rag, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rimil11/legal-rag
- Repository: https://github.com/rimil11/legal-rag

## Overview

Legal RAG AI Assistant lets users ask natural-language questions about Indian legal documents and returns streamed, document-grounded answers with source/page references and PDF links. The documented flow covers loading PDF/TXT files, chunking, embedding and indexing, then query retrieval, reranking, context construction, and LLM generation. The graph uses the README for the documented pipeline and capabilities; omitted source excerpts limit certainty about some internal wiring.

Main entry points: [`retrieval_pipeline.py`](https://github.com/rimil11/legal-rag/blob/main/retrieval_pipeline.py) (Question orchestration), [`app.py`](https://github.com/rimil11/legal-rag/blob/main/app.py) (Streamlit chat), [`ingestion_pipeline.py`](https://github.com/rimil11/legal-rag/blob/main/ingestion_pipeline.py) (Passage embedding), [`db/chroma_db`](https://github.com/rimil11/legal-rag/tree/main/db/chroma_db) (Chroma vector store)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interface"]
  node_app["Streamlit chat<br/>[app.py]"]
end

subgraph group_ingestion["Document ingestion"]
  node_legal_docs["Legal PDF/TXT"]
  node_load["Document loading"]
  node_split["Text chunking"]
  node_ingest_embed["Passage embedding"]
  node_index["Vector indexing"]
end

subgraph group_retrieval["RAG retrieval"]
  node_chroma[("Chroma vector store")]
  node_ask["Question orchestration"]
  node_query_embed["Query embedding"]
  node_search["Similarity search"]
  node_rerank["Result reranking"]
  node_context["Context and citations"]
  node_generation["Answer generation"]
end

subgraph group_services["External services"]
  node_jina_embed{{"Jina embeddings"}}
  node_jina_rank{{"Jina reranker"}}
  node_groq{{"Groq LLM"}}
  node_pdf_viewer{{"PDF.js viewer"}}
  node_github_docs{{"GitHub raw PDFs"}}
end

node_user(("Legal questioner"))

node_user -->|"asks question"| node_app
node_app -->|"calls"| node_ask
node_legal_docs -->|"loads files"| node_load
node_load -->|"returns documents"| node_split
node_split -->|"embeds chunks"| node_ingest_embed
node_ingest_embed -->|"requests embeddings"| node_jina_embed
node_ingest_embed -->|"returns vectors"| node_index
node_index -->|"writes vectors"| node_chroma
node_ask -->|"embeds query"| node_query_embed
node_query_embed -->|"requests embedding"| node_jina_embed
node_ask -->|"searches store"| node_search
node_search -->|"reads top 20"| node_chroma
node_ask -->|"reranks results"| node_rerank
node_rerank -->|"requests ranking"| node_jina_rank
node_ask -->|"builds context"| node_context
node_ask -->|"generates answer"| node_generation
node_generation -->|"streams completion"| node_groq
node_ask -->|"returns stream and sources"| node_app
node_app -.->|"opens source page"| node_pdf_viewer
node_pdf_viewer -.->|"loads PDF"| node_github_docs

click node_app "https://github.com/rimil11/legal-rag/blob/main/app.py"
click node_legal_docs "https://github.com/rimil11/legal-rag/tree/main/docs"
click node_load "https://github.com/rimil11/legal-rag/blob/main/ingestion_pipeline.py"
click node_split "https://github.com/rimil11/legal-rag/blob/main/ingestion_pipeline.py"
click node_ingest_embed "https://github.com/rimil11/legal-rag/blob/main/ingestion_pipeline.py"
click node_index "https://github.com/rimil11/legal-rag/blob/main/ingestion_pipeline.py"
click node_chroma "https://github.com/rimil11/legal-rag/tree/main/db/chroma_db"
click node_ask "https://github.com/rimil11/legal-rag/blob/main/retrieval_pipeline.py"
click node_query_embed "https://github.com/rimil11/legal-rag/blob/main/retrieval_pipeline.py"
click node_search "https://github.com/rimil11/legal-rag/blob/main/retrieval_pipeline.py"
click node_rerank "https://github.com/rimil11/legal-rag/blob/main/retrieval_pipeline.py"
click node_context "https://github.com/rimil11/legal-rag/blob/main/retrieval_pipeline.py"
click node_generation "https://github.com/rimil11/legal-rag/blob/main/retrieval_pipeline.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app toneBlue
class node_legal_docs,node_load,node_split,node_ingest_embed,node_index toneAmber
class node_chroma,node_ask,node_query_embed,node_search,node_rerank,node_context,node_generation toneMint
class node_jina_embed,node_jina_rank,node_groq,node_pdf_viewer,node_github_docs toneRose
class node_user toneIndigo
```

## Components

### User interface

- [Streamlit chat](https://github.com/rimil11/legal-rag/blob/main/app.py): `app.py`

### Document ingestion

- [Legal PDF/TXT](https://github.com/rimil11/legal-rag/tree/main/docs): `docs`
- [Document loading](https://github.com/rimil11/legal-rag/blob/main/ingestion_pipeline.py): `ingestion_pipeline.py`
- [Text chunking](https://github.com/rimil11/legal-rag/blob/main/ingestion_pipeline.py): `ingestion_pipeline.py`
- [Passage embedding](https://github.com/rimil11/legal-rag/blob/main/ingestion_pipeline.py): `ingestion_pipeline.py`
- [Vector indexing](https://github.com/rimil11/legal-rag/blob/main/ingestion_pipeline.py): `ingestion_pipeline.py`

### RAG retrieval

- [Chroma vector store](https://github.com/rimil11/legal-rag/tree/main/db/chroma_db): `db/chroma_db`
- [Question orchestration](https://github.com/rimil11/legal-rag/blob/main/retrieval_pipeline.py): `retrieval_pipeline.py`
- [Query embedding](https://github.com/rimil11/legal-rag/blob/main/retrieval_pipeline.py): `retrieval_pipeline.py`
- [Similarity search](https://github.com/rimil11/legal-rag/blob/main/retrieval_pipeline.py): `retrieval_pipeline.py`
- [Result reranking](https://github.com/rimil11/legal-rag/blob/main/retrieval_pipeline.py): `retrieval_pipeline.py`
- [Context and citations](https://github.com/rimil11/legal-rag/blob/main/retrieval_pipeline.py): `retrieval_pipeline.py`
- [Answer generation](https://github.com/rimil11/legal-rag/blob/main/retrieval_pipeline.py): `retrieval_pipeline.py`

### External services

- **Jina embeddings**
- **Jina reranker**
- **Groq LLM**
- **PDF.js viewer**
- **GitHub raw PDFs**

### Other components

- **Legal questioner**

## Connections

- Legal questioner → Streamlit chat: asks question
- Streamlit chat → Question orchestration: calls
- Legal PDF/TXT → Document loading: loads files
- Document loading → Text chunking: returns documents
- Text chunking → Passage embedding: embeds chunks
- Passage embedding → Jina embeddings: requests embeddings
- Passage embedding → Vector indexing: returns vectors
- Vector indexing → Chroma vector store: writes vectors
- Question orchestration → Query embedding: embeds query
- Query embedding → Jina embeddings: requests embedding
- Question orchestration → Similarity search: searches store
- Similarity search → Chroma vector store: reads top 20
- Question orchestration → Result reranking: reranks results
- Result reranking → Jina reranker: requests ranking
- Question orchestration → Context and citations: builds context
- Question orchestration → Answer generation: generates answer
- Answer generation → Groq LLM: streams completion
- Question orchestration → Streamlit chat: returns stream and sources
- Streamlit chat → PDF.js viewer: opens source page
- PDF.js viewer → GitHub raw PDFs: loads PDF
