# atharva-kulkarni123/aws-rag-pipeline architecture

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

- Interactive diagram: https://gitdiagram.com/atharva-kulkarni123/aws-rag-pipeline
- Repository: https://github.com/atharva-kulkarni123/aws-rag-pipeline

## Overview

This repository provides an AWS-hosted RAG API: clients submit PDFs for ingestion or ask questions grounded in ingested documents. The API routes dispatch ingestion into PDF extraction, chunking, embedding, and storage; query handling runs retrieval, reranking, prompt construction, and answer generation. The README also documents AWS infrastructure and a one-time database bootstrap, but sampled infrastructure source was not provided, so those deployment components are represented only at a high level. Relationships for internal query helpers rely on the excerpted RAG orchestrator; other unshown details are omitted.

Main entry points: [`RAG-codebase/api/main.py`](https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/api/main.py) (FastAPI app), [`RAG-codebase/RAG-Ingestion/ingestion/ingestion.py`](https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/RAG-Ingestion/ingestion/ingestion.py) (Ingestion orchestration), [`RAG-codebase/RAG-Retrieval/rag_service.py`](https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/RAG-Retrieval/rag_service.py) (RAG orchestration), [`RAG-codebase/api/routes/query.py`](https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/api/routes/query.py) (Query route)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API"]
  node_api_app["FastAPI app<br/>[main.py]"]
  node_query_route["Query route<br/>[query.py]"]
  node_ingest_route["Ingest route<br/>[ingest.py]"]
  node_api_models["Request and response models"]
  node_auth["Cognito auth middleware<br/>[auth.py]"]
  node_logging["Request logging<br/>[logging.py]"]
end

subgraph group_ingest["Ingestion"]
  node_ingest_runner["Ingestion entry point<br/>[run_ingestion.py]"]
  node_ingestion_service["Ingestion orchestration<br/>[ingestion.py]"]
  node_s3["S3 document access<br/>[s3_client.py]"]
  node_pdf["PDF page extraction<br/>[pdf_processor.py]"]
  node_chunker["Text chunking<br/>[chunker.py]"]
  node_ingest_embed["Titan embeddings<br/>[embedding.py]"]
  node_ingest_db[("Chunk vector storage<br/>[vectordb.py]")]
end

subgraph group_retrieve["Retrieval and Generation"]
  node_rag_service["RAG orchestration<br/>[rag_service.py]"]
  node_query_embed["Query embeddings<br/>[embeddings.py]"]
  node_retriever["Vector retrieval<br/>[retriever.py]"]
  node_vector_store[("Postgres vector store<br/>[vector_store.py]")]
  node_reranker["Result reranking<br/>[reranker.py]"]
  node_prompt["Prompt construction<br/>[prompt.py]"]
  node_llm["Answer generation<br/>[llm.py]"]
end

subgraph group_platform["AWS Platform"]
  node_bedrock["Amazon Bedrock"]
  node_s3_service["Amazon S3"]
  node_rds[("RDS PostgreSQL pgvector")]
  node_aws_stack["AWS network and ECS"]
  node_db_bootstrap["Database bootstrap<br/>[schema.sql]"]
end

node_client(("API client"))

node_client -->|"sends requests"| node_api_app
node_api_app -->|"applies middleware"| node_auth
node_api_app -->|"applies middleware"| node_logging
node_api_app -->|"registers route"| node_query_route
node_api_app -->|"registers route"| node_ingest_route
node_api_app -->|"initializes at startup"| node_rag_service
node_query_route -->|"calls answer"| node_rag_service
node_query_route -->|"uses schemas"| node_api_models
node_ingest_route -->|"uses schemas"| node_api_models
node_ingest_route -->|"dispatches ingestion"| node_ingest_runner
node_ingest_runner -->|"creates and runs"| node_ingestion_service
node_ingestion_service -->|"lists and downloads"| node_s3
node_s3 -->|"reads PDFs"| node_s3_service
node_ingestion_service -->|"extracts pages"| node_pdf
node_ingestion_service -->|"creates chunks"| node_chunker
node_ingestion_service -->|"embeds chunks"| node_ingest_embed
node_ingestion_service -->|"stores chunks"| node_ingest_db
node_ingest_embed -->|"invokes model"| node_bedrock
node_ingest_db -->|"writes vectors"| node_rds
node_rag_service -->|"retrieves documents"| node_retriever
node_retriever -->|"embeds question"| node_query_embed
node_retriever -->|"searches vectors"| node_vector_store
node_vector_store -->|"searches chunks"| node_rds
node_rag_service -->|"reranks results"| node_reranker
node_rag_service -->|"builds prompt"| node_prompt
node_rag_service -->|"generates answer"| node_llm
node_query_embed -->|"invokes embeddings"| node_bedrock
node_llm -->|"requests answer"| node_bedrock
node_aws_stack -->|"hosts privately"| node_api_app
node_aws_stack -->|"provisions database"| node_rds
node_db_bootstrap -->|"creates schema"| node_rds

click node_api_app "https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/api/main.py"
click node_query_route "https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/api/routes/query.py"
click node_ingest_route "https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/api/routes/ingest.py"
click node_api_models "https://github.com/atharva-kulkarni123/aws-rag-pipeline/tree/main/RAG-codebase/api/models"
click node_auth "https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/api/middleware/auth.py"
click node_logging "https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/api/middleware/logging.py"
click node_ingest_runner "https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/RAG-Ingestion/run_ingestion.py"
click node_ingestion_service "https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/RAG-Ingestion/ingestion/ingestion.py"
click node_s3 "https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/RAG-Ingestion/s3_client.py"
click node_pdf "https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/RAG-Ingestion/pdf_processor.py"
click node_chunker "https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/RAG-Ingestion/ingestion/chunker.py"
click node_ingest_embed "https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/RAG-Ingestion/embedding/embedding.py"
click node_ingest_db "https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/RAG-Ingestion/vectorstore/vectordb.py"
click node_rag_service "https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/RAG-Retrieval/rag_service.py"
click node_query_embed "https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/RAG-Retrieval/embeddings.py"
click node_retriever "https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/RAG-Retrieval/retriever.py"
click node_vector_store "https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/RAG-Retrieval/vector_store.py"
click node_reranker "https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/RAG-Retrieval/reranker.py"
click node_prompt "https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/RAG-Retrieval/prompt.py"
click node_llm "https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/RAG-Retrieval/llm.py"
click node_aws_stack "https://github.com/atharva-kulkarni123/aws-rag-pipeline/tree/main/Terraform"
click node_db_bootstrap "https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/ansible/sql/schema.sql"

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_api_app,node_query_route,node_ingest_route,node_api_models,node_auth,node_logging,node_client toneBlue
class node_ingest_runner,node_ingestion_service,node_s3,node_pdf,node_chunker,node_ingest_embed,node_ingest_db toneAmber
class node_rag_service,node_query_embed,node_retriever,node_vector_store,node_reranker,node_prompt,node_llm toneMint
class node_bedrock,node_s3_service,node_rds,node_aws_stack,node_db_bootstrap toneRose
```

## Components

### API

- [FastAPI app](https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/api/main.py): `RAG-codebase/api/main.py`
- [Query route](https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/api/routes/query.py): `RAG-codebase/api/routes/query.py`
- [Ingest route](https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/api/routes/ingest.py): `RAG-codebase/api/routes/ingest.py`
- [Request and response models](https://github.com/atharva-kulkarni123/aws-rag-pipeline/tree/main/RAG-codebase/api/models): `RAG-codebase/api/models`
- [Cognito auth middleware](https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/api/middleware/auth.py): `RAG-codebase/api/middleware/auth.py`
- [Request logging](https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/api/middleware/logging.py): `RAG-codebase/api/middleware/logging.py`

### Ingestion

- [Ingestion entry point](https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/RAG-Ingestion/run_ingestion.py): `RAG-codebase/RAG-Ingestion/run_ingestion.py`
- [Ingestion orchestration](https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/RAG-Ingestion/ingestion/ingestion.py): `RAG-codebase/RAG-Ingestion/ingestion/ingestion.py`
- [S3 document access](https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/RAG-Ingestion/s3_client.py): `RAG-codebase/RAG-Ingestion/s3_client.py`
- [PDF page extraction](https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/RAG-Ingestion/pdf_processor.py): `RAG-codebase/RAG-Ingestion/pdf_processor.py`
- [Text chunking](https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/RAG-Ingestion/ingestion/chunker.py): `RAG-codebase/RAG-Ingestion/ingestion/chunker.py`
- [Titan embeddings](https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/RAG-Ingestion/embedding/embedding.py): `RAG-codebase/RAG-Ingestion/embedding/embedding.py`
- [Chunk vector storage](https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/RAG-Ingestion/vectorstore/vectordb.py): `RAG-codebase/RAG-Ingestion/vectorstore/vectordb.py`

### Retrieval and Generation

- [RAG orchestration](https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/RAG-Retrieval/rag_service.py): `RAG-codebase/RAG-Retrieval/rag_service.py`
- [Query embeddings](https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/RAG-Retrieval/embeddings.py): `RAG-codebase/RAG-Retrieval/embeddings.py`
- [Vector retrieval](https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/RAG-Retrieval/retriever.py): `RAG-codebase/RAG-Retrieval/retriever.py`
- [Postgres vector store](https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/RAG-Retrieval/vector_store.py): `RAG-codebase/RAG-Retrieval/vector_store.py`
- [Result reranking](https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/RAG-Retrieval/reranker.py): `RAG-codebase/RAG-Retrieval/reranker.py`
- [Prompt construction](https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/RAG-Retrieval/prompt.py): `RAG-codebase/RAG-Retrieval/prompt.py`
- [Answer generation](https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/RAG-codebase/RAG-Retrieval/llm.py): `RAG-codebase/RAG-Retrieval/llm.py`

### AWS Platform

- **Amazon Bedrock**
- **Amazon S3**
- **RDS PostgreSQL pgvector**
- [AWS network and ECS](https://github.com/atharva-kulkarni123/aws-rag-pipeline/tree/main/Terraform): `Terraform`
- [Database bootstrap](https://github.com/atharva-kulkarni123/aws-rag-pipeline/blob/main/ansible/sql/schema.sql): `ansible/sql/schema.sql`

### Other components

- **API client**

## Connections

- API client → FastAPI app: sends requests (evidence: `README.md`)
- FastAPI app → Cognito auth middleware: applies middleware (evidence: `RAG-codebase/api/main.py`)
- FastAPI app → Request logging: applies middleware (evidence: `RAG-codebase/api/main.py`)
- FastAPI app → Query route: registers route (evidence: `RAG-codebase/api/main.py`)
- FastAPI app → Ingest route: registers route (evidence: `RAG-codebase/api/main.py`)
- FastAPI app → RAG orchestration: initializes at startup (evidence: `RAG-codebase/api/main.py`)
- Query route → RAG orchestration: calls answer (evidence: `RAG-codebase/api/routes/query.py`)
- Query route → Request and response models: uses schemas (evidence: `RAG-codebase/api/routes/query.py`)
- Ingest route → Request and response models: uses schemas (evidence: `RAG-codebase/api/routes/ingest.py`)
- Ingest route → Ingestion entry point: dispatches ingestion (evidence: `RAG-codebase/api/routes/ingest.py`)
- Ingestion entry point → Ingestion orchestration: creates and runs (evidence: `RAG-codebase/RAG-Ingestion/run_ingestion.py`)
- Ingestion orchestration → S3 document access: lists and downloads (evidence: `RAG-codebase/RAG-Ingestion/ingestion/ingestion.py`)
- S3 document access → Amazon S3: reads PDFs (evidence: `RAG-codebase/RAG-Ingestion/s3_client.py`)
- Ingestion orchestration → PDF page extraction: extracts pages (evidence: `RAG-codebase/RAG-Ingestion/ingestion/ingestion.py`)
- Ingestion orchestration → Text chunking: creates chunks (evidence: `RAG-codebase/RAG-Ingestion/ingestion/ingestion.py`)
- Ingestion orchestration → Titan embeddings: embeds chunks (evidence: `RAG-codebase/RAG-Ingestion/ingestion/ingestion.py`)
- Ingestion orchestration → Chunk vector storage: stores chunks (evidence: `RAG-codebase/RAG-Ingestion/ingestion/ingestion.py`)
- Titan embeddings → Amazon Bedrock: invokes model (evidence: `RAG-codebase/RAG-Ingestion/embedding/embedding.py`)
- Chunk vector storage → RDS PostgreSQL pgvector: writes vectors (evidence: `README.md`)
- RAG orchestration → Vector retrieval: retrieves documents (evidence: `RAG-codebase/RAG-Retrieval/rag_service.py`)
- Vector retrieval → Query embeddings: embeds question (evidence: `RAG-codebase/RAG-Retrieval/rag_service.py`)
- Vector retrieval → Postgres vector store: searches vectors (evidence: `RAG-codebase/RAG-Retrieval/rag_service.py`)
- Postgres vector store → RDS PostgreSQL pgvector: searches chunks (evidence: `README.md`)
- RAG orchestration → Result reranking: reranks results (evidence: `RAG-codebase/RAG-Retrieval/rag_service.py`)
- RAG orchestration → Prompt construction: builds prompt (evidence: `RAG-codebase/RAG-Retrieval/rag_service.py`)
- RAG orchestration → Answer generation: generates answer (evidence: `RAG-codebase/RAG-Retrieval/rag_service.py`)
- Query embeddings → Amazon Bedrock: invokes embeddings (evidence: `RAG-codebase/RAG-Retrieval/embeddings.py`)
- Answer generation → Amazon Bedrock: requests answer (evidence: `README.md`)
- AWS network and ECS → FastAPI app: hosts privately (evidence: `README.md`)
- AWS network and ECS → RDS PostgreSQL pgvector: provisions database (evidence: `README.md`)
- Database bootstrap → RDS PostgreSQL pgvector: creates schema (evidence: `README.md`)
