# felipetds/projeto-ia-rag architecture

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

- Interactive diagram: https://gitdiagram.com/felipetds/projeto-ia-rag
- Repository: https://github.com/felipetds/projeto-ia-rag

## Overview

#### Purpose and Entry Point
This is a local Python RAG-ingestion pipeline for Markdown product manuals. It discovers unprocessed manuals, splits them by Markdown structure, enriches chunks with size/token metrics, and writes JSON artifacts suitable for later vector-store ingestion. The operational entry point is `src/main.py`.

#### Input Discovery and Incremental Control
Manuals are the source-of-truth inputs under `src/data/base_manuais/`, such as `src/data/base_manuais/manual maquina de lavar.md`. `src/buscador.py` scans and validates Markdown inputs. `src/verificar_arquivos.py` compares discovered files against the persisted processing history in `src/data/verificar_arquivos/arquivos_injetados.json`, preventing repeat ingestion.

#### Chunking Stage
`src/gerar_chunks.py` performs the semantic Markdown split, preserving heading hierarchy (`#`, `##`, `###`) as context rather than treating files as arbitrary text. It uses LangChain text-splitter functionality, making this the main transformation boundary between raw manuals and retrieval-ready records.

#### Chunk Enrichment
Each generated text block is augmented with control metadata, notably character count and OpenAI-token count. This responsibility is isolated in `src/infos_chunks.py`; token estimation uses `tiktoken`. These metrics support embedding/cost planning, but this repository does not itself show embedding generation or vector-database writes.

#### Persistence and Pipeline Outputs
The orchestrator in `src/main.py` coordinates discovery, history filtering, splitting, metadata generation, JSON output, and history updates. Processed chunks are persisted at `src/data/chunks_processados/chunks_finais.json`; the processed-file ledger is updated at `src/data/verificar_arquivos/arquivos_injetados.json`. Both are local filesystem boundaries and enable repeatable incremental runs.

#### Runtime and External Dependencies
The runtime is Python 3.12+ with dependencies declared in `requirements.txt`. Material libraries are LangChain text splitters and `tiktoken`; `pathlib` supports path-safe local file handling. The README specifies OpenAI environment variables (`OPENAI_API_KEY`, `OPENAI_MODEL`), but the described pipeline’s concrete output is local JSON, so OpenAI is primarily a configured downstream embedding/tokenization concern rather than a demonstrated persistence service.

#### End-to-End Control Flow
`src/main.py` processes: Markdown files in `src/data/base_manuais/` → discovery/validation in `src/buscador.py` → deduplication through `src/verificar_arquivos.py` and its JSON ledger → semantic splitting in `src/gerar_chunks.py` → token/character enrichment in `src/infos_chunks.py` → chunk JSON and updated ingestion history. The key contract for downstream RAG infrastructure is `src/data/chunks_processados/chunks_finais.json`.

Main entry points: [`src/main.py`](https://github.com/felipetds/projeto-ia-rag/blob/main/src/main.py) (Pipeline orchestrator), [`src/gerar_chunks.py`](https://github.com/felipetds/projeto-ia-rag/blob/main/src/gerar_chunks.py) (Semantic Markdown split), [`src/infos_chunks.py`](https://github.com/felipetds/projeto-ia-rag/blob/main/src/infos_chunks.py) (Chunk metrics), [`src/buscador.py`](https://github.com/felipetds/projeto-ia-rag/blob/main/src/buscador.py) (Discovery & validation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Manual Inputs"]
  node_manuals["Markdown manuals<br/>source documents"]
end

subgraph group_pipeline["Ingestion Pipeline"]
  node_main["Pipeline orchestrator<br/>Python entry point<br/>[main.py]"]
  node_discovery["Discovery &amp; validation<br/>Python module<br/>[buscador.py]"]
  node_history_filter["Incremental filter<br/>Python module"]
  node_chunking["Semantic Markdown split<br/>Python module<br/>[gerar_chunks.py]"]
  node_langchain{{"LangChain splitters<br/>[requirements.txt]"}}
  node_enrichment["Chunk metrics<br/>Python module<br/>[infos_chunks.py]"]
  node_tiktoken{{"tiktoken<br/>[requirements.txt]"}}
  node_python_runtime{{"Python 3.12+ runtime<br/>[requirements.txt]"}}
end

subgraph group_storage["Local JSON State"]
  node_chunk_output["Final chunks JSON<br/>pipeline artifact<br/>[chunks_finais.json]"]
  node_history_ledger["Processed-file ledger<br/>JSON state"]
end

node_downstream_rag(("Future vector ingestion<br/>external downstream"))

node_python_runtime -->|"runs"| node_main
node_main -->|"discovers"| node_discovery
node_manuals -->|"scanned inputs"| node_discovery
node_discovery -->|"validated manuals"| node_history_filter
node_history_ledger -->|"prior history"| node_history_filter
node_history_filter -->|"unprocessed manuals"| node_chunking
node_chunking -.->|"uses"| node_langchain
node_chunking -->|"text blocks"| node_enrichment
node_enrichment -.->|"counts tokens with"| node_tiktoken
node_enrichment -->|"writes enriched chunks"| node_chunk_output
node_main -->|"updates after processing"| node_history_ledger
node_chunk_output -.->|"retrieval-ready records"| node_downstream_rag

click node_main "https://github.com/felipetds/projeto-ia-rag/blob/main/src/main.py"
click node_discovery "https://github.com/felipetds/projeto-ia-rag/blob/main/src/buscador.py"
click node_history_filter "https://github.com/felipetds/projeto-ia-rag/blob/main/src/verificar_arquivos.py"
click node_chunking "https://github.com/felipetds/projeto-ia-rag/blob/main/src/gerar_chunks.py"
click node_langchain "https://github.com/felipetds/projeto-ia-rag/blob/main/requirements.txt"
click node_enrichment "https://github.com/felipetds/projeto-ia-rag/blob/main/src/infos_chunks.py"
click node_tiktoken "https://github.com/felipetds/projeto-ia-rag/blob/main/requirements.txt"
click node_chunk_output "https://github.com/felipetds/projeto-ia-rag/blob/main/src/data/chunks_processados/chunks_finais.json"
click node_history_ledger "https://github.com/felipetds/projeto-ia-rag/blob/main/src/data/verificar_arquivos/arquivos_injetados.json"
click node_python_runtime "https://github.com/felipetds/projeto-ia-rag/blob/main/requirements.txt"

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_manuals toneBlue
class node_main,node_discovery,node_history_filter,node_chunking,node_langchain,node_enrichment,node_tiktoken,node_python_runtime toneAmber
class node_chunk_output,node_history_ledger toneMint
class node_downstream_rag toneNeutral
```

## Components

### Manual Inputs

- **Markdown manuals**: source documents · Source-of-truth product manuals.

### Ingestion Pipeline

- [Pipeline orchestrator](https://github.com/felipetds/projeto-ia-rag/blob/main/src/main.py): Python entry point · Coordinates the incremental ingestion run. · `src/main.py`
- [Discovery & validation](https://github.com/felipetds/projeto-ia-rag/blob/main/src/buscador.py): Python module · `src/buscador.py`
- [Incremental filter](https://github.com/felipetds/projeto-ia-rag/blob/main/src/verificar_arquivos.py): Python module · Excludes manuals already recorded as processed. · `src/verificar_arquivos.py`
- [Semantic Markdown split](https://github.com/felipetds/projeto-ia-rag/blob/main/src/gerar_chunks.py): Python module · Preserves heading hierarchy while splitting manuals. · `src/gerar_chunks.py`
- [LangChain splitters](https://github.com/felipetds/projeto-ia-rag/blob/main/requirements.txt): library · `requirements.txt`
- [Chunk metrics](https://github.com/felipetds/projeto-ia-rag/blob/main/src/infos_chunks.py): Python module · Adds character and token counts to chunks. · `src/infos_chunks.py`
- [tiktoken](https://github.com/felipetds/projeto-ia-rag/blob/main/requirements.txt): library · Estimates OpenAI token counts. · `requirements.txt`
- [Python 3.12+ runtime](https://github.com/felipetds/projeto-ia-rag/blob/main/requirements.txt): runtime · `requirements.txt`

### Local JSON State

- [Final chunks JSON](https://github.com/felipetds/projeto-ia-rag/blob/main/src/data/chunks_processados/chunks_finais.json): pipeline artifact · Downstream contract for later vector-store ingestion. · `src/data/chunks_processados/chunks_finais.json`
- [Processed-file ledger](https://github.com/felipetds/projeto-ia-rag/blob/main/src/data/verificar_arquivos/arquivos_injetados.json): JSON state · Persists ingestion history for incremental runs. · `src/data/verificar_arquivos/arquivos_injetados.json`

### Other components

- **Future vector ingestion**: external downstream · Not implemented in this repository.

## Connections

- Python 3.12+ runtime → Pipeline orchestrator: runs
- Pipeline orchestrator → Discovery & validation: discovers
- Markdown manuals → Discovery & validation: scanned inputs
- Discovery & validation → Incremental filter: validated manuals
- Processed-file ledger → Incremental filter: prior history
- Incremental filter → Semantic Markdown split: unprocessed manuals
- Semantic Markdown split → LangChain splitters: uses
- Semantic Markdown split → Chunk metrics: text blocks
- Chunk metrics → tiktoken: counts tokens with
- Chunk metrics → Final chunks JSON: writes enriched chunks
- Pipeline orchestrator → Processed-file ledger: updates after processing
- Final chunks JSON → Future vector ingestion: retrieval-ready records
