# mjlee0914/rag-enterprise-api-assignment architecture

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

- Interactive diagram: https://gitdiagram.com/mjlee0914/rag-enterprise-api-assignment
- Repository: https://github.com/mjlee0914/rag-enterprise-api-assignment

## Overview

This is a FastAPI enterprise RAG API with three product workflows: policy-document chat, hybrid and personalized product recommendations, and RAGAS evaluation/regression. The graph follows documented endpoints and sampled router/service calls; unsampled implementations are represented only where the README establishes their capabilities. Dashed edges mark external model or storage dependencies whose specific runtime calls were not shown.

Main entry points: [`src/shared/core/vector_store.py`](https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/shared/core/vector_store.py) (Model and vector access), [`src/main.py`](https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/main.py) (FastAPI application), [`src/v1/recommend/router.py`](https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/recommend/router.py) (Recommendation routes), [`src/v1/evaluations/dataset_builder.py`](https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/evaluations/dataset_builder.py) (Golden dataset and outputs)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Shared infrastructure"]
  node_app["FastAPI application<br/>[main.py]"]
  node_config["Configuration<br/>[config.py]"]
  node_vector["Model and vector access<br/>[vector_store.py]"]
  node_response["API response schema<br/>[schemas.py]"]
  node_errors["Exception handling"]
  node_exceptions["Shared exceptions<br/>[exceptions.py]"]
  node_logger["Logging<br/>[logger.py]"]
end

subgraph group_chat["Policy chatbot"]
  node_chat_router["Chatbot routes<br/>[router.py]"]
  node_chunker["Chunking preview<br/>[chunker.py]"]
  node_indexer["Document indexing<br/>[indexer.py]"]
  node_chat_generator["Policy answers<br/>[generator.py]"]
  node_chat_retriever["Policy retrieval<br/>[retriever.py]"]
  node_chat_schemas["Chat request models<br/>[schemas.py]"]
end

subgraph group_recommend["Product recommendations"]
  node_recommend_router["Recommendation routes<br/>[router.py]"]
  node_catalog["Catalog sync<br/>[catalog_loader.py]"]
  node_bm25["BM25 retrieval<br/>[bm25_retriever.py]"]
  node_hybrid["Hybrid RRF search<br/>[hybrid_rrf.py]"]
  node_rewrite["Activity query rewrite<br/>[query_rewrite.py]"]
  node_reranker["Candidate reranking<br/>[reranker.py]"]
  node_recommend_schemas["Recommendation models<br/>[schemas.py]"]
end

subgraph group_evaluation["Evaluation and regression"]
  node_eval_router["Evaluation routes<br/>[router.py]"]
  node_dataset["Golden dataset and outputs<br/>[dataset_builder.py]"]
  node_metrics["RAGAS metrics<br/>[metrics_runner.py]"]
  node_failure["Failure diagnosis"]
  node_regression["Regression service"]
  node_eval_schemas["Evaluation models<br/>[schemas.py]"]
end

node_user(("API client"))
node_database[("PostgreSQL pgvector")]
node_models["LLM and embeddings"]

node_user -->|"sends requests"| node_app
node_app -->|"registers routes"| node_chat_router
node_app -->|"registers routes"| node_recommend_router
node_app -->|"registers routes"| node_eval_router
node_app -->|"loads settings"| node_config
node_app -->|"initializes collections"| node_vector
node_app -->|"registers handlers"| node_errors
node_errors -->|"handles"| node_exceptions
node_errors -->|"formats failures"| node_response
node_errors -->|"logs errors"| node_logger
node_vector -->|"reads settings"| node_config
node_vector -.->|"connects to"| node_database
node_vector -->|"creates clients"| node_models
node_chat_router -->|"previews chunks"| node_chunker
node_chat_router -->|"indexes documents"| node_indexer
node_chat_router -->|"answers questions"| node_chat_generator
node_chat_router -->|"wraps results"| node_response
node_indexer -->|"chunks documents"| node_chunker
node_indexer -->|"stores vectors"| node_vector
node_chat_generator -->|"retrieves context"| node_chat_retriever
node_chat_generator -->|"accesses vector store"| node_vector
node_chat_retriever -->|"searches vectors"| node_vector
node_recommend_router -->|"syncs catalog"| node_catalog
node_recommend_router -->|"runs hybrid search"| node_hybrid
node_recommend_router -->|"rewrites activity query"| node_rewrite
node_recommend_router -->|"reranks candidates"| node_reranker
node_recommend_router -->|"wraps results"| node_response
node_catalog -->|"stores catalog"| node_vector
node_hybrid -->|"gets keyword ranks"| node_bm25
node_hybrid -->|"gets vector ranks"| node_vector
node_rewrite -->|"invokes language model"| node_vector
node_reranker -->|"invokes language model"| node_vector
node_eval_router -->|"loads dataset and outputs"| node_dataset
node_eval_router -->|"runs regression"| node_regression
node_eval_router -->|"wraps results"| node_response
node_dataset -->|"searches candidates"| node_hybrid
node_dataset -->|"rewrites queries"| node_rewrite
node_dataset -->|"reranks candidates"| node_reranker
node_dataset -->|"runs baseline search"| node_vector
node_regression -->|"collects outputs"| node_dataset
node_regression -->|"measures outputs"| node_metrics
node_regression -->|"diagnoses failures"| node_failure
node_metrics -->|"uses vector access"| node_vector

click node_app "https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/main.py"
click node_config "https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/shared/core/config.py"
click node_vector "https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/shared/core/vector_store.py"
click node_response "https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/shared/core/schemas.py"
click node_errors "https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/shared/core/exception_handlers.py"
click node_exceptions "https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/shared/core/exceptions.py"
click node_logger "https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/shared/core/logger.py"
click node_chat_router "https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/chatbot/router.py"
click node_chunker "https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/chatbot/chunker.py"
click node_indexer "https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/chatbot/indexer.py"
click node_chat_generator "https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/chatbot/generator.py"
click node_chat_retriever "https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/chatbot/retriever.py"
click node_chat_schemas "https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/chatbot/schemas.py"
click node_recommend_router "https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/recommend/router.py"
click node_catalog "https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/recommend/catalog_loader.py"
click node_bm25 "https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/recommend/bm25_retriever.py"
click node_hybrid "https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/recommend/hybrid_rrf.py"
click node_rewrite "https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/recommend/query_rewrite.py"
click node_reranker "https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/recommend/reranker.py"
click node_recommend_schemas "https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/recommend/schemas.py"
click node_eval_router "https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/evaluations/router.py"
click node_dataset "https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/evaluations/dataset_builder.py"
click node_metrics "https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/evaluations/metrics_runner.py"
click node_failure "https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/evaluations/failure_analyzer.py"
click node_regression "https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/evaluations/regression_service.py"
click node_eval_schemas "https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/evaluations/schemas.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_app,node_config,node_vector,node_response,node_errors,node_exceptions,node_logger,node_user toneBlue
class node_chat_router,node_chunker,node_indexer,node_chat_generator,node_chat_retriever,node_chat_schemas,node_database toneAmber
class node_recommend_router,node_catalog,node_bm25,node_hybrid,node_rewrite,node_reranker,node_recommend_schemas toneMint
class node_eval_router,node_dataset,node_metrics,node_failure,node_regression,node_eval_schemas toneRose
class node_models toneIndigo
```

## Components

### Shared infrastructure

- [FastAPI application](https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/main.py): `src/main.py`
- [Configuration](https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/shared/core/config.py): `src/shared/core/config.py`
- [Model and vector access](https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/shared/core/vector_store.py): `src/shared/core/vector_store.py`
- [API response schema](https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/shared/core/schemas.py): `src/shared/core/schemas.py`
- [Exception handling](https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/shared/core/exception_handlers.py): `src/shared/core/exception_handlers.py`
- [Shared exceptions](https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/shared/core/exceptions.py): `src/shared/core/exceptions.py`
- [Logging](https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/shared/core/logger.py): `src/shared/core/logger.py`

### Policy chatbot

- [Chatbot routes](https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/chatbot/router.py): `src/v1/chatbot/router.py`
- [Chunking preview](https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/chatbot/chunker.py): `src/v1/chatbot/chunker.py`
- [Document indexing](https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/chatbot/indexer.py): `src/v1/chatbot/indexer.py`
- [Policy answers](https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/chatbot/generator.py): `src/v1/chatbot/generator.py`
- [Policy retrieval](https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/chatbot/retriever.py): `src/v1/chatbot/retriever.py`
- [Chat request models](https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/chatbot/schemas.py): `src/v1/chatbot/schemas.py`

### Product recommendations

- [Recommendation routes](https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/recommend/router.py): `src/v1/recommend/router.py`
- [Catalog sync](https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/recommend/catalog_loader.py): `src/v1/recommend/catalog_loader.py`
- [BM25 retrieval](https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/recommend/bm25_retriever.py): `src/v1/recommend/bm25_retriever.py`
- [Hybrid RRF search](https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/recommend/hybrid_rrf.py): `src/v1/recommend/hybrid_rrf.py`
- [Activity query rewrite](https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/recommend/query_rewrite.py): `src/v1/recommend/query_rewrite.py`
- [Candidate reranking](https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/recommend/reranker.py): `src/v1/recommend/reranker.py`
- [Recommendation models](https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/recommend/schemas.py): `src/v1/recommend/schemas.py`

### Evaluation and regression

- [Evaluation routes](https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/evaluations/router.py): `src/v1/evaluations/router.py`
- [Golden dataset and outputs](https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/evaluations/dataset_builder.py): `src/v1/evaluations/dataset_builder.py`
- [RAGAS metrics](https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/evaluations/metrics_runner.py): `src/v1/evaluations/metrics_runner.py`
- [Failure diagnosis](https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/evaluations/failure_analyzer.py): `src/v1/evaluations/failure_analyzer.py`
- [Regression service](https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/evaluations/regression_service.py): `src/v1/evaluations/regression_service.py`
- [Evaluation models](https://github.com/mjlee0914/rag-enterprise-api-assignment/blob/main/src/v1/evaluations/schemas.py): `src/v1/evaluations/schemas.py`

### Other components

- **API client**
- **PostgreSQL pgvector**
- **LLM and embeddings**

## Connections

- API client → FastAPI application: sends requests (evidence: `README.md`)
- FastAPI application → Chatbot routes: registers routes (evidence: `src/main.py`)
- FastAPI application → Recommendation routes: registers routes (evidence: `src/main.py`)
- FastAPI application → Evaluation routes: registers routes (evidence: `src/main.py`)
- FastAPI application → Configuration: loads settings (evidence: `src/main.py`)
- FastAPI application → Model and vector access: initializes collections (evidence: `src/main.py`)
- FastAPI application → Exception handling: registers handlers (evidence: `src/main.py`)
- Exception handling → Shared exceptions: handles (evidence: `src/shared/core/exception_handlers.py`)
- Exception handling → API response schema: formats failures (evidence: `src/shared/core/exception_handlers.py`)
- Exception handling → Logging: logs errors (evidence: `src/shared/core/exception_handlers.py`)
- Model and vector access → Configuration: reads settings (evidence: `src/shared/core/vector_store.py`)
- Model and vector access → PostgreSQL pgvector: connects to (evidence: `README.md`)
- Model and vector access → LLM and embeddings: creates clients (evidence: `src/shared/core/vector_store.py`)
- Chatbot routes → Chunking preview: previews chunks (evidence: `src/v1/chatbot/router.py`)
- Chatbot routes → Document indexing: indexes documents (evidence: `src/v1/chatbot/router.py`)
- Chatbot routes → Policy answers: answers questions (evidence: `src/v1/chatbot/router.py`)
- Chatbot routes → API response schema: wraps results (evidence: `src/v1/chatbot/router.py`)
- Document indexing → Chunking preview: chunks documents (evidence: `src/v1/chatbot/indexer.py`)
- Document indexing → Model and vector access: stores vectors (evidence: `src/v1/chatbot/indexer.py`)
- Policy answers → Policy retrieval: retrieves context (evidence: `src/v1/chatbot/generator.py`)
- Policy answers → Model and vector access: accesses vector store (evidence: `src/v1/chatbot/generator.py`)
- Policy retrieval → Model and vector access: searches vectors (evidence: `src/v1/chatbot/retriever.py`)
- Recommendation routes → Catalog sync: syncs catalog (evidence: `src/v1/recommend/router.py`)
- Recommendation routes → Hybrid RRF search: runs hybrid search (evidence: `src/v1/recommend/router.py`)
- Recommendation routes → Activity query rewrite: rewrites activity query (evidence: `src/v1/recommend/router.py`)
- Recommendation routes → Candidate reranking: reranks candidates (evidence: `src/v1/recommend/router.py`)
- Recommendation routes → API response schema: wraps results (evidence: `src/v1/recommend/router.py`)
- Catalog sync → Model and vector access: stores catalog (evidence: `src/v1/recommend/catalog_loader.py`)
- Hybrid RRF search → BM25 retrieval: gets keyword ranks (evidence: `src/v1/recommend/hybrid_rrf.py`)
- Hybrid RRF search → Model and vector access: gets vector ranks (evidence: `src/v1/recommend/hybrid_rrf.py`)
- Activity query rewrite → Model and vector access: invokes language model (evidence: `src/v1/recommend/query_rewrite.py`)
- Candidate reranking → Model and vector access: invokes language model (evidence: `src/v1/recommend/reranker.py`)
- Evaluation routes → Golden dataset and outputs: loads dataset and outputs (evidence: `src/v1/evaluations/router.py`)
- Evaluation routes → Regression service: runs regression (evidence: `src/v1/evaluations/router.py`)
- Evaluation routes → API response schema: wraps results (evidence: `src/v1/evaluations/router.py`)
- Golden dataset and outputs → Hybrid RRF search: searches candidates (evidence: `src/v1/evaluations/dataset_builder.py`)
- Golden dataset and outputs → Activity query rewrite: rewrites queries (evidence: `src/v1/evaluations/dataset_builder.py`)
- Golden dataset and outputs → Candidate reranking: reranks candidates (evidence: `src/v1/evaluations/dataset_builder.py`)
- Golden dataset and outputs → Model and vector access: runs baseline search (evidence: `src/v1/evaluations/dataset_builder.py`)
- Regression service → Golden dataset and outputs: collects outputs (evidence: `src/v1/evaluations/regression_service.py`)
- Regression service → RAGAS metrics: measures outputs (evidence: `src/v1/evaluations/regression_service.py`)
- Regression service → Failure diagnosis: diagnoses failures (evidence: `src/v1/evaluations/regression_service.py`)
- RAGAS metrics → Model and vector access: uses vector access (evidence: `src/v1/evaluations/metrics_runner.py`)
