# hemakshijain25/retrieval-augmented-generation architecture

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

- Interactive diagram: https://gitdiagram.com/hemakshijain25/retrieval-augmented-generation
- Repository: https://github.com/hemakshijain25/retrieval-augmented-generation

## Overview

This is a PDF question-answering application with two Python implementations: a Gradio upload-and-question interface and a standalone backend script. The main user workflow is to upload a PDF, extract and split its text, store vector and graph representations in Neo4j, then retrieve both forms of evidence for a Claude-generated answer. The graph preserves those distinct ingestion and retrieval stages. The excerpts show key calls, but omit some orchestration code; README statements support the broader hybrid-RAG capability.

Main entry points: [`backend.py`](https://github.com/hemakshijain25/retrieval-augmented-generation/blob/main/backend.py) (Backend Script), [`frontend+backend.py`](https://github.com/hemakshijain25/retrieval-augmented-generation/blob/main/frontend%2Bbackend.py) (Vector Store)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["PDF Ingestion"]
  node_pdf_extract["PDF Extraction"]
  node_chunking["Text Chunking"]
  node_embedding["Text Embeddings"]
  node_graph_extract["Graph Extraction"]
end

subgraph group_knowledge["Knowledge Stores"]
  node_vector_store[("Vector Store")]
  node_graph_store[("Knowledge Graph")]
  node_neo4j[("Neo4j")]
end

subgraph group_answering["Question Answering"]
  node_question_routes["Question Handling"]
  node_vector_retrieval["Vector Retrieval"]
  node_graph_retrieval["Graph Retrieval"]
  node_answer_prompt["Context Assembly"]
  node_claude["Claude LLM"]
  node_answer["Answer Output"]
end

subgraph group_interface["Application Interfaces"]
  node_gradio["Gradio UI"]
  node_ui_handlers["UI Handlers"]
  node_backend_script["Backend Script<br/>[backend.py]"]
end

node_user(("User"))

node_user -->|"uses"| node_gradio
node_gradio -->|"dispatches"| node_ui_handlers
node_ui_handlers -->|"processes upload"| node_pdf_extract
node_pdf_extract -->|"splits text"| node_chunking
node_chunking -->|"stores chunks"| node_vector_store
node_embedding -->|"embeds chunks"| node_vector_store
node_chunking -->|"transforms chunks"| node_graph_extract
node_graph_extract -->|"adds graph data"| node_graph_store
node_vector_store -->|"persists vectors"| node_neo4j
node_graph_store -->|"queries graph"| node_neo4j
node_user -->|"asks question"| node_question_routes
node_question_routes -->|"retrieves chunks"| node_vector_retrieval
node_vector_retrieval -->|"searches similar"| node_vector_store
node_question_routes -->|"queries graph"| node_graph_retrieval
node_graph_retrieval -->|"runs Cypher"| node_graph_store
node_question_routes -->|"combines evidence"| node_answer_prompt
node_vector_retrieval -->|"supplies context"| node_answer_prompt
node_graph_retrieval -->|"supplies graph facts"| node_answer_prompt
node_answer_prompt -->|"prompts"| node_claude
node_claude -->|"generates"| node_answer
node_answer -->|"displays"| node_gradio
node_backend_script -->|"creates store"| node_vector_store
node_backend_script -->|"builds graph"| node_graph_store
node_backend_script -->|"runs retrieval"| node_vector_retrieval
node_backend_script -->|"runs retrieval"| node_graph_retrieval
node_backend_script -->|"combines results"| node_answer_prompt
node_backend_script -->|"generates answer"| node_claude

click node_gradio "https://github.com/hemakshijain25/retrieval-augmented-generation/blob/main/frontend%2Bbackend.py"
click node_ui_handlers "https://github.com/hemakshijain25/retrieval-augmented-generation/blob/main/frontend%2Bbackend.py"
click node_backend_script "https://github.com/hemakshijain25/retrieval-augmented-generation/blob/main/backend.py"
click node_pdf_extract "https://github.com/hemakshijain25/retrieval-augmented-generation/blob/main/frontend%2Bbackend.py"
click node_chunking "https://github.com/hemakshijain25/retrieval-augmented-generation/blob/main/frontend%2Bbackend.py"
click node_embedding "https://github.com/hemakshijain25/retrieval-augmented-generation/blob/main/frontend%2Bbackend.py"
click node_graph_extract "https://github.com/hemakshijain25/retrieval-augmented-generation/blob/main/frontend%2Bbackend.py"
click node_vector_store "https://github.com/hemakshijain25/retrieval-augmented-generation/blob/main/frontend%2Bbackend.py"
click node_graph_store "https://github.com/hemakshijain25/retrieval-augmented-generation/blob/main/frontend%2Bbackend.py"
click node_question_routes "https://github.com/hemakshijain25/retrieval-augmented-generation/blob/main/frontend%2Bbackend.py"
click node_vector_retrieval "https://github.com/hemakshijain25/retrieval-augmented-generation/blob/main/frontend%2Bbackend.py"
click node_graph_retrieval "https://github.com/hemakshijain25/retrieval-augmented-generation/blob/main/frontend%2Bbackend.py"
click node_answer_prompt "https://github.com/hemakshijain25/retrieval-augmented-generation/blob/main/frontend%2Bbackend.py"
click node_answer "https://github.com/hemakshijain25/retrieval-augmented-generation/blob/main/frontend%2Bbackend.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_pdf_extract,node_chunking,node_embedding,node_graph_extract,node_user toneBlue
class node_vector_store,node_graph_store,node_neo4j toneAmber
class node_question_routes,node_vector_retrieval,node_graph_retrieval,node_answer_prompt,node_claude,node_answer toneMint
class node_gradio,node_ui_handlers,node_backend_script toneRose
```

## Components

### PDF Ingestion

- [PDF Extraction](https://github.com/hemakshijain25/retrieval-augmented-generation/blob/main/frontend%2Bbackend.py): `frontend+backend.py`
- [Text Chunking](https://github.com/hemakshijain25/retrieval-augmented-generation/blob/main/frontend%2Bbackend.py): `frontend+backend.py`
- [Text Embeddings](https://github.com/hemakshijain25/retrieval-augmented-generation/blob/main/frontend%2Bbackend.py): `frontend+backend.py`
- [Graph Extraction](https://github.com/hemakshijain25/retrieval-augmented-generation/blob/main/frontend%2Bbackend.py): `frontend+backend.py`

### Knowledge Stores

- [Vector Store](https://github.com/hemakshijain25/retrieval-augmented-generation/blob/main/frontend%2Bbackend.py): `frontend+backend.py`
- [Knowledge Graph](https://github.com/hemakshijain25/retrieval-augmented-generation/blob/main/frontend%2Bbackend.py): `frontend+backend.py`
- **Neo4j**

### Question Answering

- [Question Handling](https://github.com/hemakshijain25/retrieval-augmented-generation/blob/main/frontend%2Bbackend.py): `frontend+backend.py`
- [Vector Retrieval](https://github.com/hemakshijain25/retrieval-augmented-generation/blob/main/frontend%2Bbackend.py): `frontend+backend.py`
- [Graph Retrieval](https://github.com/hemakshijain25/retrieval-augmented-generation/blob/main/frontend%2Bbackend.py): `frontend+backend.py`
- [Context Assembly](https://github.com/hemakshijain25/retrieval-augmented-generation/blob/main/frontend%2Bbackend.py): `frontend+backend.py`
- **Claude LLM**
- [Answer Output](https://github.com/hemakshijain25/retrieval-augmented-generation/blob/main/frontend%2Bbackend.py): `frontend+backend.py`

### Application Interfaces

- [Gradio UI](https://github.com/hemakshijain25/retrieval-augmented-generation/blob/main/frontend%2Bbackend.py): `frontend+backend.py`
- [UI Handlers](https://github.com/hemakshijain25/retrieval-augmented-generation/blob/main/frontend%2Bbackend.py): `frontend+backend.py`
- [Backend Script](https://github.com/hemakshijain25/retrieval-augmented-generation/blob/main/backend.py): `backend.py`

### Other components

- **User**

## Connections

- User → Gradio UI: uses (evidence: `README.md`)
- Gradio UI → UI Handlers: dispatches (evidence: `frontend+backend.py`)
- UI Handlers → PDF Extraction: processes upload (evidence: `frontend+backend.py`)
- PDF Extraction → Text Chunking: splits text (evidence: `frontend+backend.py`)
- Text Chunking → Vector Store: stores chunks (evidence: `frontend+backend.py`)
- Text Embeddings → Vector Store: embeds chunks (evidence: `frontend+backend.py`)
- Text Chunking → Graph Extraction: transforms chunks (evidence: `frontend+backend.py`)
- Graph Extraction → Knowledge Graph: adds graph data (evidence: `frontend+backend.py`)
- Vector Store → Neo4j: persists vectors (evidence: `frontend+backend.py`)
- Knowledge Graph → Neo4j: queries graph (evidence: `frontend+backend.py`)
- User → Question Handling: asks question (evidence: `README.md`)
- Question Handling → Vector Retrieval: retrieves chunks (evidence: `frontend+backend.py`)
- Vector Retrieval → Vector Store: searches similar (evidence: `frontend+backend.py`)
- Question Handling → Graph Retrieval: queries graph (evidence: `frontend+backend.py`)
- Graph Retrieval → Knowledge Graph: runs Cypher (evidence: `frontend+backend.py`)
- Question Handling → Context Assembly: combines evidence (evidence: `frontend+backend.py`)
- Vector Retrieval → Context Assembly: supplies context (evidence: `frontend+backend.py`)
- Graph Retrieval → Context Assembly: supplies graph facts (evidence: `frontend+backend.py`)
- Context Assembly → Claude LLM: prompts (evidence: `frontend+backend.py`)
- Claude LLM → Answer Output: generates (evidence: `frontend+backend.py`)
- Answer Output → Gradio UI: displays (evidence: `frontend+backend.py`)
- Backend Script → Vector Store: creates store (evidence: `backend.py`)
- Backend Script → Knowledge Graph: builds graph (evidence: `backend.py`)
- Backend Script → Vector Retrieval: runs retrieval (evidence: `backend.py`)
- Backend Script → Graph Retrieval: runs retrieval (evidence: `backend.py`)
- Backend Script → Context Assembly: combines results (evidence: `backend.py`)
- Backend Script → Claude LLM: generates answer (evidence: `backend.py`)
