# arunkumar-201/judicial_rag_bot architecture

> Architecture diagram of the GitHub repository arunkumar-201/judicial_rag_bot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/arunkumar-201/judicial_rag_bot
- Repository: https://github.com/arunkumar-201/judicial_rag_bot

## Overview

This is a Streamlit assistant for explaining court procedures from legal documents. Users can upload TXT/PDF files for ingestion, or use the bundled court document; they ask a question and receive an answer with retrieved source snippets. Ingestion extracts and chunks text, embeds it, and persists a FAISS index and document store. The answering path validates the query, retrieves matching chunks, applies an optional category filter, then generates an explanation using Gemini when a key is supplied or the local FLAN-T5 model otherwise. Source excerpts show the main calls; unsampled document and vector-store contents are treated only as data.

Main entry points: [`rag.py`](https://github.com/arunkumar-201/judicial_rag_bot/blob/main/rag.py) (Answer orchestration), [`app.py`](https://github.com/arunkumar-201/judicial_rag_bot/blob/main/app.py) (Streamlit chat and uploads), [`ingest.py`](https://github.com/arunkumar-201/judicial_rag_bot/blob/main/ingest.py) (File ingestion), [`vectorstore/index.faiss`](https://github.com/arunkumar-201/judicial_rag_bot/blob/main/vectorstore/index.faiss) (FAISS index and documents)

## Diagram (Mermaid)

```mermaid
flowchart TD

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

subgraph group_ingestion["Document ingestion"]
  node_ingest_file["File ingestion<br/>[ingest.py]"]
  node_text_extract["TXT/PDF extraction<br/>[ingest.py]"]
  node_chunk_embed["Chunk and embed<br/>[ingest.py]"]
  node_default_docs["Bundled court text<br/>[court_docs.txt]"]
end

subgraph group_answering["Question answering"]
  node_answer_flow["Answer orchestration<br/>[rag.py]"]
  node_query_filter["Judicial query validation<br/>[rag.py]"]
  node_semantic_retrieval["Semantic retrieval and filtering<br/>[rag.py]"]
  node_answer_generation["Explanation generation<br/>[rag.py]"]
end

subgraph group_knowledge["Knowledge store"]
  node_vector_store[("FAISS index and documents<br/>[index.faiss]")]
end

node_user(("User"))
node_embedding_model{{"Sentence Transformer"}}
node_local_model{{"Local FLAN-T5"}}
node_gemini{{"Gemini API"}}

node_user -->|"asks or uploads"| node_app
node_app -->|"ingests uploads"| node_ingest_file
node_app -->|"initializes defaults"| node_ingest_file
node_ingest_file -->|"extracts text"| node_text_extract
node_text_extract -->|"chunks text"| node_chunk_embed
node_chunk_embed -->|"encodes chunks"| node_embedding_model
node_ingest_file -->|"reads default file"| node_default_docs
node_chunk_embed -->|"writes embeddings and chunks"| node_vector_store
node_app -->|"submits question"| node_answer_flow
node_answer_flow -->|"validates query"| node_query_filter
node_answer_flow -->|"retrieves context"| node_semantic_retrieval
node_semantic_retrieval -->|"encodes query"| node_embedding_model
node_semantic_retrieval -->|"searches index and reads documents"| node_vector_store
node_answer_flow -->|"generates response"| node_answer_generation
node_answer_generation -->|"uses local model"| node_local_model
node_answer_generation -.->|"uses keyed API"| node_gemini
node_answer_flow -->|"returns answer and sources"| node_app

click node_app "https://github.com/arunkumar-201/judicial_rag_bot/blob/main/app.py"
click node_ingest_file "https://github.com/arunkumar-201/judicial_rag_bot/blob/main/ingest.py"
click node_text_extract "https://github.com/arunkumar-201/judicial_rag_bot/blob/main/ingest.py"
click node_chunk_embed "https://github.com/arunkumar-201/judicial_rag_bot/blob/main/ingest.py"
click node_default_docs "https://github.com/arunkumar-201/judicial_rag_bot/blob/main/data/court_docs.txt"
click node_vector_store "https://github.com/arunkumar-201/judicial_rag_bot/blob/main/vectorstore/index.faiss"
click node_answer_flow "https://github.com/arunkumar-201/judicial_rag_bot/blob/main/rag.py"
click node_query_filter "https://github.com/arunkumar-201/judicial_rag_bot/blob/main/rag.py"
click node_semantic_retrieval "https://github.com/arunkumar-201/judicial_rag_bot/blob/main/rag.py"
click node_answer_generation "https://github.com/arunkumar-201/judicial_rag_bot/blob/main/rag.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,node_user toneBlue
class node_ingest_file,node_text_extract,node_chunk_embed,node_default_docs toneAmber
class node_answer_flow,node_query_filter,node_semantic_retrieval,node_answer_generation,node_gemini toneMint
class node_vector_store toneRose
class node_embedding_model,node_local_model toneIndigo
```

## Components

### User interface

- [Streamlit chat and uploads](https://github.com/arunkumar-201/judicial_rag_bot/blob/main/app.py): `app.py`

### Document ingestion

- [File ingestion](https://github.com/arunkumar-201/judicial_rag_bot/blob/main/ingest.py): `ingest.py`
- [TXT/PDF extraction](https://github.com/arunkumar-201/judicial_rag_bot/blob/main/ingest.py): `ingest.py`
- [Chunk and embed](https://github.com/arunkumar-201/judicial_rag_bot/blob/main/ingest.py): `ingest.py`
- [Bundled court text](https://github.com/arunkumar-201/judicial_rag_bot/blob/main/data/court_docs.txt): `data/court_docs.txt`

### Question answering

- [Answer orchestration](https://github.com/arunkumar-201/judicial_rag_bot/blob/main/rag.py): `rag.py`
- [Judicial query validation](https://github.com/arunkumar-201/judicial_rag_bot/blob/main/rag.py): `rag.py`
- [Semantic retrieval and filtering](https://github.com/arunkumar-201/judicial_rag_bot/blob/main/rag.py): `rag.py`
- [Explanation generation](https://github.com/arunkumar-201/judicial_rag_bot/blob/main/rag.py): `rag.py`

### Knowledge store

- [FAISS index and documents](https://github.com/arunkumar-201/judicial_rag_bot/blob/main/vectorstore/index.faiss): `vectorstore/index.faiss`

### Other components

- **User**
- **Sentence Transformer**
- **Local FLAN-T5**
- **Gemini API**

## Connections

- User → Streamlit chat and uploads: asks or uploads (evidence: `app.py`)
- Streamlit chat and uploads → File ingestion: ingests uploads (evidence: `app.py`)
- Streamlit chat and uploads → File ingestion: initializes defaults (evidence: `app.py`)
- File ingestion → TXT/PDF extraction: extracts text (evidence: `ingest.py`)
- TXT/PDF extraction → Chunk and embed: chunks text (evidence: `ingest.py`)
- Chunk and embed → Sentence Transformer: encodes chunks (evidence: `ingest.py`)
- File ingestion → Bundled court text: reads default file (evidence: `ingest.py`)
- Chunk and embed → FAISS index and documents: writes embeddings and chunks (evidence: `ingest.py`)
- Streamlit chat and uploads → Answer orchestration: submits question (evidence: `app.py`)
- Answer orchestration → Judicial query validation: validates query (evidence: `rag.py`)
- Answer orchestration → Semantic retrieval and filtering: retrieves context (evidence: `rag.py`)
- Semantic retrieval and filtering → Sentence Transformer: encodes query (evidence: `rag.py`)
- Semantic retrieval and filtering → FAISS index and documents: searches index and reads documents (evidence: `rag.py`)
- Answer orchestration → Explanation generation: generates response (evidence: `rag.py`)
- Explanation generation → Local FLAN-T5: uses local model (evidence: `rag.py`)
- Explanation generation → Gemini API: uses keyed API (evidence: `rag.py`)
- Answer orchestration → Streamlit chat and uploads: returns answer and sources (evidence: `app.py`)
