# kunal-thapliyal/rag-agentic-ai architecture

> Architecture diagram of the GitHub repository kunal-thapliyal/rag-agentic-ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kunal-thapliyal/rag-agentic-ai
- Repository: https://github.com/kunal-thapliyal/rag-agentic-ai

## Overview

The Agentic AI Knowledge Assistant ingests one PDF into Qdrant, then answers each user question through a LangGraph RAG workflow: retrieve the five nearest chunks, use the best similarity score as confidence, and either refuse below the threshold or ask Groq for a context-only answer. Streamlit displays the answer, confidence, and retrieved sources. Offline ingestion and online querying are separate paths. The README documents the major stages; sampled source confirms their call ownership and branching.

Main entry points: [`app/graph.py`](https://github.com/kunal-thapliyal/rag-agentic-ai/blob/main/app/graph.py) (RAG Workflow), [`app/Scripts/ingest.py`](https://github.com/kunal-thapliyal/rag-agentic-ai/blob/main/app/Scripts/ingest.py) (Ingestion Runner), [`app/retrieval.py`](https://github.com/kunal-thapliyal/rag-agentic-ai/blob/main/app/retrieval.py) (Similarity Search), [`app/generation.py`](https://github.com/kunal-thapliyal/rag-agentic-ai/blob/main/app/generation.py) (Grounded Generation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingestion["PDF Ingestion"]
  node_ingest_script["Ingestion Runner<br/>[ingest.py]"]
  node_pdf_processing["PDF Extraction &amp; Chunking<br/>[ingestion.py]"]
  node_document_embeddings["Document Embeddings<br/>[embeddings.py]"]
  node_vector_upload["Collection &amp; Upload<br/>[vectorstore.py]"]
end

subgraph group_retrieval["Knowledge Retrieval"]
  node_query_embeddings["Query Embedding<br/>[embeddings.py]"]
  node_retrieval_search["Similarity Search<br/>[retrieval.py]"]
  node_qdrant[("Qdrant Collection")]
  node_config["Runtime Configuration<br/>[config.py]"]
end

subgraph group_answering["Answer Workflow"]
  node_workflow["RAG Workflow<br/>[graph.py]"]
  node_relevance{{"Relevance Gate<br/>[graph.py]"}}
  node_refusal["Refusal Result<br/>[graph.py]"]
  node_generation["Grounded Generation<br/>[generation.py]"]
end

subgraph group_interface["User Interface"]
  node_streamlit["Streamlit UI<br/>[streamlitapp.py]"]
end

node_user(("User"))
node_pdf["Agentic AI PDF"]
node_groq["Groq API"]

node_ingest_script -->|"loads and chunks"| node_pdf_processing
node_pdf_processing -->|"reads pages"| node_pdf
node_ingest_script -->|"embeds chunks"| node_document_embeddings
node_ingest_script -->|"creates collection"| node_vector_upload
node_ingest_script -->|"uploads vectors"| node_vector_upload
node_vector_upload -->|"writes chunks"| node_qdrant
node_user -->|"asks question"| node_streamlit
node_streamlit -->|"calls ask_question"| node_workflow
node_workflow -->|"searches question"| node_retrieval_search
node_retrieval_search -->|"embeds query"| node_query_embeddings
node_retrieval_search -->|"queries top five"| node_qdrant
node_qdrant -->|"returns matches"| node_retrieval_search
node_workflow -->|"checks top score"| node_relevance
node_relevance -->|"score at least 0.50"| node_generation
node_relevance -->|"score below 0.50"| node_refusal
node_workflow -->|"calls with question and matches"| node_generation
node_generation -->|"requests completion"| node_groq
node_workflow -->|"returns answer and sources"| node_streamlit
node_refusal -->|"sets refusal result"| node_workflow
node_config -->|"supplies model settings"| node_query_embeddings
node_config -->|"supplies collection settings"| node_qdrant
node_config -->|"supplies API key"| node_generation

click node_pdf "https://github.com/kunal-thapliyal/rag-agentic-ai/blob/main/data/Ebook-Agentic-AI.pdf"
click node_ingest_script "https://github.com/kunal-thapliyal/rag-agentic-ai/blob/main/app/Scripts/ingest.py"
click node_pdf_processing "https://github.com/kunal-thapliyal/rag-agentic-ai/blob/main/app/ingestion.py"
click node_document_embeddings "https://github.com/kunal-thapliyal/rag-agentic-ai/blob/main/app/embeddings.py"
click node_vector_upload "https://github.com/kunal-thapliyal/rag-agentic-ai/blob/main/app/vectorstore.py"
click node_query_embeddings "https://github.com/kunal-thapliyal/rag-agentic-ai/blob/main/app/embeddings.py"
click node_retrieval_search "https://github.com/kunal-thapliyal/rag-agentic-ai/blob/main/app/retrieval.py"
click node_config "https://github.com/kunal-thapliyal/rag-agentic-ai/blob/main/app/config.py"
click node_streamlit "https://github.com/kunal-thapliyal/rag-agentic-ai/blob/main/app/streamlitapp.py"
click node_workflow "https://github.com/kunal-thapliyal/rag-agentic-ai/blob/main/app/graph.py"
click node_relevance "https://github.com/kunal-thapliyal/rag-agentic-ai/blob/main/app/graph.py"
click node_refusal "https://github.com/kunal-thapliyal/rag-agentic-ai/blob/main/app/graph.py"
click node_generation "https://github.com/kunal-thapliyal/rag-agentic-ai/blob/main/app/generation.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_ingest_script,node_pdf_processing,node_document_embeddings,node_vector_upload,node_user toneBlue
class node_query_embeddings,node_retrieval_search,node_qdrant,node_config toneAmber
class node_workflow,node_relevance,node_refusal,node_generation,node_groq toneMint
class node_streamlit toneRose
class node_pdf toneTeal
```

## Components

### PDF Ingestion

- [Ingestion Runner](https://github.com/kunal-thapliyal/rag-agentic-ai/blob/main/app/Scripts/ingest.py): `app/Scripts/ingest.py`
- [PDF Extraction & Chunking](https://github.com/kunal-thapliyal/rag-agentic-ai/blob/main/app/ingestion.py): `app/ingestion.py`
- [Document Embeddings](https://github.com/kunal-thapliyal/rag-agentic-ai/blob/main/app/embeddings.py): `app/embeddings.py`
- [Collection & Upload](https://github.com/kunal-thapliyal/rag-agentic-ai/blob/main/app/vectorstore.py): `app/vectorstore.py`

### Knowledge Retrieval

- [Query Embedding](https://github.com/kunal-thapliyal/rag-agentic-ai/blob/main/app/embeddings.py): `app/embeddings.py`
- [Similarity Search](https://github.com/kunal-thapliyal/rag-agentic-ai/blob/main/app/retrieval.py): `app/retrieval.py`
- **Qdrant Collection**
- [Runtime Configuration](https://github.com/kunal-thapliyal/rag-agentic-ai/blob/main/app/config.py): `app/config.py`

### Answer Workflow

- [RAG Workflow](https://github.com/kunal-thapliyal/rag-agentic-ai/blob/main/app/graph.py): `app/graph.py`
- [Relevance Gate](https://github.com/kunal-thapliyal/rag-agentic-ai/blob/main/app/graph.py): `app/graph.py`
- [Refusal Result](https://github.com/kunal-thapliyal/rag-agentic-ai/blob/main/app/graph.py): `app/graph.py`
- [Grounded Generation](https://github.com/kunal-thapliyal/rag-agentic-ai/blob/main/app/generation.py): `app/generation.py`

### User Interface

- [Streamlit UI](https://github.com/kunal-thapliyal/rag-agentic-ai/blob/main/app/streamlitapp.py): `app/streamlitapp.py`

### Other components

- **User**
- [Agentic AI PDF](https://github.com/kunal-thapliyal/rag-agentic-ai/blob/main/data/Ebook-Agentic-AI.pdf): `data/Ebook-Agentic-AI.pdf`
- **Groq API**

## Connections

- Ingestion Runner → PDF Extraction & Chunking: loads and chunks
- PDF Extraction & Chunking → Agentic AI PDF: reads pages
- Ingestion Runner → Document Embeddings: embeds chunks
- Ingestion Runner → Collection & Upload: creates collection
- Ingestion Runner → Collection & Upload: uploads vectors
- Collection & Upload → Qdrant Collection: writes chunks
- User → Streamlit UI: asks question
- Streamlit UI → RAG Workflow: calls ask_question
- RAG Workflow → Similarity Search: searches question
- Similarity Search → Query Embedding: embeds query
- Similarity Search → Qdrant Collection: queries top five
- Qdrant Collection → Similarity Search: returns matches
- RAG Workflow → Relevance Gate: checks top score
- Relevance Gate → Grounded Generation: score at least 0.50
- Relevance Gate → Refusal Result: score below 0.50
- RAG Workflow → Grounded Generation: calls with question and matches
- Grounded Generation → Groq API: requests completion
- RAG Workflow → Streamlit UI: returns answer and sources
- Refusal Result → RAG Workflow: sets refusal result
- Runtime Configuration → Query Embedding: supplies model settings
- Runtime Configuration → Qdrant Collection: supplies collection settings
- Runtime Configuration → Grounded Generation: supplies API key
