# mohamad-hachem/rag_langchain architecture

> Architecture diagram of the GitHub repository mohamad-hachem/rag_langchain, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mohamad-hachem/rag_langchain
- Repository: https://github.com/mohamad-hachem/rag_langchain

## Overview

This is a compact agentic RAG document assistant with two entry points: an interactive Streamlit app that indexes uploaded files per session, and a fixed-corpus example over sample PDFs. Both workflows prepare chunks for semantic retrieval, save retrieved passages for specialist analysis, and synthesize answers. The README documents the overall retrieval and delegation flow; some implementation excerpts are partial, so uncertain internal links are omitted.

Main entry points: [`main.py`](https://github.com/mohamad-hachem/rag_langchain/blob/main/main.py) (Session coordinator), [`agent.py`](https://github.com/mohamad-hachem/rag_langchain/blob/main/agent.py) (Example coordinator), [`indexing.py`](https://github.com/mohamad-hachem/rag_langchain/blob/main/indexing.py) (Fixed-corpus index), [`tools.py`](https://github.com/mohamad-hachem/rag_langchain/blob/main/tools.py) (Search tool)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Interactive app"]
  node_streamlit["Chat interface<br/>[main.py]"]
  node_upload_parse["Upload parser<br/>[main.py]"]
end

subgraph group_prep["Document preparation"]
  node_session_index["Session indexing<br/>[main.py]"]
  node_session_vectors[("Session vector store<br/>[main.py]")]
end

subgraph group_agent["Agent workflow"]
  node_session_agent["Session coordinator<br/>[main.py]"]
  node_session_search["Search tool<br/>[main.py]"]
  node_session_files[("Retrieved passages<br/>[main.py]")]
  node_prompts["Workflow prompts<br/>[prompts.py]"]
  node_analyst["Chunk analyst<br/>[main.py]"]
end

subgraph group_example["Fixed corpus"]
  node_sample_pdfs["Sample PDF corpus"]
  node_pdf_reader["PDF reader<br/>[filereader.py]"]
  node_fixed_index[("Fixed-corpus index<br/>[indexing.py]")]
  node_fixed_search["Search tool<br/>[tools.py]"]
  node_fixed_files[("Retrieved passages<br/>[tools.py]")]
  node_fixed_agent["Example coordinator<br/>[agent.py]"]
end

node_user(("Document user"))
node_openai_embed{{"OpenAI embeddings"}}
node_openai_chat{{"OpenAI chat model"}}

node_user -->|"uploads, asks"| node_streamlit
node_streamlit -->|"processes files"| node_upload_parse
node_upload_parse -->|"provides documents"| node_session_index
node_session_index -->|"indexes chunks"| node_session_vectors
node_session_index -->|"embeds chunks"| node_openai_embed
node_streamlit -->|"invokes question"| node_session_agent
node_session_agent -->|"calls retrieval"| node_session_search
node_session_search -->|"searches vectors"| node_session_vectors
node_session_search -->|"saves passages"| node_session_files
node_session_agent -->|"uses instructions"| node_prompts
node_session_agent -->|"delegates analysis"| node_analyst
node_analyst -->|"reads passages"| node_session_files
node_session_agent -->|"synthesizes answer"| node_openai_chat
node_sample_pdfs -->|"provides PDFs"| node_pdf_reader
node_pdf_reader -->|"returns documents"| node_fixed_index
node_fixed_index -->|"embeds chunks"| node_openai_embed
node_fixed_index -->|"supplies index"| node_fixed_search
node_fixed_agent -->|"calls retrieval"| node_fixed_search
node_fixed_search -->|"searches vectors"| node_fixed_index
node_fixed_search -->|"saves passages"| node_fixed_files
node_fixed_agent -->|"uses instructions"| node_prompts
node_fixed_agent -->|"delegates analysis"| node_analyst
node_fixed_agent -->|"synthesizes answer"| node_openai_chat

click node_streamlit "https://github.com/mohamad-hachem/rag_langchain/blob/main/main.py"
click node_upload_parse "https://github.com/mohamad-hachem/rag_langchain/blob/main/main.py"
click node_session_index "https://github.com/mohamad-hachem/rag_langchain/blob/main/main.py"
click node_session_vectors "https://github.com/mohamad-hachem/rag_langchain/blob/main/main.py"
click node_session_agent "https://github.com/mohamad-hachem/rag_langchain/blob/main/main.py"
click node_session_search "https://github.com/mohamad-hachem/rag_langchain/blob/main/main.py"
click node_session_files "https://github.com/mohamad-hachem/rag_langchain/blob/main/main.py"
click node_prompts "https://github.com/mohamad-hachem/rag_langchain/blob/main/prompts.py"
click node_analyst "https://github.com/mohamad-hachem/rag_langchain/blob/main/main.py"
click node_sample_pdfs "https://github.com/mohamad-hachem/rag_langchain/tree/main/pdfs"
click node_pdf_reader "https://github.com/mohamad-hachem/rag_langchain/blob/main/filereader.py"
click node_fixed_index "https://github.com/mohamad-hachem/rag_langchain/blob/main/indexing.py"
click node_fixed_search "https://github.com/mohamad-hachem/rag_langchain/blob/main/tools.py"
click node_fixed_files "https://github.com/mohamad-hachem/rag_langchain/blob/main/tools.py"
click node_fixed_agent "https://github.com/mohamad-hachem/rag_langchain/blob/main/agent.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_streamlit,node_upload_parse,node_user toneBlue
class node_session_index,node_session_vectors toneAmber
class node_session_agent,node_session_search,node_session_files,node_prompts,node_analyst toneMint
class node_sample_pdfs,node_pdf_reader,node_fixed_index,node_fixed_search,node_fixed_files,node_fixed_agent toneRose
class node_openai_embed,node_openai_chat toneIndigo
```

## Components

### Interactive app

- [Chat interface](https://github.com/mohamad-hachem/rag_langchain/blob/main/main.py): `main.py`
- [Upload parser](https://github.com/mohamad-hachem/rag_langchain/blob/main/main.py): `main.py`

### Document preparation

- [Session indexing](https://github.com/mohamad-hachem/rag_langchain/blob/main/main.py): `main.py`
- [Session vector store](https://github.com/mohamad-hachem/rag_langchain/blob/main/main.py): `main.py`

### Agent workflow

- [Session coordinator](https://github.com/mohamad-hachem/rag_langchain/blob/main/main.py): `main.py`
- [Search tool](https://github.com/mohamad-hachem/rag_langchain/blob/main/main.py): `main.py`
- [Retrieved passages](https://github.com/mohamad-hachem/rag_langchain/blob/main/main.py): `main.py`
- [Workflow prompts](https://github.com/mohamad-hachem/rag_langchain/blob/main/prompts.py): `prompts.py`
- [Chunk analyst](https://github.com/mohamad-hachem/rag_langchain/blob/main/main.py): `main.py`

### Fixed corpus

- [Sample PDF corpus](https://github.com/mohamad-hachem/rag_langchain/tree/main/pdfs): `pdfs`
- [PDF reader](https://github.com/mohamad-hachem/rag_langchain/blob/main/filereader.py): `filereader.py`
- [Fixed-corpus index](https://github.com/mohamad-hachem/rag_langchain/blob/main/indexing.py): `indexing.py`
- [Search tool](https://github.com/mohamad-hachem/rag_langchain/blob/main/tools.py): `tools.py`
- [Retrieved passages](https://github.com/mohamad-hachem/rag_langchain/blob/main/tools.py): `tools.py`
- [Example coordinator](https://github.com/mohamad-hachem/rag_langchain/blob/main/agent.py): `agent.py`

### Other components

- **Document user**
- **OpenAI embeddings**
- **OpenAI chat model**

## Connections

- Document user → Chat interface: uploads, asks (evidence: `README.md`)
- Chat interface → Upload parser: processes files (evidence: `main.py`)
- Upload parser → Session indexing: provides documents (evidence: `main.py`)
- Session indexing → Session vector store: indexes chunks (evidence: `main.py`)
- Session indexing → OpenAI embeddings: embeds chunks (evidence: `README.md`)
- Chat interface → Session coordinator: invokes question (evidence: `main.py`)
- Session coordinator → Search tool: calls retrieval (evidence: `README.md`)
- Search tool → Session vector store: searches vectors (evidence: `README.md`)
- Search tool → Retrieved passages: saves passages (evidence: `README.md`)
- Session coordinator → Workflow prompts: uses instructions (evidence: `main.py`)
- Session coordinator → Chunk analyst: delegates analysis (evidence: `README.md`)
- Chunk analyst → Retrieved passages: reads passages (evidence: `README.md`)
- Session coordinator → OpenAI chat model: synthesizes answer (evidence: `README.md`)
- Sample PDF corpus → PDF reader: provides PDFs
- PDF reader → Fixed-corpus index: returns documents (evidence: `indexing.py`)
- Fixed-corpus index → OpenAI embeddings: embeds chunks (evidence: `README.md`)
- Fixed-corpus index → Search tool: supplies index (evidence: `tools.py`)
- Example coordinator → Search tool: calls retrieval (evidence: `agent.py`)
- Search tool → Fixed-corpus index: searches vectors (evidence: `tools.py`)
- Search tool → Retrieved passages: saves passages (evidence: `tools.py`)
- Example coordinator → Workflow prompts: uses instructions (evidence: `agent.py`)
- Example coordinator → Chunk analyst: delegates analysis (evidence: `README.md`)
- Example coordinator → OpenAI chat model: synthesizes answer (evidence: `README.md`)
