# jacksonsouza99/ai-document-assistant architecture

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

- Interactive diagram: https://gitdiagram.com/jacksonsouza99/ai-document-assistant
- Repository: https://github.com/jacksonsouza99/ai-document-assistant

## Overview

AI Document Assistant is a Python RAG application: it ingests PDF text into a persistent vector collection, then retrieves relevant passages to ground Gemini answers. The primary workflow runs from PDF ingestion through retrieval and response generation; a separate query script prints retrieved passages without generating an answer. The embedding demonstration and database-cleanup script are peripheral to that workflow. Edges reflect the shown calls and documented behavior; the graph does not assume relationships for unsampled code.

Main entry points: [`app/ask.py`](https://github.com/jacksonsouza99/ai-document-assistant/blob/main/app/ask.py) (Question workflow), [`app/vector_store.py`](https://github.com/jacksonsouza99/ai-document-assistant/blob/main/app/vector_store.py) (Ingestion runner), [`app/llm.py`](https://github.com/jacksonsouza99/ai-document-assistant/blob/main/app/llm.py) (Answer generation), [`app/query.py`](https://github.com/jacksonsouza99/ai-document-assistant/blob/main/app/query.py) (Passage query script)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["PDF ingestion"]
  node_ingest_runner["Ingestion runner<br/>[vector_store.py]"]
  node_pdf_reader["PDF text extraction<br/>[reader.py]"]
  node_chunker["Text chunking<br/>[chunker.py]"]
  node_ingest_embeddings["Chunk embeddings<br/>[vector_store.py]"]
end

subgraph group_answer["Question answering"]
  node_question_flow["Question workflow<br/>[ask.py]"]
  node_question_embeddings["Question embeddings<br/>[ask.py]"]
  node_semantic_search["Semantic retrieval<br/>[ask.py]"]
  node_context_builder["Context assembly<br/>[ask.py]"]
  node_answer_generator["Answer generation<br/>[llm.py]"]
  node_passage_query["Passage query script<br/>[query.py]"]
end

subgraph group_storage["Vector storage"]
  node_vector_db[("Chroma collection<br/>[vector_store.py]")]
end

node_user(("User"))
node_pdf["PDF document"]
node_gemini{{"Gemini API"}}

node_user -.->|"starts ingestion"| node_ingest_runner
node_pdf -.->|"provides PDF"| node_ingest_runner
node_ingest_runner -->|"extracts text"| node_pdf_reader
node_ingest_runner -->|"splits text"| node_chunker
node_ingest_runner -->|"encodes chunks"| node_ingest_embeddings
node_ingest_runner -->|"upserts vectors"| node_vector_db
node_user -->|"asks question"| node_question_flow
node_question_flow -->|"encodes question"| node_question_embeddings
node_question_flow -->|"queries collection"| node_semantic_search
node_semantic_search -->|"uses embedding"| node_question_embeddings
node_semantic_search -->|"retrieves passages"| node_vector_db
node_question_flow -->|"assembles context"| node_context_builder
node_question_flow -->|"requests answer"| node_answer_generator
node_answer_generator -->|"generates response"| node_gemini
node_question_flow -->|"prints answer"| node_user
node_user -->|"enters question"| node_passage_query
node_passage_query -->|"queries collection"| node_vector_db

click node_ingest_runner "https://github.com/jacksonsouza99/ai-document-assistant/blob/main/app/vector_store.py"
click node_pdf_reader "https://github.com/jacksonsouza99/ai-document-assistant/blob/main/app/reader.py"
click node_chunker "https://github.com/jacksonsouza99/ai-document-assistant/blob/main/app/chunker.py"
click node_ingest_embeddings "https://github.com/jacksonsouza99/ai-document-assistant/blob/main/app/vector_store.py"
click node_vector_db "https://github.com/jacksonsouza99/ai-document-assistant/blob/main/app/vector_store.py"
click node_question_flow "https://github.com/jacksonsouza99/ai-document-assistant/blob/main/app/ask.py"
click node_question_embeddings "https://github.com/jacksonsouza99/ai-document-assistant/blob/main/app/ask.py"
click node_semantic_search "https://github.com/jacksonsouza99/ai-document-assistant/blob/main/app/ask.py"
click node_context_builder "https://github.com/jacksonsouza99/ai-document-assistant/blob/main/app/ask.py"
click node_answer_generator "https://github.com/jacksonsouza99/ai-document-assistant/blob/main/app/llm.py"
click node_passage_query "https://github.com/jacksonsouza99/ai-document-assistant/blob/main/app/query.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_ingest_runner,node_pdf_reader,node_chunker,node_ingest_embeddings,node_user toneBlue
class node_question_flow,node_question_embeddings,node_semantic_search,node_context_builder,node_answer_generator,node_passage_query toneAmber
class node_vector_db,node_gemini toneMint
class node_pdf toneIndigo
```

## Components

### PDF ingestion

- [Ingestion runner](https://github.com/jacksonsouza99/ai-document-assistant/blob/main/app/vector_store.py): `app/vector_store.py`
- [PDF text extraction](https://github.com/jacksonsouza99/ai-document-assistant/blob/main/app/reader.py): `app/reader.py`
- [Text chunking](https://github.com/jacksonsouza99/ai-document-assistant/blob/main/app/chunker.py): `app/chunker.py`
- [Chunk embeddings](https://github.com/jacksonsouza99/ai-document-assistant/blob/main/app/vector_store.py): `app/vector_store.py`

### Question answering

- [Question workflow](https://github.com/jacksonsouza99/ai-document-assistant/blob/main/app/ask.py): `app/ask.py`
- [Question embeddings](https://github.com/jacksonsouza99/ai-document-assistant/blob/main/app/ask.py): `app/ask.py`
- [Semantic retrieval](https://github.com/jacksonsouza99/ai-document-assistant/blob/main/app/ask.py): `app/ask.py`
- [Context assembly](https://github.com/jacksonsouza99/ai-document-assistant/blob/main/app/ask.py): `app/ask.py`
- [Answer generation](https://github.com/jacksonsouza99/ai-document-assistant/blob/main/app/llm.py): `app/llm.py`
- [Passage query script](https://github.com/jacksonsouza99/ai-document-assistant/blob/main/app/query.py): `app/query.py`

### Vector storage

- [Chroma collection](https://github.com/jacksonsouza99/ai-document-assistant/blob/main/app/vector_store.py): `app/vector_store.py`

### Other components

- **User**
- **PDF document**
- **Gemini API**

## Connections

- User → Ingestion runner: starts ingestion (evidence: `README.md`)
- PDF document → Ingestion runner: provides PDF (evidence: `README.md`)
- Ingestion runner → PDF text extraction: extracts text (evidence: `app/vector_store.py`)
- Ingestion runner → Text chunking: splits text (evidence: `app/vector_store.py`)
- Ingestion runner → Chunk embeddings: encodes chunks (evidence: `app/vector_store.py`)
- Ingestion runner → Chroma collection: upserts vectors (evidence: `app/vector_store.py`)
- User → Question workflow: asks question (evidence: `app/ask.py`)
- Question workflow → Question embeddings: encodes question (evidence: `app/ask.py`)
- Question workflow → Semantic retrieval: queries collection (evidence: `app/ask.py`)
- Semantic retrieval → Question embeddings: uses embedding (evidence: `app/ask.py`)
- Semantic retrieval → Chroma collection: retrieves passages (evidence: `app/ask.py`)
- Question workflow → Context assembly: assembles context (evidence: `app/ask.py`)
- Question workflow → Answer generation: requests answer (evidence: `app/ask.py`)
- Answer generation → Gemini API: generates response (evidence: `app/llm.py`)
- Question workflow → User: prints answer (evidence: `app/ask.py`)
- User → Passage query script: enters question (evidence: `app/query.py`)
- Passage query script → Chroma collection: queries collection (evidence: `app/query.py`)
