How felipetds/projeto-ia-rag works
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: main.py Pipeline orchestrator · gerar_chunks.py Semantic Markdown split · infos_chunks.py Chunk metrics · buscador.py Discovery & validation
Components 12
Manual Inputs
- Markdown manuals · Source-of-truth product manuals.
Ingestion Pipeline
- Pipeline orchestrator · Coordinates the incremental ingestion run.
src/main.py - Discovery & validation
src/buscador.py - Incremental filter · Excludes manuals already recorded as processed.
src/verificar_arquivos.py - Semantic Markdown split · Preserves heading hierarchy while splitting manuals.
src/gerar_chunks.py - LangChain splitters
requirements.txt - Chunk metrics · Adds character and token counts to chunks.
src/infos_chunks.py - tiktoken · Estimates OpenAI token counts.
requirements.txt - Python 3.12+ runtime
requirements.txt
Local JSON State
- Final chunks JSON · Downstream contract for later vector-store ingestion.
src/data/chunks_processados/chunks_finais.json - Processed-file ledger · Persists ingestion history for incremental runs.
src/data/verificar_arquivos/arquivos_injetados.json
Other components
- Future vector ingestion · Not implemented in this repository.
Connections 12
- 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