Módulo 8: Proyecto Final Integrador - RAG System Completo

Módulo 8: Proyecto Final Integrador - RAG System Completo

Introducción

Este es el módulo final que integra TODO lo aprendido en los 7 módulos anteriores. Construirás un sistema RAG production-ready end-to-end con:

  • M1-M2: Embeddings (OpenAI + SBERT fallback)
  • M3: Model comparison y selección
  • M4: Chunking inteligente + evaluación
  • M5: Distance metrics optimizadas (FAISS)
  • M6: Embedding operations (query expansion)
  • M7: Production patterns (caching, monitoring, fault tolerance)

Objetivos del proyecto final

  1. Sistema completo: Ingest → Chunk → Embed → Index → Retrieve → Evaluate
  2. Production-ready: Caching, monitoring, error handling
  3. Evaluación: Métricas (nDCG, Recall@K)
  4. Optimización: FAISS, batch processing
  5. CLI interactivo: Testing tool
  6. Documentation: Setup, API, deployment

Roadmap del módulo

Fase 1: Architecture (Cápsulas 01-03)

  • Cápsula 01: Introducción y arquitectura
  • Cápsula 02: Document ingestion pipeline
  • Cápsula 03: Chunking & embedding pipeline

Fase 2: Retrieval & Evaluation (Cápsulas 04-06)

  • Cápsula 04: Vector search con FAISS
  • Cápsula 05: Evaluation framework
  • Cápsula 06: Query expansion & reranking

Fase 3: Production & Deploy (Cápsulas 07-08)

  • Cápsula 07: Production deployment
  • Cápsula 08: Conclusiones y next steps

Arquitectura del sistema

┌─────────────────────────────────────────────┐
│           DOCUMENT INGESTION                │
│  - Load docs (PDF, MD, TXT)                 │
│  - Metadata extraction                      │
└──────────────────┬──────────────────────────┘
                   │
                   ▼
┌─────────────────────────────────────────────┐
│            CHUNKING PIPELINE                │
│  - Recursive chunking (LangChain)           │
│  - Token-aware (tiktoken)                   │
│  - Metadata enrichment                      │
└──────────────────┬──────────────────────────┘
                   │
                   ▼
┌─────────────────────────────────────────────┐
│          EMBEDDING GENERATION               │
│  - OpenAI API (primary)                     │
│  - SBERT (fallback)                         │
│  - Redis caching                            │
│  - Batch processing                         │
└──────────────────┬──────────────────────────┘
                   │
                   ▼
┌─────────────────────────────────────────────┐
│           VECTOR INDEXING                   │
│  - FAISS (HNSW index)                       │
│  - Normalized embeddings                    │
│  - Metadata storage                         │
└──────────────────┬──────────────────────────┘
                   │
                   ▼
┌─────────────────────────────────────────────┐
│            RETRIEVAL SYSTEM                 │
│  - Query embedding                          │
│  - FAISS search (top-K)                     │
│  - Optional: Query expansion                │
│  - Optional: Reranking                      │
└──────────────────┬──────────────────────────┘
                   │
                   ▼
┌─────────────────────────────────────────────┐
│             EVALUATION                      │
│  - nDCG@K, Recall@K                         │
│  - A/B testing chunking strategies          │
│  - Performance monitoring                   │
└─────────────────────────────────────────────┘

Tech Stack

# Core
- Python 3.10+
- NumPy
- OpenAI API

# Embeddings
- openai==1.54.0
- sentence-transformers==2.3.1

# Chunking
- langchain==0.1.0
- tiktoken==0.5.2

# Vector search
- faiss-cpu==1.7.4

# Production
- redis==5.0.1
- prometheus-client==0.19.0

# Evaluation
- scikit-learn==1.4.0

Proyecto structure

rag-system-final/
├── src/
│   ├── ingestion/
│   │   ├── __init__.py
│   │   ├── document_loader.py
│   │   └── metadata_extractor.py
│   ├── chunking/
│   │   ├── __init__.py
│   │   └── smart_chunker.py
│   ├── embeddings/
│   │   ├── __init__.py
│   │   ├── embedding_client.py
│   │   └── cache.py
│   ├── indexing/
│   │   ├── __init__.py
│   │   └── faiss_index.py
│   ├── retrieval/
│   │   ├── __init__.py
│   │   ├── retriever.py
│   │   └── reranker.py
│   ├── evaluation/
│   │   ├── __init__.py
│   │   └── metrics.py
│   └── monitoring/
│       ├── __init__.py
│       └── metrics_collector.py
├── data/
│   ├── documents/          # Input docs
│   ├── eval_dataset.json   # Evaluation set
│   └── cache/              # Redis alternative
├── indexes/                # FAISS indexes
├── config/
│   └── config.yaml         # Configuration
├── tests/
│   └── test_*.py
├── main.py                 # CLI
├── api.py                  # REST API (FastAPI)
├── requirements.txt
├── README.md
└── docker-compose.yml

Key features

1. Intelligent Chunking

# Recursive chunking con token awareness
# - Respeta boundaries (párrafos, frases)
# - Garantiza max_tokens
# - Metadata enrichment (source, headers)

2. Multi-provider embeddings

# Primary: OpenAI (alta calidad)
# Fallback: SBERT local (fault tolerance)
# Caching: Redis (80% hit rate)

3. Optimized search

# FAISS HNSW (100x faster)
# Normalized embeddings (dot product)
# Query expansion (better recall)

4. Production patterns

# - Retry logic (exponential backoff)
# - Circuit breaker
# - Health checks
# - Monitoring (Prometheus)
# - Cost tracking

5. Comprehensive evaluation

# - nDCG@K, Recall@K, Precision@K
# - A/B testing
# - Performance benchmarks

En las siguientes cápsulas

Implementarás cada componente paso a paso, culminando en un sistema RAG production-ready completo.


Módulo 8 - Cápsula 01 Proyecto Final: integrando 7 módulos de conocimiento