# nisargkadam/rag_evaluation architecture

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

- Interactive diagram: https://gitdiagram.com/nisargkadam/rag_evaluation
- Repository: https://github.com/nisargkadam/rag_evaluation

## Overview

This is an inspectable fitness-and-nutrition RAG learning application. Users ask questions through a Streamlit or terminal interface; the agent retrieves page-ranked evidence, evaluates search quality, optionally retries once with a rewritten query, generates a source-constrained answer, evaluates it, and returns sources, scores, and retry counts. A separate PDF-ingestion path builds the FAISS knowledge base, while labeled benchmarks provide reproducible evaluation. The graph follows documented workflow stages; some internal wiring is inferred only from README descriptions because source excerpts are partial.

Main entry points: [`app/agent.py`](https://github.com/nisargkadam/rag_evaluation/blob/main/app/agent.py) (Search evaluation), [`app/ingest.py`](https://github.com/nisargkadam/rag_evaluation/blob/main/app/ingest.py) (PDF ingestion), [`run_evaluation.py`](https://github.com/nisargkadam/rag_evaluation/blob/main/run_evaluation.py) (Benchmark runner), [`streamlit_app.py`](https://github.com/nisargkadam/rag_evaluation/blob/main/streamlit_app.py) (Streamlit chat)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User interfaces"]
  node_streamlit["Streamlit chat<br/>[streamlit_app.py]"]
  node_terminal["Terminal chat<br/>[main.py]"]
end

subgraph group_rag["RAG workflow"]
  node_agent["RAG agent<br/>[agent.py]"]
  node_retrieval["Page retrieval<br/>[agent.py]"]
  node_search_eval["Search evaluation<br/>[agent.py]"]
  node_rewrite["Query rewrite<br/>[agent.py]"]
  node_generation["Answer generation<br/>[agent.py]"]
  node_answer_eval["Answer evaluation<br/>[agent.py]"]
  node_graph_state["Workflow state<br/>[graph.py]"]
end

subgraph group_knowledge["Knowledge ingestion"]
  node_faiss[("FAISS index")]
  node_pdfs["Nutrition PDFs"]
  node_ingestion["PDF ingestion<br/>[ingest.py]"]
  node_chunking["Chunk strategies"]
  node_embeddings["Local embeddings"]
end

subgraph group_evaluation["Evaluation"]
  node_judge["LLM judge<br/>[judge.py]"]
  node_metrics["Metric calculations<br/>[evaluation.py]"]
  node_benchmark_data["Labeled questions"]
  node_benchmark_loader["Benchmark helpers<br/>[benchmarks.py]"]
  node_benchmark_runner["Benchmark runner<br/>[run_evaluation.py]"]
end

node_user(("Questioner"))
node_llm["OpenAI model"]

node_user -->|"asks in"| node_streamlit
node_user -->|"asks in"| node_terminal
node_streamlit -->|"submits query"| node_agent
node_terminal -->|"submits query"| node_agent
node_agent -->|"starts workflow"| node_retrieval
node_retrieval -->|"retrieves pages"| node_faiss
node_retrieval -->|"evaluates results"| node_search_eval
node_search_eval -->|"judges relevance"| node_judge
node_search_eval -->|"calculates scores"| node_metrics
node_search_eval -->|"requests bounded retry"| node_rewrite
node_rewrite -->|"retries search"| node_retrieval
node_search_eval -->|"approves evidence"| node_generation
node_generation -->|"generates answer"| node_llm
node_generation -->|"evaluates answer"| node_answer_eval
node_answer_eval -->|"judges support"| node_judge
node_answer_eval -->|"calculates scores"| node_metrics
node_answer_eval -->|"requests stricter retry"| node_generation
node_agent -->|"carries workflow state"| node_graph_state
node_pdfs -->|"loads documents"| node_ingestion
node_ingestion -->|"selects strategy"| node_chunking
node_ingestion -->|"embeds chunks"| node_embeddings
node_ingestion -->|"writes index"| node_faiss
node_benchmark_data -->|"loads labels"| node_benchmark_loader
node_streamlit -->|"matches questions"| node_benchmark_loader
node_benchmark_runner -->|"runs benchmark queries"| node_agent
node_benchmark_runner -->|"reads cases"| node_benchmark_data
node_benchmark_runner -.->|"aggregates scores"| node_metrics

click node_streamlit "https://github.com/nisargkadam/rag_evaluation/blob/main/streamlit_app.py"
click node_terminal "https://github.com/nisargkadam/rag_evaluation/blob/main/app/main.py"
click node_agent "https://github.com/nisargkadam/rag_evaluation/blob/main/app/agent.py"
click node_retrieval "https://github.com/nisargkadam/rag_evaluation/blob/main/app/agent.py"
click node_search_eval "https://github.com/nisargkadam/rag_evaluation/blob/main/app/agent.py"
click node_rewrite "https://github.com/nisargkadam/rag_evaluation/blob/main/app/agent.py"
click node_generation "https://github.com/nisargkadam/rag_evaluation/blob/main/app/agent.py"
click node_answer_eval "https://github.com/nisargkadam/rag_evaluation/blob/main/app/agent.py"
click node_graph_state "https://github.com/nisargkadam/rag_evaluation/blob/main/app/graph.py"
click node_pdfs "https://github.com/nisargkadam/rag_evaluation/tree/main/data/pdfs"
click node_ingestion "https://github.com/nisargkadam/rag_evaluation/blob/main/app/ingest.py"
click node_chunking "https://github.com/nisargkadam/rag_evaluation/blob/main/app/chunking_strategies.py"
click node_judge "https://github.com/nisargkadam/rag_evaluation/blob/main/app/judge.py"
click node_metrics "https://github.com/nisargkadam/rag_evaluation/blob/main/app/evaluation.py"
click node_benchmark_data "https://github.com/nisargkadam/rag_evaluation/blob/main/data/evaluation_questions.json"
click node_benchmark_loader "https://github.com/nisargkadam/rag_evaluation/blob/main/app/benchmarks.py"
click node_benchmark_runner "https://github.com/nisargkadam/rag_evaluation/blob/main/run_evaluation.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_streamlit,node_terminal toneBlue
class node_agent,node_retrieval,node_search_eval,node_rewrite,node_generation,node_answer_eval,node_graph_state toneAmber
class node_faiss,node_pdfs,node_ingestion,node_chunking,node_embeddings toneMint
class node_judge,node_metrics,node_benchmark_data,node_benchmark_loader,node_benchmark_runner toneRose
class node_user,node_llm toneIndigo
```

## Components

### User interfaces

- [Streamlit chat](https://github.com/nisargkadam/rag_evaluation/blob/main/streamlit_app.py): `streamlit_app.py`
- [Terminal chat](https://github.com/nisargkadam/rag_evaluation/blob/main/app/main.py): `app/main.py`

### RAG workflow

- [RAG agent](https://github.com/nisargkadam/rag_evaluation/blob/main/app/agent.py): `app/agent.py`
- [Page retrieval](https://github.com/nisargkadam/rag_evaluation/blob/main/app/agent.py): `app/agent.py`
- [Search evaluation](https://github.com/nisargkadam/rag_evaluation/blob/main/app/agent.py): `app/agent.py`
- [Query rewrite](https://github.com/nisargkadam/rag_evaluation/blob/main/app/agent.py): `app/agent.py`
- [Answer generation](https://github.com/nisargkadam/rag_evaluation/blob/main/app/agent.py): `app/agent.py`
- [Answer evaluation](https://github.com/nisargkadam/rag_evaluation/blob/main/app/agent.py): `app/agent.py`
- [Workflow state](https://github.com/nisargkadam/rag_evaluation/blob/main/app/graph.py): `app/graph.py`

### Knowledge ingestion

- **FAISS index**
- [Nutrition PDFs](https://github.com/nisargkadam/rag_evaluation/tree/main/data/pdfs): `data/pdfs`
- [PDF ingestion](https://github.com/nisargkadam/rag_evaluation/blob/main/app/ingest.py): `app/ingest.py`
- [Chunk strategies](https://github.com/nisargkadam/rag_evaluation/blob/main/app/chunking_strategies.py): `app/chunking_strategies.py`
- **Local embeddings**

### Evaluation

- [LLM judge](https://github.com/nisargkadam/rag_evaluation/blob/main/app/judge.py): `app/judge.py`
- [Metric calculations](https://github.com/nisargkadam/rag_evaluation/blob/main/app/evaluation.py): `app/evaluation.py`
- [Labeled questions](https://github.com/nisargkadam/rag_evaluation/blob/main/data/evaluation_questions.json): `data/evaluation_questions.json`
- [Benchmark helpers](https://github.com/nisargkadam/rag_evaluation/blob/main/app/benchmarks.py): `app/benchmarks.py`
- [Benchmark runner](https://github.com/nisargkadam/rag_evaluation/blob/main/run_evaluation.py): `run_evaluation.py`

### Other components

- **Questioner**
- **OpenAI model**

## Connections

- Questioner → Streamlit chat: asks in (evidence: `README.md`)
- Questioner → Terminal chat: asks in (evidence: `README.md`)
- Streamlit chat → RAG agent: submits query (evidence: `streamlit_app.py`)
- Terminal chat → RAG agent: submits query (evidence: `app/main.py`)
- RAG agent → Page retrieval: starts workflow (evidence: `README.md`)
- Page retrieval → FAISS index: retrieves pages (evidence: `README.md`)
- Page retrieval → Search evaluation: evaluates results (evidence: `README.md`)
- Search evaluation → LLM judge: judges relevance (evidence: `app/agent.py`)
- Search evaluation → Metric calculations: calculates scores (evidence: `README.md`)
- Search evaluation → Query rewrite: requests bounded retry (evidence: `README.md`)
- Query rewrite → Page retrieval: retries search (evidence: `README.md`)
- Search evaluation → Answer generation: approves evidence (evidence: `README.md`)
- Answer generation → OpenAI model: generates answer (evidence: `README.md`)
- Answer generation → Answer evaluation: evaluates answer (evidence: `README.md`)
- Answer evaluation → LLM judge: judges support (evidence: `app/agent.py`)
- Answer evaluation → Metric calculations: calculates scores (evidence: `README.md`)
- Answer evaluation → Answer generation: requests stricter retry (evidence: `README.md`)
- RAG agent → Workflow state: carries workflow state (evidence: `app/agent.py`)
- Nutrition PDFs → PDF ingestion: loads documents (evidence: `README.md`)
- PDF ingestion → Chunk strategies: selects strategy (evidence: `app/ingest.py`)
- PDF ingestion → Local embeddings: embeds chunks (evidence: `README.md`)
- PDF ingestion → FAISS index: writes index (evidence: `app/ingest.py`)
- Labeled questions → Benchmark helpers: loads labels (evidence: `app/benchmarks.py`)
- Streamlit chat → Benchmark helpers: matches questions (evidence: `streamlit_app.py`)
- Benchmark runner → RAG agent: runs benchmark queries (evidence: `run_evaluation.py`)
- Benchmark runner → Labeled questions: reads cases (evidence: `README.md`)
- Benchmark runner → Metric calculations: aggregates scores
