# pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents architecture

> Architecture diagram of the GitHub repository pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents, 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/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents
- Repository: https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents

## Overview

RAGnarok turns uploaded or locally supplied documents into a searchable corpus, then answers questions grounded in retrieved passages with validated citations or a refusal. The main path is document extraction and chunking, embedding and persistence, vector retrieval, prompt construction, and LLM response. Streamlit and FastAPI expose the shared query core; the hybrid BM25/reranking implementation is a documented experiment, not the production path. The README also describes evaluation capabilities, but those are development tools rather than runtime product components. API ingestion is mentioned in Ingest.py’s docstring but is not present in the sampled api.py excerpt.

Main entry points: [`app.py`](https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/app.py) (Upload and chat UI), [`api.py`](https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/api.py) (HTTP API), [`Ingest.py`](https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/Ingest.py) (Ingestion pipeline), [`Query.py`](https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/Query.py) (Vector retrieval)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingestion["Document ingestion"]
  node_ingest["Ingestion pipeline<br/>[Ingest.py]"]
  node_extract["Format extraction<br/>[Ingest.py]"]
  node_chunk["Chunk and page mapping<br/>[Ingest.py]"]
  node_embed["Document embeddings<br/>[Ingest.py]"]
  node_chunkstore["Chunk records<br/>[chunks.json]"]
  node_vectorstore["Embedding matrix<br/>[embeddings.npy]"]
end

subgraph group_query["Grounded Q&amp;A"]
  node_querycore["Query and corpus core<br/>[Query.py]"]
  node_retrieve["Vector retrieval<br/>[Query.py]"]
  node_prompt["Citation prompt<br/>[Query.py]"]
  node_validate["Citation validation<br/>[Query.py]"]
end

subgraph group_interfaces["Product interfaces"]
  node_streamlit["Upload and chat UI<br/>[app.py]"]
  node_api["HTTP API<br/>[api.py]"]
end

subgraph group_experimental["Retrieval experiment"]
  node_hybrid["Hybrid retrieval<br/>[Query_hybrid.py]"]
  node_bm25["BM25 candidates<br/>[Query_hybrid.py]"]
  node_rerank["LLM reranking<br/>[Query_hybrid.py]"]
end

node_user(("Document user"))
node_openrouter{{"OpenRouter models"}}

node_user -->|"uploads and asks"| node_streamlit
node_user -->|"asks via HTTP"| node_api
node_user -->|"runs CLI ingestion"| node_ingest
node_streamlit -->|"ingests upload"| node_ingest
node_ingest -->|"loads documents"| node_extract
node_extract -->|"provides text and page offsets"| node_chunk
node_chunk -->|"embeds chunks"| node_embed
node_embed -->|"requests embeddings"| node_openrouter
node_ingest -->|"writes records"| node_chunkstore
node_ingest -->|"writes vectors"| node_vectorstore
node_streamlit -->|"reloads corpus"| node_querycore
node_querycore -->|"loads chunks"| node_chunkstore
node_querycore -->|"loads vectors"| node_vectorstore
node_streamlit -->|"requests results"| node_retrieve
node_api -->|"requests results"| node_retrieve
node_retrieve -->|"embeds question"| node_openrouter
node_retrieve -->|"returns retrieved chunks"| node_prompt
node_streamlit -->|"builds answer prompt"| node_prompt
node_api -->|"builds answer prompt"| node_prompt
node_streamlit -->|"requests answer"| node_openrouter
node_api -->|"requests answer"| node_openrouter
node_streamlit -->|"checks citations"| node_validate
node_api -->|"checks citations"| node_validate
node_hybrid -->|"combines candidates"| node_bm25
node_hybrid -.->|"uses vector candidates"| node_retrieve
node_bm25 -->|"supplies candidates"| node_rerank
node_hybrid -->|"scores and answers"| node_openrouter

click node_streamlit "https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/app.py"
click node_api "https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/api.py"
click node_ingest "https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/Ingest.py"
click node_extract "https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/Ingest.py"
click node_chunk "https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/Ingest.py"
click node_embed "https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/Ingest.py"
click node_chunkstore "https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/chunks.json"
click node_vectorstore "https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/embeddings.npy"
click node_querycore "https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/Query.py"
click node_retrieve "https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/Query.py"
click node_prompt "https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/Query.py"
click node_validate "https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/Query.py"
click node_hybrid "https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/Query_hybrid.py"
click node_bm25 "https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/Query_hybrid.py"
click node_rerank "https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/Query_hybrid.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,node_extract,node_chunk,node_embed,node_chunkstore,node_vectorstore,node_user toneBlue
class node_querycore,node_retrieve,node_prompt,node_validate toneAmber
class node_streamlit,node_api,node_openrouter toneMint
class node_hybrid,node_bm25,node_rerank toneRose
```

## Components

### Document ingestion

- [Ingestion pipeline](https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/Ingest.py): `Ingest.py`
- [Format extraction](https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/Ingest.py): `Ingest.py`
- [Chunk and page mapping](https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/Ingest.py): `Ingest.py`
- [Document embeddings](https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/Ingest.py): `Ingest.py`
- [Chunk records](https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/chunks.json): `chunks.json`
- [Embedding matrix](https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/embeddings.npy): `embeddings.npy`

### Grounded Q&A

- [Query and corpus core](https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/Query.py): `Query.py`
- [Vector retrieval](https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/Query.py): `Query.py`
- [Citation prompt](https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/Query.py): `Query.py`
- [Citation validation](https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/Query.py): `Query.py`

### Product interfaces

- [Upload and chat UI](https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/app.py): `app.py`
- [HTTP API](https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/api.py): `api.py`

### Retrieval experiment

- [Hybrid retrieval](https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/Query_hybrid.py): `Query_hybrid.py`
- [BM25 candidates](https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/Query_hybrid.py): `Query_hybrid.py`
- [LLM reranking](https://github.com/pvnkmr205/ragnarok---production-rag-chatbot-over-your-own-documents/blob/main/Query_hybrid.py): `Query_hybrid.py`

### Other components

- **Document user**
- **OpenRouter models**

## Connections

- Document user → Upload and chat UI: uploads and asks (evidence: `README.md`)
- Document user → HTTP API: asks via HTTP (evidence: `README.md`)
- Document user → Ingestion pipeline: runs CLI ingestion (evidence: `README.md`)
- Upload and chat UI → Ingestion pipeline: ingests upload (evidence: `app.py`)
- Ingestion pipeline → Format extraction: loads documents (evidence: `Ingest.py`)
- Format extraction → Chunk and page mapping: provides text and page offsets (evidence: `Ingest.py`)
- Chunk and page mapping → Document embeddings: embeds chunks (evidence: `Ingest.py`)
- Document embeddings → OpenRouter models: requests embeddings (evidence: `Ingest.py`)
- Ingestion pipeline → Chunk records: writes records (evidence: `Ingest.py`)
- Ingestion pipeline → Embedding matrix: writes vectors (evidence: `Ingest.py`)
- Upload and chat UI → Query and corpus core: reloads corpus (evidence: `app.py`)
- Query and corpus core → Chunk records: loads chunks (evidence: `Query.py`)
- Query and corpus core → Embedding matrix: loads vectors (evidence: `Query.py`)
- Upload and chat UI → Vector retrieval: requests results (evidence: `app.py`)
- HTTP API → Vector retrieval: requests results (evidence: `api.py`)
- Vector retrieval → OpenRouter models: embeds question (evidence: `Query.py`)
- Vector retrieval → Citation prompt: returns retrieved chunks (evidence: `Query.py`)
- Upload and chat UI → Citation prompt: builds answer prompt (evidence: `app.py`)
- HTTP API → Citation prompt: builds answer prompt (evidence: `api.py`)
- Upload and chat UI → OpenRouter models: requests answer (evidence: `app.py`)
- HTTP API → OpenRouter models: requests answer (evidence: `api.py`)
- Upload and chat UI → Citation validation: checks citations (evidence: `app.py`)
- HTTP API → Citation validation: checks citations (evidence: `api.py`)
- Hybrid retrieval → BM25 candidates: combines candidates (evidence: `Query_hybrid.py`)
- Hybrid retrieval → Vector retrieval: uses vector candidates
- BM25 candidates → LLM reranking: supplies candidates (evidence: `Query_hybrid.py`)
- Hybrid retrieval → OpenRouter models: scores and answers (evidence: `Query_hybrid.py`)
