# ayshasharaf/rag-knowledge-base architecture

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

- Interactive diagram: https://gitdiagram.com/ayshasharaf/rag-knowledge-base
- Repository: https://github.com/ayshasharaf/rag-knowledge-base

## Overview

This is a PDF-based RAG knowledge-base API. A user uploads a PDF; the API saves it and invokes indexing, which loads and splits the document, embeds its chunks, and writes them to Pinecone. For questions, the API invokes retrieval and then answer generation with the retrieved context, returning the answer and source chunks. The README documents these capabilities; the sampled source confirms the main call and data flows shown here.

Main entry points: [`app/main.py`](https://github.com/ayshasharaf/rag-knowledge-base/blob/main/app/main.py) (FastAPI routes), [`app/ingestor.py`](https://github.com/ayshasharaf/rag-knowledge-base/blob/main/app/ingestor.py) (Document ingestor), [`app/retriever.py`](https://github.com/ayshasharaf/rag-knowledge-base/blob/main/app/retriever.py) (Chunk retriever), [`app/generator.py`](https://github.com/ayshasharaf/rag-knowledge-base/blob/main/app/generator.py) (Answer generator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API"]
  node_api["FastAPI routes<br/>[main.py]"]
end

subgraph group_indexing["Document indexing"]
  node_files["Uploaded PDFs<br/>[main.py]"]
  node_ingestor["Document ingestor<br/>[ingestor.py]"]
  node_pdf_loader["PDF loader<br/>[ingestor.py]"]
  node_splitter["Text splitter<br/>[ingestor.py]"]
  node_embeddings["Embedding encoder<br/>[ingestor.py]"]
  node_pinecone[("Pinecone index<br/>[ingestor.py]")]
end

subgraph group_answers["Question answering"]
  node_retriever["Chunk retriever<br/>[retriever.py]"]
  node_generator["Answer generator<br/>[generator.py]"]
  node_hf_chat["Hugging Face chat API"]
end

node_user(("User"))

node_user -->|"uploads PDF"| node_api
node_user -->|"asks question"| node_api
node_api -->|"writes file"| node_files
node_api -->|"indexes file"| node_ingestor
node_ingestor -->|"loads PDF"| node_pdf_loader
node_pdf_loader -->|"supplies pages"| node_splitter
node_ingestor -->|"splits documents"| node_splitter
node_ingestor -->|"embeds chunks"| node_embeddings
node_ingestor -->|"upserts vectors"| node_pinecone
node_api -->|"retrieves context"| node_retriever
node_retriever -->|"embeds question"| node_embeddings
node_retriever -->|"queries vectors"| node_pinecone
node_pinecone -->|"returns matches"| node_retriever
node_api -->|"generates answer"| node_generator
node_generator -->|"requests completion"| node_hf_chat
node_hf_chat -->|"returns completion"| node_generator
node_generator -->|"returns answer"| node_api
node_api -->|"returns result"| node_user

click node_api "https://github.com/ayshasharaf/rag-knowledge-base/blob/main/app/main.py"
click node_files "https://github.com/ayshasharaf/rag-knowledge-base/blob/main/app/main.py"
click node_ingestor "https://github.com/ayshasharaf/rag-knowledge-base/blob/main/app/ingestor.py"
click node_pdf_loader "https://github.com/ayshasharaf/rag-knowledge-base/blob/main/app/ingestor.py"
click node_splitter "https://github.com/ayshasharaf/rag-knowledge-base/blob/main/app/ingestor.py"
click node_embeddings "https://github.com/ayshasharaf/rag-knowledge-base/blob/main/app/ingestor.py"
click node_pinecone "https://github.com/ayshasharaf/rag-knowledge-base/blob/main/app/ingestor.py"
click node_retriever "https://github.com/ayshasharaf/rag-knowledge-base/blob/main/app/retriever.py"
click node_generator "https://github.com/ayshasharaf/rag-knowledge-base/blob/main/app/generator.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_api,node_user toneBlue
class node_files,node_ingestor,node_pdf_loader,node_splitter,node_embeddings,node_pinecone toneAmber
class node_retriever,node_generator,node_hf_chat toneMint
```

## Components

### API

- [FastAPI routes](https://github.com/ayshasharaf/rag-knowledge-base/blob/main/app/main.py): `app/main.py`

### Document indexing

- [Uploaded PDFs](https://github.com/ayshasharaf/rag-knowledge-base/blob/main/app/main.py): `app/main.py`
- [Document ingestor](https://github.com/ayshasharaf/rag-knowledge-base/blob/main/app/ingestor.py): `app/ingestor.py`
- [PDF loader](https://github.com/ayshasharaf/rag-knowledge-base/blob/main/app/ingestor.py): `app/ingestor.py`
- [Text splitter](https://github.com/ayshasharaf/rag-knowledge-base/blob/main/app/ingestor.py): `app/ingestor.py`
- [Embedding encoder](https://github.com/ayshasharaf/rag-knowledge-base/blob/main/app/ingestor.py): `app/ingestor.py`
- [Pinecone index](https://github.com/ayshasharaf/rag-knowledge-base/blob/main/app/ingestor.py): `app/ingestor.py`

### Question answering

- [Chunk retriever](https://github.com/ayshasharaf/rag-knowledge-base/blob/main/app/retriever.py): `app/retriever.py`
- [Answer generator](https://github.com/ayshasharaf/rag-knowledge-base/blob/main/app/generator.py): `app/generator.py`
- **Hugging Face chat API**

### Other components

- **User**

## Connections

- User → FastAPI routes: uploads PDF
- User → FastAPI routes: asks question
- FastAPI routes → Uploaded PDFs: writes file
- FastAPI routes → Document ingestor: indexes file
- Document ingestor → PDF loader: loads PDF
- PDF loader → Text splitter: supplies pages
- Document ingestor → Text splitter: splits documents
- Document ingestor → Embedding encoder: embeds chunks
- Document ingestor → Pinecone index: upserts vectors
- FastAPI routes → Chunk retriever: retrieves context
- Chunk retriever → Embedding encoder: embeds question
- Chunk retriever → Pinecone index: queries vectors
- Pinecone index → Chunk retriever: returns matches
- FastAPI routes → Answer generator: generates answer
- Answer generator → Hugging Face chat API: requests completion
- Hugging Face chat API → Answer generator: returns completion
- Answer generator → FastAPI routes: returns answer
- FastAPI routes → User: returns result
