# sabertooth-123/rag_yt_chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/sabertooth-123/rag_yt_chatbot
- Repository: https://github.com/sabertooth-123/rag_yt_chatbot

## Overview

yt-chat is a terminal YouTube-video Q&A application designed to ground answers in timestamped transcript passages and refuse when retrieval confidence or citations are insufficient. Its principal workflow runs from a user’s video and question through transcript acquisition, cleaning and chunking, embedding and caching, retrieval, answer generation and citation checks, then displays linked timestamps. Separate evaluation capabilities compare retrievers, measure citation and answer quality, and calibrate refusal thresholds. The graph follows documented workflow and sampled orchestration references; unsampled implementation details are not inferred.

Main entry points: [`src/ytchat/pipeline.py`](https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/pipeline.py) (Pipeline orchestration), [`src/ytchat/cli/app.py`](https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/cli/app.py) (CLI and chat), [`src/ytchat/retrieval/factory.py`](https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/retrieval/factory.py) (Retriever selection), [`src/ytchat/evaluation/runner.py`](https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/evaluation/runner.py) (Evaluation runner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Terminal interface"]
  node_cli["CLI and chat<br/>[app.py]"]
  node_repl["Chat commands<br/>[repl.py]"]
end

subgraph group_indexing["Transcript indexing"]
  node_pipeline["Pipeline orchestration<br/>[pipeline.py]"]
  node_url["Video URL parsing<br/>[url.py]"]
  node_transcript["Transcript acquisition<br/>[transcript.py]"]
  node_metadata["Video metadata<br/>[metadata.py]"]
  node_clean["Transcript cleaning<br/>[clean.py]"]
  node_chunking["Timed chunking<br/>[chunking.py]"]
  node_embedding["Embedding providers<br/>[factory.py]"]
  node_repository[("Transcript and cache<br/>[repository.py]")]
  node_vectorstore[("Vector index<br/>[vectorstore.py]")]
end

subgraph group_qa["Search and answers"]
  node_retriever_factory["Retriever selection<br/>[factory.py]"]
  node_dense["Dense search<br/>[dense.py]"]
  node_sparse["Sparse search<br/>[sparse.py]"]
  node_hybrid["Hybrid search<br/>[hybrid.py]"]
  node_rerank["Optional reranking<br/>[rerank.py]"]
  node_rewriter["Follow-up rewriting<br/>[rewriter.py]"]
  node_answerer["Grounded answering<br/>[answerer.py]"]
  node_citations["Citation validation<br/>[citations.py]"]
  node_llm["LLM adapters<br/>[llm.py]"]
end

subgraph group_evaluation["Evaluation"]
  node_dataset["Benchmark datasets<br/>[dataset.py]"]
  node_eval_runner["Evaluation runner<br/>[runner.py]"]
  node_metrics["Retrieval metrics"]
  node_generation_metrics["Generation scoring"]
  node_report["Evaluation reports<br/>[report.py]"]
end

node_user(("Video and question"))
node_youtube(("YouTube"))
node_llm_service(("LLM service"))

node_user -->|"provides video"| node_cli
node_cli -->|"starts workflow"| node_pipeline
node_cli -->|"opens chat"| node_repl
node_pipeline -->|"parses video"| node_url
node_pipeline -->|"fetches captions"| node_transcript
node_pipeline -->|"fetches metadata"| node_metadata
node_pipeline -->|"cleans transcript"| node_clean
node_pipeline -->|"creates chunks"| node_chunking
node_pipeline -->|"builds embeddings"| node_embedding
node_pipeline -->|"caches stages"| node_repository
node_pipeline -->|"builds index"| node_vectorstore
node_transcript -->|"fetches subtitles"| node_youtube
node_repl -->|"queries video"| node_pipeline
node_pipeline -->|"selects search"| node_retriever_factory
node_retriever_factory -->|"creates dense"| node_dense
node_retriever_factory -->|"creates sparse"| node_sparse
node_retriever_factory -->|"creates hybrid"| node_hybrid
node_retriever_factory -.->|"configures reranking"| node_rerank
node_pipeline -->|"rewrites follow-ups"| node_rewriter
node_pipeline -->|"generates answer"| node_answerer
node_answerer -->|"checks citations"| node_citations
node_answerer -->|"requests completion"| node_llm
node_llm -->|"sends prompt"| node_llm_service
node_cli -->|"loads benchmarks"| node_dataset
node_cli -->|"runs evaluation"| node_eval_runner
node_eval_runner -->|"evaluates cases"| node_dataset
node_eval_runner -->|"scores retrieval"| node_metrics
node_eval_runner -->|"scores answers"| node_generation_metrics
node_cli -->|"formats results"| node_report

click node_cli "https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/cli/app.py"
click node_repl "https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/cli/repl.py"
click node_pipeline "https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/pipeline.py"
click node_url "https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/ingestion/url.py"
click node_transcript "https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/ingestion/transcript.py"
click node_metadata "https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/ingestion/metadata.py"
click node_clean "https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/preprocessing/clean.py"
click node_chunking "https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/preprocessing/chunking.py"
click node_embedding "https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/embeddings/factory.py"
click node_repository "https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/database/repository.py"
click node_vectorstore "https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/database/vectorstore.py"
click node_retriever_factory "https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/retrieval/factory.py"
click node_dense "https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/retrieval/dense.py"
click node_sparse "https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/retrieval/sparse.py"
click node_hybrid "https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/retrieval/hybrid.py"
click node_rerank "https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/retrieval/rerank.py"
click node_rewriter "https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/generation/rewriter.py"
click node_answerer "https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/generation/answerer.py"
click node_citations "https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/generation/citations.py"
click node_llm "https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/generation/llm.py"
click node_dataset "https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/evaluation/dataset.py"
click node_eval_runner "https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/evaluation/runner.py"
click node_metrics "https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/evaluation/retrieval_metrics.py"
click node_generation_metrics "https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/evaluation/generation_metrics.py"
click node_report "https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/evaluation/report.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_cli,node_repl toneBlue
class node_pipeline,node_url,node_transcript,node_metadata,node_clean,node_chunking,node_embedding,node_repository,node_vectorstore toneAmber
class node_retriever_factory,node_dense,node_sparse,node_hybrid,node_rerank,node_rewriter,node_answerer,node_citations,node_llm toneMint
class node_dataset,node_eval_runner,node_metrics,node_generation_metrics,node_report toneRose
class node_user,node_youtube,node_llm_service toneIndigo
```

## Components

### Terminal interface

- [CLI and chat](https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/cli/app.py): `src/ytchat/cli/app.py`
- [Chat commands](https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/cli/repl.py): `src/ytchat/cli/repl.py`

### Transcript indexing

- [Pipeline orchestration](https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/pipeline.py): `src/ytchat/pipeline.py`
- [Video URL parsing](https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/ingestion/url.py): `src/ytchat/ingestion/url.py`
- [Transcript acquisition](https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/ingestion/transcript.py): `src/ytchat/ingestion/transcript.py`
- [Video metadata](https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/ingestion/metadata.py): `src/ytchat/ingestion/metadata.py`
- [Transcript cleaning](https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/preprocessing/clean.py): `src/ytchat/preprocessing/clean.py`
- [Timed chunking](https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/preprocessing/chunking.py): `src/ytchat/preprocessing/chunking.py`
- [Embedding providers](https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/embeddings/factory.py): `src/ytchat/embeddings/factory.py`
- [Transcript and cache](https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/database/repository.py): `src/ytchat/database/repository.py`
- [Vector index](https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/database/vectorstore.py): `src/ytchat/database/vectorstore.py`

### Search and answers

- [Retriever selection](https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/retrieval/factory.py): `src/ytchat/retrieval/factory.py`
- [Dense search](https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/retrieval/dense.py): `src/ytchat/retrieval/dense.py`
- [Sparse search](https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/retrieval/sparse.py): `src/ytchat/retrieval/sparse.py`
- [Hybrid search](https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/retrieval/hybrid.py): `src/ytchat/retrieval/hybrid.py`
- [Optional reranking](https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/retrieval/rerank.py): `src/ytchat/retrieval/rerank.py`
- [Follow-up rewriting](https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/generation/rewriter.py): `src/ytchat/generation/rewriter.py`
- [Grounded answering](https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/generation/answerer.py): `src/ytchat/generation/answerer.py`
- [Citation validation](https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/generation/citations.py): `src/ytchat/generation/citations.py`
- [LLM adapters](https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/generation/llm.py): `src/ytchat/generation/llm.py`

### Evaluation

- [Benchmark datasets](https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/evaluation/dataset.py): `src/ytchat/evaluation/dataset.py`
- [Evaluation runner](https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/evaluation/runner.py): `src/ytchat/evaluation/runner.py`
- [Retrieval metrics](https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/evaluation/retrieval_metrics.py): `src/ytchat/evaluation/retrieval_metrics.py`
- [Generation scoring](https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/evaluation/generation_metrics.py): `src/ytchat/evaluation/generation_metrics.py`
- [Evaluation reports](https://github.com/sabertooth-123/rag_yt_chatbot/blob/main/src/ytchat/evaluation/report.py): `src/ytchat/evaluation/report.py`

### Other components

- **Video and question**
- **YouTube**
- **LLM service**

## Connections

- Video and question → CLI and chat: provides video (evidence: `README.md`)
- CLI and chat → Pipeline orchestration: starts workflow (evidence: `src/ytchat/cli/app.py`)
- CLI and chat → Chat commands: opens chat (evidence: `src/ytchat/cli/app.py`)
- Pipeline orchestration → Video URL parsing: parses video (evidence: `src/ytchat/pipeline.py`)
- Pipeline orchestration → Transcript acquisition: fetches captions (evidence: `src/ytchat/pipeline.py`)
- Pipeline orchestration → Video metadata: fetches metadata (evidence: `src/ytchat/pipeline.py`)
- Pipeline orchestration → Transcript cleaning: cleans transcript (evidence: `src/ytchat/pipeline.py`)
- Pipeline orchestration → Timed chunking: creates chunks (evidence: `src/ytchat/pipeline.py`)
- Pipeline orchestration → Embedding providers: builds embeddings (evidence: `src/ytchat/pipeline.py`)
- Pipeline orchestration → Transcript and cache: caches stages (evidence: `src/ytchat/pipeline.py`)
- Pipeline orchestration → Vector index: builds index (evidence: `src/ytchat/pipeline.py`)
- Transcript acquisition → YouTube: fetches subtitles (evidence: `README.md`)
- Chat commands → Pipeline orchestration: queries video (evidence: `src/ytchat/cli/repl.py`)
- Pipeline orchestration → Retriever selection: selects search (evidence: `src/ytchat/pipeline.py`)
- Retriever selection → Dense search: creates dense (evidence: `src/ytchat/retrieval/factory.py`)
- Retriever selection → Sparse search: creates sparse (evidence: `src/ytchat/retrieval/factory.py`)
- Retriever selection → Hybrid search: creates hybrid (evidence: `src/ytchat/retrieval/factory.py`)
- Retriever selection → Optional reranking: configures reranking (evidence: `src/ytchat/retrieval/factory.py`)
- Pipeline orchestration → Follow-up rewriting: rewrites follow-ups (evidence: `src/ytchat/pipeline.py`)
- Pipeline orchestration → Grounded answering: generates answer (evidence: `src/ytchat/pipeline.py`)
- Grounded answering → Citation validation: checks citations (evidence: `src/ytchat/generation/answerer.py`)
- Grounded answering → LLM adapters: requests completion (evidence: `src/ytchat/generation/answerer.py`)
- LLM adapters → LLM service: sends prompt (evidence: `src/ytchat/generation/llm.py`)
- CLI and chat → Benchmark datasets: loads benchmarks (evidence: `src/ytchat/cli/app.py`)
- CLI and chat → Evaluation runner: runs evaluation (evidence: `src/ytchat/cli/app.py`)
- Evaluation runner → Benchmark datasets: evaluates cases (evidence: `src/ytchat/evaluation/runner.py`)
- Evaluation runner → Retrieval metrics: scores retrieval (evidence: `src/ytchat/evaluation/runner.py`)
- Evaluation runner → Generation scoring: scores answers (evidence: `src/ytchat/evaluation/runner.py`)
- CLI and chat → Evaluation reports: formats results (evidence: `src/ytchat/cli/app.py`)
