# kashish1530/internal-knowledge-assistant-rag- architecture

> Architecture diagram of the GitHub repository kashish1530/internal-knowledge-assistant-rag-, 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/kashish1530/internal-knowledge-assistant-rag-
- Repository: https://github.com/kashish1530/internal-knowledge-assistant-rag-

## Overview

This is an enterprise policy knowledge assistant: users ask questions through a Streamlit chat or CLI, and the system retrieves policy passages, reranks them, applies refusal/grounding checks, and returns an answer with citations. The graph also preserves corpus creation, PDF ingestion, stratified indexing, and the documented retrieval-evaluation branch. Some internal app and generator code is excerpted only partially, so unsampled implementation details are omitted rather than inferred.

Main entry points: [`app.py`](https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/app.py) (Web Chat), [`vector_stores`](https://github.com/kashish1530/internal-knowledge-assistant-rag-/tree/main/vector_stores) (Chunk-Size Indexes), [`query.py`](https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/query.py) (CLI Chat), [`golden_eval_set.csv`](https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/golden_eval_set.csv) (Golden Questions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_corpus["Policy Corpus"]
  node_corpus_generator["Corpus Generator<br/>[generate_corpus.py]"]
  node_policy_pdfs["Policy PDFs"]
end

subgraph group_index["Indexing"]
  node_ingestion["PDF Extraction &amp; Chunking<br/>[ingest.py]"]
  node_index_builder["FAISS Index Builder<br/>[database.py]"]
  node_vector_indexes[("Chunk-Size Indexes")]
end

subgraph group_assistant["Question Answering"]
  node_web_chat["Web Chat<br/>[app.py]"]
  node_cli_chat["CLI Chat<br/>[query.py]"]
  node_dense_search["Dense Search<br/>[app.py]"]
  node_keyword_search["BM25 Search<br/>[app.py]"]
  node_candidate_merge["Candidate Merge<br/>[app.py]"]
  node_reranker["Cross-Encoder Reranker<br/>[app.py]"]
  node_safety_grounding["Security &amp; Grounding<br/>[app.py]"]
  node_answer_model["Local Qwen Generator"]
end

subgraph group_validation["Retrieval Validation"]
  node_evaluation["Retrieval Experiments<br/>[evaluate.py]"]
  node_hybrid_evaluation["Hybrid Recall Evaluation"]
  node_vector_recall["Vector Recall Evaluation<br/>[retrieve.py]"]
  node_golden_set["Golden Questions"]
end

node_user(("Questioner"))

node_corpus_generator -->|"generates"| node_policy_pdfs
node_policy_pdfs -->|"extracts pages"| node_ingestion
node_ingestion -->|"builds chunks"| node_index_builder
node_index_builder -->|"saves indexes"| node_vector_indexes
node_user -->|"asks question"| node_web_chat
node_user -->|"asks question"| node_cli_chat
node_web_chat -->|"loads and searches"| node_vector_indexes
node_web_chat -->|"runs dense search"| node_dense_search
node_web_chat -->|"runs BM25 search"| node_keyword_search
node_dense_search -->|"adds candidates"| node_candidate_merge
node_keyword_search -->|"adds candidates"| node_candidate_merge
node_web_chat -->|"deduplicates results"| node_candidate_merge
node_candidate_merge -->|"scores candidates"| node_reranker
node_web_chat -->|"checks prompt and context"| node_safety_grounding
node_web_chat -->|"generates answer"| node_answer_model
node_cli_chat -->|"searches index"| node_vector_indexes
node_cli_chat -->|"reranks candidates"| node_reranker
node_cli_chat -->|"generates answer"| node_answer_model
node_evaluation -->|"loads queries"| node_golden_set
node_evaluation -->|"measures recall"| node_vector_indexes
node_hybrid_evaluation -->|"loads queries"| node_golden_set
node_hybrid_evaluation -->|"loads dense index"| node_vector_indexes
node_vector_recall -->|"loads queries"| node_golden_set
node_vector_recall -->|"measures recall"| node_vector_indexes

click node_corpus_generator "https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/generate_corpus.py"
click node_policy_pdfs "https://github.com/kashish1530/internal-knowledge-assistant-rag-/tree/main/data"
click node_ingestion "https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/ingest.py"
click node_index_builder "https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/database.py"
click node_vector_indexes "https://github.com/kashish1530/internal-knowledge-assistant-rag-/tree/main/vector_stores"
click node_web_chat "https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/app.py"
click node_cli_chat "https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/query.py"
click node_dense_search "https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/app.py"
click node_keyword_search "https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/app.py"
click node_candidate_merge "https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/app.py"
click node_reranker "https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/app.py"
click node_safety_grounding "https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/app.py"
click node_evaluation "https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/evaluate.py"
click node_hybrid_evaluation "https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/advanced_retrieve.py"
click node_vector_recall "https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/retrieve.py"
click node_golden_set "https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/golden_eval_set.csv"

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_corpus_generator,node_policy_pdfs toneBlue
class node_ingestion,node_index_builder,node_vector_indexes toneAmber
class node_web_chat,node_cli_chat,node_dense_search,node_keyword_search,node_candidate_merge,node_reranker,node_safety_grounding,node_answer_model toneMint
class node_evaluation,node_hybrid_evaluation,node_vector_recall,node_golden_set toneRose
class node_user toneIndigo
```

## Components

### Policy Corpus

- [Corpus Generator](https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/generate_corpus.py): `generate_corpus.py`
- [Policy PDFs](https://github.com/kashish1530/internal-knowledge-assistant-rag-/tree/main/data): `data`

### Indexing

- [PDF Extraction & Chunking](https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/ingest.py): `ingest.py`
- [FAISS Index Builder](https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/database.py): `database.py`
- [Chunk-Size Indexes](https://github.com/kashish1530/internal-knowledge-assistant-rag-/tree/main/vector_stores): `vector_stores`

### Question Answering

- [Web Chat](https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/app.py): `app.py`
- [CLI Chat](https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/query.py): `query.py`
- [Dense Search](https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/app.py): `app.py`
- [BM25 Search](https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/app.py): `app.py`
- [Candidate Merge](https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/app.py): `app.py`
- [Cross-Encoder Reranker](https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/app.py): `app.py`
- [Security & Grounding](https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/app.py): `app.py`
- **Local Qwen Generator**

### Retrieval Validation

- [Retrieval Experiments](https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/evaluate.py): `evaluate.py`
- [Hybrid Recall Evaluation](https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/advanced_retrieve.py): `advanced_retrieve.py`
- [Vector Recall Evaluation](https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/retrieve.py): `retrieve.py`
- [Golden Questions](https://github.com/kashish1530/internal-knowledge-assistant-rag-/blob/main/golden_eval_set.csv): `golden_eval_set.csv`

### Other components

- **Questioner**

## Connections

- Corpus Generator → Policy PDFs: generates (evidence: `README.md`)
- Policy PDFs → PDF Extraction & Chunking: extracts pages (evidence: `ingest.py`)
- PDF Extraction & Chunking → FAISS Index Builder: builds chunks (evidence: `database.py`)
- FAISS Index Builder → Chunk-Size Indexes: saves indexes (evidence: `database.py`)
- Questioner → Web Chat: asks question (evidence: `app.py`)
- Questioner → CLI Chat: asks question (evidence: `query.py`)
- Web Chat → Chunk-Size Indexes: loads and searches (evidence: `app.py`)
- Web Chat → Dense Search: runs dense search (evidence: `app.py`)
- Web Chat → BM25 Search: runs BM25 search (evidence: `app.py`)
- Dense Search → Candidate Merge: adds candidates (evidence: `app.py`)
- BM25 Search → Candidate Merge: adds candidates (evidence: `app.py`)
- Web Chat → Candidate Merge: deduplicates results (evidence: `app.py`)
- Candidate Merge → Cross-Encoder Reranker: scores candidates (evidence: `app.py`)
- Web Chat → Security & Grounding: checks prompt and context (evidence: `app.py`)
- Web Chat → Local Qwen Generator: generates answer (evidence: `app.py`)
- CLI Chat → Chunk-Size Indexes: searches index (evidence: `query.py`)
- CLI Chat → Cross-Encoder Reranker: reranks candidates (evidence: `query.py`)
- CLI Chat → Local Qwen Generator: generates answer (evidence: `query.py`)
- Retrieval Experiments → Golden Questions: loads queries (evidence: `evaluate.py`)
- Retrieval Experiments → Chunk-Size Indexes: measures recall (evidence: `evaluate.py`)
- Hybrid Recall Evaluation → Golden Questions: loads queries (evidence: `advanced_retrieve.py`)
- Hybrid Recall Evaluation → Chunk-Size Indexes: loads dense index (evidence: `advanced_retrieve.py`)
- Vector Recall Evaluation → Golden Questions: loads queries (evidence: `retrieve.py`)
- Vector Recall Evaluation → Chunk-Size Indexes: measures recall (evidence: `retrieve.py`)
