# mohammed-kamran-ahmed/indicbns-simplify architecture

> Architecture diagram of the GitHub repository mohammed-kamran-ahmed/indicbns-simplify, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mohammed-kamran-ahmed/indicbns-simplify
- Repository: https://github.com/mohammed-kamran-ahmed/indicbns-simplify

## Overview

IndicBNS-Simplify is a multilingual legal-section retrieval and grounded-explanation prototype. Its main workflow turns the official BNS PDF into structured sections, indexes them for hybrid BM25 and BGE-M3 retrieval, and presents ranked provisions in Streamlit; users can then extract section and penalty entities and request a grounded explanation. The README also describes multilingual corpus support and query-based retrieval evaluation. Source excerpts show the UI and retrieval calls; unsampled subsystem links are omitted where their wiring is not established.

Main entry points: [`ui/app.py`](https://github.com/mohammed-kamran-ahmed/indicbns-simplify/blob/main/ui/app.py) (Streamlit interface), [`src/retriever.py`](https://github.com/mohammed-kamran-ahmed/indicbns-simplify/blob/main/src/retriever.py) (Hybrid retriever), [`src/build_index.py`](https://github.com/mohammed-kamran-ahmed/indicbns-simplify/blob/main/src/build_index.py) (Hybrid index builder), [`evaluation/evaluate.py`](https://github.com/mohammed-kamran-ahmed/indicbns-simplify/blob/main/evaluation/evaluate.py) (Retrieval evaluation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_corpus["Corpus preparation"]
  node_corpus_builder["PDF section extraction<br/>[build_corpus.py]"]
  node_sections["Structured sections<br/>[bns_sections.jsonl]"]
  node_multilingual_builder["Multilingual corpus builder"]
  node_multilingual_corpus["Multilingual corpus"]
end

subgraph group_retrieval["Index and retrieval"]
  node_index_builder["Hybrid index builder<br/>[build_index.py]"]
  node_embedding_config["Embedding configuration<br/>[config.py]"]
  node_index_artifacts[("Search index artifacts")]
  node_retriever["Hybrid retriever<br/>[retriever.py]"]
end

subgraph group_experience["User experience"]
  node_streamlit_ui["Streamlit interface<br/>[app.py]"]
  node_entity_extraction["Entity extraction<br/>[entities.py]"]
  node_grounded_explanation["Grounded explanation<br/>[generate.py]"]
end

subgraph group_evaluation["Retrieval evaluation"]
  node_evaluation_queries["Evaluation queries<br/>[queries.jsonl]"]
  node_evaluation_runner["Retrieval evaluation<br/>[evaluate.py]"]
  node_evaluation_metrics["Ranking metrics<br/>[metrics.py]"]
end

node_official_pdf["Official BNS PDF"]
node_user(("Legal questioner"))
node_openai["OpenAI API"]

node_official_pdf -->|"extracts from"| node_corpus_builder
node_corpus_builder -->|"writes sections"| node_sections
node_sections -->|"indexes corpus"| node_index_builder
node_index_builder -->|"loads model setting"| node_embedding_config
node_index_builder -->|"writes index"| node_index_artifacts
node_index_artifacts -->|"loads artifacts"| node_retriever
node_user -->|"asks question"| node_streamlit_ui
node_streamlit_ui -->|"searches query"| node_retriever
node_retriever -->|"returns ranked sections"| node_streamlit_ui
node_streamlit_ui -->|"extracts entities"| node_entity_extraction
node_streamlit_ui -->|"requests explanation"| node_grounded_explanation
node_grounded_explanation -->|"requests completion"| node_openai
node_evaluation_queries -->|"provides queries"| node_evaluation_runner
node_evaluation_runner -->|"runs searches"| node_retriever
node_evaluation_runner -->|"computes metrics"| node_evaluation_metrics

click node_corpus_builder "https://github.com/mohammed-kamran-ahmed/indicbns-simplify/blob/main/src/build_corpus.py"
click node_sections "https://github.com/mohammed-kamran-ahmed/indicbns-simplify/blob/main/data/processed/bns_sections.jsonl"
click node_multilingual_builder "https://github.com/mohammed-kamran-ahmed/indicbns-simplify/blob/main/src/build_multilingual_corpus.py"
click node_multilingual_corpus "https://github.com/mohammed-kamran-ahmed/indicbns-simplify/blob/main/data/processed/bns_multilingual.jsonl"
click node_index_builder "https://github.com/mohammed-kamran-ahmed/indicbns-simplify/blob/main/src/build_index.py"
click node_embedding_config "https://github.com/mohammed-kamran-ahmed/indicbns-simplify/blob/main/src/config.py"
click node_index_artifacts "https://github.com/mohammed-kamran-ahmed/indicbns-simplify/tree/main/artifacts/index_multilingual"
click node_retriever "https://github.com/mohammed-kamran-ahmed/indicbns-simplify/blob/main/src/retriever.py"
click node_streamlit_ui "https://github.com/mohammed-kamran-ahmed/indicbns-simplify/blob/main/ui/app.py"
click node_entity_extraction "https://github.com/mohammed-kamran-ahmed/indicbns-simplify/blob/main/src/entities.py"
click node_grounded_explanation "https://github.com/mohammed-kamran-ahmed/indicbns-simplify/blob/main/src/generate.py"
click node_evaluation_queries "https://github.com/mohammed-kamran-ahmed/indicbns-simplify/blob/main/data/processed/queries.jsonl"
click node_evaluation_runner "https://github.com/mohammed-kamran-ahmed/indicbns-simplify/blob/main/evaluation/evaluate.py"
click node_evaluation_metrics "https://github.com/mohammed-kamran-ahmed/indicbns-simplify/blob/main/evaluation/metrics.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_corpus_builder,node_sections,node_multilingual_builder,node_multilingual_corpus toneBlue
class node_index_builder,node_embedding_config,node_index_artifacts,node_retriever toneAmber
class node_streamlit_ui,node_entity_extraction,node_grounded_explanation,node_openai toneMint
class node_evaluation_queries,node_evaluation_runner,node_evaluation_metrics toneRose
class node_official_pdf,node_user toneIndigo
```

## Components

### Corpus preparation

- [PDF section extraction](https://github.com/mohammed-kamran-ahmed/indicbns-simplify/blob/main/src/build_corpus.py): `src/build_corpus.py`
- [Structured sections](https://github.com/mohammed-kamran-ahmed/indicbns-simplify/blob/main/data/processed/bns_sections.jsonl): `data/processed/bns_sections.jsonl`
- [Multilingual corpus builder](https://github.com/mohammed-kamran-ahmed/indicbns-simplify/blob/main/src/build_multilingual_corpus.py): `src/build_multilingual_corpus.py`
- [Multilingual corpus](https://github.com/mohammed-kamran-ahmed/indicbns-simplify/blob/main/data/processed/bns_multilingual.jsonl): `data/processed/bns_multilingual.jsonl`

### Index and retrieval

- [Hybrid index builder](https://github.com/mohammed-kamran-ahmed/indicbns-simplify/blob/main/src/build_index.py): `src/build_index.py`
- [Embedding configuration](https://github.com/mohammed-kamran-ahmed/indicbns-simplify/blob/main/src/config.py): `src/config.py`
- [Search index artifacts](https://github.com/mohammed-kamran-ahmed/indicbns-simplify/tree/main/artifacts/index_multilingual): `artifacts/index_multilingual`
- [Hybrid retriever](https://github.com/mohammed-kamran-ahmed/indicbns-simplify/blob/main/src/retriever.py): `src/retriever.py`

### User experience

- [Streamlit interface](https://github.com/mohammed-kamran-ahmed/indicbns-simplify/blob/main/ui/app.py): `ui/app.py`
- [Entity extraction](https://github.com/mohammed-kamran-ahmed/indicbns-simplify/blob/main/src/entities.py): `src/entities.py`
- [Grounded explanation](https://github.com/mohammed-kamran-ahmed/indicbns-simplify/blob/main/src/generate.py): `src/generate.py`

### Retrieval evaluation

- [Evaluation queries](https://github.com/mohammed-kamran-ahmed/indicbns-simplify/blob/main/data/processed/queries.jsonl): `data/processed/queries.jsonl`
- [Retrieval evaluation](https://github.com/mohammed-kamran-ahmed/indicbns-simplify/blob/main/evaluation/evaluate.py): `evaluation/evaluate.py`
- [Ranking metrics](https://github.com/mohammed-kamran-ahmed/indicbns-simplify/blob/main/evaluation/metrics.py): `evaluation/metrics.py`

### Other components

- **Official BNS PDF**
- **Legal questioner**
- **OpenAI API**

## Connections

- Official BNS PDF → PDF section extraction: extracts from (evidence: `README.md`)
- PDF section extraction → Structured sections: writes sections (evidence: `README.md`)
- Structured sections → Hybrid index builder: indexes corpus (evidence: `README.md`)
- Hybrid index builder → Embedding configuration: loads model setting (evidence: `src/build_index.py`)
- Hybrid index builder → Search index artifacts: writes index (evidence: `README.md`)
- Search index artifacts → Hybrid retriever: loads artifacts (evidence: `src/retriever.py`)
- Legal questioner → Streamlit interface: asks question (evidence: `ui/app.py`)
- Streamlit interface → Hybrid retriever: searches query (evidence: `ui/app.py`)
- Hybrid retriever → Streamlit interface: returns ranked sections (evidence: `ui/app.py`)
- Streamlit interface → Entity extraction: extracts entities (evidence: `ui/app.py`)
- Streamlit interface → Grounded explanation: requests explanation (evidence: `ui/app.py`)
- Grounded explanation → OpenAI API: requests completion (evidence: `src/generate.py`)
- Evaluation queries → Retrieval evaluation: provides queries (evidence: `README.md`)
- Retrieval evaluation → Hybrid retriever: runs searches (evidence: `evaluation/evaluate.py`)
- Retrieval evaluation → Ranking metrics: computes metrics (evidence: `evaluation/evaluate.py`)
