# s-md-ahmed/langchaintextrag architecture

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

- Interactive diagram: https://gitdiagram.com/s-md-ahmed/langchaintextrag
- Repository: https://github.com/s-md-ahmed/langchaintextrag

## Overview

This is a Streamlit PDF question-answering app. A user uploads a text-based PDF; the app extracts and chunks its pages, builds dense and keyword indexes, combines retrieval results, expands matches to full pages, and asks Groq to answer from that context. The main workflow and its components are all implemented in main.py. The graph separates indexing from query-time retrieval and answer generation; external users and the Groq model are shown separately.

Main entry points: [`main.py`](https://github.com/s-md-ahmed/langchaintextrag/blob/main/main.py) (Streamlit app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interface"]
  node_app["Streamlit app<br/>[main.py]"]
  node_response["Answer display<br/>[main.py]"]
end

subgraph group_indexing["Document indexing"]
  node_pdf["PDF extraction<br/>[main.py]"]
  node_chunking["Page chunking<br/>[main.py]"]
  node_embedder["Embedding model<br/>[main.py]"]
  node_chroma[("Chroma vector index<br/>[main.py]")]
  node_bm25["BM25 index<br/>[main.py]"]
end

subgraph group_answering["Retrieval and answers"]
  node_retrieval["Hybrid retrieval<br/>[main.py]"]
  node_expansion["Page expansion<br/>[main.py]"]
  node_groq["Groq model"]
end

node_user(("User"))

node_user -->|"uploads PDF"| node_app
node_app -->|"reads PDF"| node_pdf
node_pdf -->|"provides pages"| node_chunking
node_app -->|"loads model"| node_embedder
node_app -->|"builds index"| node_chroma
node_app -->|"builds index"| node_bm25
node_chunking -->|"supplies chunks"| node_chroma
node_chunking -->|"supplies chunks"| node_bm25
node_user -->|"asks question"| node_app
node_app -->|"invokes retrievers"| node_retrieval
node_retrieval -->|"searches vectors"| node_chroma
node_retrieval -->|"searches keywords"| node_bm25
node_app -->|"expands matched pages"| node_expansion
node_retrieval -->|"provides matches"| node_expansion
node_app -->|"submits prompt"| node_groq
node_expansion -->|"provides context"| node_groq
node_groq -->|"returns answer"| node_response
node_response -->|"shows answer"| node_user

click node_app "https://github.com/s-md-ahmed/langchaintextrag/blob/main/main.py"
click node_pdf "https://github.com/s-md-ahmed/langchaintextrag/blob/main/main.py"
click node_chunking "https://github.com/s-md-ahmed/langchaintextrag/blob/main/main.py"
click node_embedder "https://github.com/s-md-ahmed/langchaintextrag/blob/main/main.py"
click node_chroma "https://github.com/s-md-ahmed/langchaintextrag/blob/main/main.py"
click node_bm25 "https://github.com/s-md-ahmed/langchaintextrag/blob/main/main.py"
click node_retrieval "https://github.com/s-md-ahmed/langchaintextrag/blob/main/main.py"
click node_expansion "https://github.com/s-md-ahmed/langchaintextrag/blob/main/main.py"
click node_response "https://github.com/s-md-ahmed/langchaintextrag/blob/main/main.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_response,node_user toneBlue
class node_pdf,node_chunking,node_embedder,node_chroma,node_bm25 toneAmber
class node_retrieval,node_expansion,node_groq toneMint
```

## Components

### User interface

- [Streamlit app](https://github.com/s-md-ahmed/langchaintextrag/blob/main/main.py): `main.py`
- [Answer display](https://github.com/s-md-ahmed/langchaintextrag/blob/main/main.py): `main.py`

### Document indexing

- [PDF extraction](https://github.com/s-md-ahmed/langchaintextrag/blob/main/main.py): `main.py`
- [Page chunking](https://github.com/s-md-ahmed/langchaintextrag/blob/main/main.py): `main.py`
- [Embedding model](https://github.com/s-md-ahmed/langchaintextrag/blob/main/main.py): `main.py`
- [Chroma vector index](https://github.com/s-md-ahmed/langchaintextrag/blob/main/main.py): `main.py`
- [BM25 index](https://github.com/s-md-ahmed/langchaintextrag/blob/main/main.py): `main.py`

### Retrieval and answers

- [Hybrid retrieval](https://github.com/s-md-ahmed/langchaintextrag/blob/main/main.py): `main.py`
- [Page expansion](https://github.com/s-md-ahmed/langchaintextrag/blob/main/main.py): `main.py`
- **Groq model**

### Other components

- **User**

## Connections

- User → Streamlit app: uploads PDF (evidence: `main.py`)
- Streamlit app → PDF extraction: reads PDF (evidence: `main.py`)
- PDF extraction → Page chunking: provides pages (evidence: `main.py`)
- Streamlit app → Embedding model: loads model (evidence: `main.py`)
- Streamlit app → Chroma vector index: builds index (evidence: `main.py`)
- Streamlit app → BM25 index: builds index (evidence: `main.py`)
- Page chunking → Chroma vector index: supplies chunks (evidence: `main.py`)
- Page chunking → BM25 index: supplies chunks (evidence: `main.py`)
- User → Streamlit app: asks question (evidence: `main.py`)
- Streamlit app → Hybrid retrieval: invokes retrievers (evidence: `main.py`)
- Hybrid retrieval → Chroma vector index: searches vectors (evidence: `main.py`)
- Hybrid retrieval → BM25 index: searches keywords (evidence: `main.py`)
- Streamlit app → Page expansion: expands matched pages (evidence: `main.py`)
- Hybrid retrieval → Page expansion: provides matches (evidence: `main.py`)
- Streamlit app → Groq model: submits prompt (evidence: `main.py`)
- Page expansion → Groq model: provides context (evidence: `main.py`)
- Groq model → Answer display: returns answer (evidence: `main.py`)
- Answer display → User: shows answer (evidence: `main.py`)
