# shivammitra/rag-document-q-a-chatbot architecture

> Architecture diagram of the GitHub repository shivammitra/rag-document-q-a-chatbot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shivammitra/rag-document-q-a-chatbot
- Repository: https://github.com/shivammitra/rag-document-q-a-chatbot

## Overview

#### 1. Repository Shape and Purpose
This repository contains two standalone Python RAG examples rather than one integrated application:
- Document-centric question answering in `RAG Document Q&A/main.py`.
- Conversational document Q&A in `RAG Q&A Conversation/app.py`.

Both implement the core RAG boundary: local PDF content is transformed into searchable embeddings, retrieved for a user question, then supplied as context to an LLM.

#### 2. Document Q&A Entry Points
`RAG Document Q&A/main.py` is the primary entry point for the document-QA variant. It is paired with `RAG Document Q&A/app_huggingfaceembedding.py`, which indicates an alternative or dedicated application path using Hugging Face embeddings.

The local corpus is represented by PDFs under `RAG Document Q&A/research_papers/`, including:
- `RAG Document Q&A/research_papers/Attention.pdf`
- `RAG Document Q&A/research_papers/LLM.pdf`

This project’s expected control flow is corpus ingestion/index construction followed by interactive or request-driven question answering.

#### 3. RAG Ingestion and Indexing Stage
The document-QA pipeline has a material ingestion boundary:
1. Read source PDFs from `RAG Document Q&A/research_papers/`.
2. Extract and split document text into retrievable chunks.
3. Generate vector embeddings.
4. Persist or retain a vector index/store for similarity search.

`RAG Document Q&A/app_huggingfaceembedding.py` is architecturally significant because it makes the embedding provider/model choice explicit. The README allows either an in-memory index or an external vector database, but the concrete store implementation cannot be confirmed from the supplied tree.

#### 4. Retrieval and Answer Generation Stage
For an incoming question, the QA application embeds the query, searches the document index, selects relevant chunks, and combines those chunks with the question for LLM answer generation. This is the principal retrieval-to-generation boundary in:
- `RAG Document Q&A/main.py`
- `RAG Document Q&A/app_huggingfaceembedding.py`

The source PDFs remain the grounding corpus; generated answers should be constrained by retrieved context rather than direct model-only responses.

#### 5. Conversational RAG Application
`RAG Q&A Conversation/app.py` is the entry point for the multi-turn variant. It adds conversation state/history around the same retrieval-and-generation pattern, allowing later questions to depend on prior interaction context.

Its available sample document is `RAG Q&A Conversation/temp.pdf`. The conversation layer must decide how historical turns influence retrieval and prompting: history can be used to rewrite a follow-up query, appended to the LLM prompt, or both. This is the main behavioral difference from the stateless document-QA project.

#### 6. Runtime and External Dependencies
The runtime is Python 3.8+ per the README. Material external capabilities are:
- An embedding model/provider; Hugging Face is directly suggested by `RAG Document Q&A/app_huggingfaceembedding.py`.
- An LLM API or local/open-source LLM for response generation.
- A vector store/index, potentially in memory or an external database such as FAISS or Pinecone.

API keys and vector-store credentials are deployment-time boundaries. No infrastructure manifests, dependency lockfiles, or service definitions appear in the supplied tree, so environment provisioning and persistence behavior should be verified in the Python entry points before extending the system.

Main entry points: [`RAG Document Q&A/research_papers`](https://github.com/shivammitra/rag-document-q-a-chatbot/tree/main/RAG%20Document%20Q%26A/research_papers) (Research PDFs), [`RAG Q&A Conversation/app.py`](https://github.com/shivammitra/rag-document-q-a-chatbot/blob/main/RAG%20Q%26A%20Conversation/app.py) (Conversation QA entry point), [`RAG Document Q&A/main.py`](https://github.com/shivammitra/rag-document-q-a-chatbot/blob/main/RAG%20Document%20Q%26A/main.py) (Document QA entry point), [`RAG Document Q&A/app_huggingfaceembedding.py`](https://github.com/shivammitra/rag-document-q-a-chatbot/blob/main/RAG%20Document%20Q%26A/app_huggingfaceembedding.py) (HF embeddings path)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_document_qa["Document Q&amp;A"]
  node_doc_main["Document QA entry point<br/>Python application<br/>[main.py]"]
  node_hf_app["HF embeddings path<br/>Python application"]
  node_doc_pdfs["Research PDFs<br/>grounding corpus"]
  node_attention_pdf["Attention paper<br/>PDF source<br/>[Attention.pdf]"]
  node_llm_pdf["LLM paper<br/>PDF source<br/>[LLM.pdf]"]
  node_doc_ingestion["Extract and chunk<br/>ingestion stage"]
  node_embedding_provider{{"Embedding provider<br/>model provider"}}
  node_vector_index[("Vector index<br/>similarity store")]
  node_doc_retrieval["Retrieve context<br/>retrieval stage"]
end

subgraph group_conversation_qa["Conversational Q&amp;A"]
  node_conversation_app["Conversation QA entry point<br/>Python application<br/>[app.py]"]
  node_conversation_pdf["Sample PDF<br/>grounding corpus<br/>[temp.pdf]"]
  node_conversation_ingestion["Extract, chunk, index<br/>ingestion stage"]
  node_conversation_index[("Conversation vector index<br/>similarity store")]
  node_history[("Conversation history<br/>session state")]
  node_conversation_retrieval["History-aware retrieval<br/>retrieval stage"]
end

node_llm{{"LLM<br/>answer model"}}
node_answers["Grounded answers<br/>generated response"]

node_attention_pdf -->|"included in corpus"| node_doc_pdfs
node_llm_pdf -->|"included in corpus"| node_doc_pdfs
node_doc_pdfs -->|"read PDFs"| node_doc_ingestion
node_doc_ingestion -->|"embed chunks"| node_embedding_provider
node_embedding_provider -->|"store vectors"| node_vector_index
node_doc_main -->|"question"| node_doc_retrieval
node_hf_app -->|"question"| node_doc_retrieval
node_vector_index -->|"similarity search"| node_doc_retrieval
node_embedding_provider -->|"embed query"| node_doc_retrieval
node_doc_retrieval -->|"question + context"| node_llm
node_conversation_pdf -->|"read PDF"| node_conversation_ingestion
node_conversation_ingestion -->|"chunk embeddings"| node_conversation_index
node_conversation_app -->|"record turns"| node_history
node_conversation_app -->|"new question"| node_conversation_retrieval
node_history -->|"follow-up context"| node_conversation_retrieval
node_conversation_index -->|"similarity search"| node_conversation_retrieval
node_conversation_retrieval -->|"context + history"| node_llm
node_llm -->|"generate"| node_answers

click node_doc_main "https://github.com/shivammitra/rag-document-q-a-chatbot/blob/main/RAG%20Document%20Q%26A/main.py"
click node_hf_app "https://github.com/shivammitra/rag-document-q-a-chatbot/blob/main/RAG%20Document%20Q%26A/app_huggingfaceembedding.py"
click node_doc_pdfs "https://github.com/shivammitra/rag-document-q-a-chatbot/tree/main/RAG%20Document%20Q%26A/research_papers"
click node_attention_pdf "https://github.com/shivammitra/rag-document-q-a-chatbot/blob/main/RAG%20Document%20Q%26A/research_papers/Attention.pdf"
click node_llm_pdf "https://github.com/shivammitra/rag-document-q-a-chatbot/blob/main/RAG%20Document%20Q%26A/research_papers/LLM.pdf"
click node_conversation_app "https://github.com/shivammitra/rag-document-q-a-chatbot/blob/main/RAG%20Q%26A%20Conversation/app.py"
click node_conversation_pdf "https://github.com/shivammitra/rag-document-q-a-chatbot/blob/main/RAG%20Q%26A%20Conversation/temp.pdf"

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_doc_main,node_hf_app,node_doc_pdfs,node_attention_pdf,node_llm_pdf,node_doc_ingestion,node_embedding_provider,node_vector_index,node_doc_retrieval toneBlue
class node_conversation_app,node_conversation_pdf,node_conversation_ingestion,node_conversation_index,node_history,node_conversation_retrieval toneAmber
class node_llm,node_answers toneNeutral
```

## Components

### Document Q&A

Standalone stateless RAG example.

- [Document QA entry point](https://github.com/shivammitra/rag-document-q-a-chatbot/blob/main/RAG%20Document%20Q%26A/main.py): Python application · `RAG Document Q&A/main.py`
- [HF embeddings path](https://github.com/shivammitra/rag-document-q-a-chatbot/blob/main/RAG%20Document%20Q%26A/app_huggingfaceembedding.py): Python application · Alternative path that makes the embedding provider explicit. · `RAG Document Q&A/app_huggingfaceembedding.py`
- [Research PDFs](https://github.com/shivammitra/rag-document-q-a-chatbot/tree/main/RAG%20Document%20Q%26A/research_papers): grounding corpus · `RAG Document Q&A/research_papers`
- [Attention paper](https://github.com/shivammitra/rag-document-q-a-chatbot/blob/main/RAG%20Document%20Q%26A/research_papers/Attention.pdf): PDF source · `RAG Document Q&A/research_papers/Attention.pdf`
- [LLM paper](https://github.com/shivammitra/rag-document-q-a-chatbot/blob/main/RAG%20Document%20Q%26A/research_papers/LLM.pdf): PDF source · `RAG Document Q&A/research_papers/LLM.pdf`
- **Extract and chunk**: ingestion stage · Turns PDF text into retrievable chunks.
- **Embedding provider**: model provider · Hugging Face is explicitly indicated for one application path.
- **Vector index**: similarity store · May be in-memory or an external vector database.
- **Retrieve context**: retrieval stage · Embeds questions and selects relevant chunks.

### Conversational Q&A

Standalone multi-turn RAG example.

- [Conversation QA entry point](https://github.com/shivammitra/rag-document-q-a-chatbot/blob/main/RAG%20Q%26A%20Conversation/app.py): Python application · `RAG Q&A Conversation/app.py`
- [Sample PDF](https://github.com/shivammitra/rag-document-q-a-chatbot/blob/main/RAG%20Q%26A%20Conversation/temp.pdf): grounding corpus · `RAG Q&A Conversation/temp.pdf`
- **Extract, chunk, index**: ingestion stage
- **Conversation vector index**: similarity store
- **Conversation history**: session state · Prior turns can rewrite retrieval queries and augment prompts.
- **History-aware retrieval**: retrieval stage

### Other components

- **LLM**: answer model · Generates answers from question and retrieved context.
- **Grounded answers**: generated response · Responses should be constrained by retrieved context.

## Connections

- Attention paper → Research PDFs: included in corpus
- LLM paper → Research PDFs: included in corpus
- Research PDFs → Extract and chunk: read PDFs
- Extract and chunk → Embedding provider: embed chunks
- Embedding provider → Vector index: store vectors
- Document QA entry point → Retrieve context: question
- HF embeddings path → Retrieve context: question
- Vector index → Retrieve context: similarity search
- Embedding provider → Retrieve context: embed query
- Retrieve context → LLM: question + context
- Sample PDF → Extract, chunk, index: read PDF
- Extract, chunk, index → Conversation vector index: chunk embeddings
- Conversation QA entry point → Conversation history: record turns
- Conversation QA entry point → History-aware retrieval: new question
- Conversation history → History-aware retrieval: follow-up context
- Conversation vector index → History-aware retrieval: similarity search
- History-aware retrieval → LLM: context + history
- LLM → Grounded answers: generate
