Sistema modular de RAG (Retrieval Augmented Generation) para processamento de documentos e geração de respostas
Project description
🧠 RAG Core
Sistema modular de RAG (Retrieval Augmented Generation) desenvolvido para ser reutilizável e escalável, com suporte a múltiplos tenants e diferentes provedores de LLM.
🌟 Características
- ✨ Arquitetura Event-Driven: Baseada em Kafka para processamento assíncrono
- 🔄 Pipeline Modular: Extração → Embedding → Armazenamento → Recuperação → Geração
- 🔌 Múltiplos Provedores: Suporte a diferentes LLMs (Gemini, OpenAI, Mistral, etc.)
- 📊 Vector Store: Integração com Qdrant para busca semântica
- 📦 MongoDB: Armazenamento de documentos e metadados
- 🔐 Multi-tenant: Isolamento completo entre diferentes clientes
- 📈 Observabilidade: OpenTelemetry para traces, métricas e logs
🚀 Começando
Pré-requisitos
- Python 3.10+
- Docker e Docker Compose
- Make (opcional, mas recomendado)
Instalação
- Clone o repositório:
git clone https://github.com/seu-usuario/rag_core.git
cd rag_core
- Crie e ative um ambiente virtual:
python -m venv .venv
source .venv/bin/activate # Linux/Mac
# ou
.venv\Scripts\activate # Windows
- Instale as dependências:
pip install -r requirements.txt
- Copie o arquivo de exemplo de variáveis de ambiente:
cp .env.example .env
- Inicie os serviços com Docker Compose:
docker-compose up -d
🔧 Configuração
Edite o arquivo .env com suas configurações:
# Kafka
KAFKA_BOOTSTRAP_SERVERS=localhost:9092
# Qdrant
QDRANT_HOST=localhost
QDRANT_PORT=6333
# MongoDB
MONGODB_URI=mongodb://localhost:27017
# LLM Providers
GEMINI_API_KEY=sua_chave_aqui
OPENAI_API_KEY=sua_chave_aqui
📚 Como Usar
Uso Básico
from rag_core.core_orchestrator import CoreOrchestrator
from rag_core.events.event_bus import EventBus
from rag_core.events.event_types import DOCUMENT_UPLOADED, QUESTION_RECEIVED
# Inicializa o core
core = CoreOrchestrator()
core.start()
# Obtém instância do EventBus
event_bus = EventBus()
# Envia um documento
event_bus.emit(DOCUMENT_UPLOADED, {
"tenant_id": "empresa_x",
"session_id": "sessao_123",
"file_path": "/caminho/para/documento.pdf",
"file_type": "pdf"
})
# Faz uma pergunta
event_bus.emit(QUESTION_RECEIVED, {
"tenant_id": "empresa_x",
"session_id": "sessao_123",
"question": "Qual é o procedimento para...?",
"metadata": {
"language": "pt-BR",
"max_tokens": 500
}
})
Usando como Dependência
Instale o pacote via pip:
pip install rag_core
Ou adicione ao seu requirements.txt:
rag_core @ git+https://github.com/seu-usuario/rag_core.git
🏗️ Arquitetura
O sistema é dividido em camadas:
- Extraction Layer: Extrai texto de diferentes tipos de documento
- Embedding Layer: Gera embeddings usando diferentes provedores
- Vector Store Layer: Armazena e recupera vetores
- Retrieval Layer: Realiza busca semântica
- Generation Layer: Gera respostas usando LLMs
🔄 Eventos
O sistema usa os seguintes eventos principais:
DOCUMENT_UPLOADED: Documento enviado para processamentoDOCUMENT_EXTRACTED: Texto extraído do documentoEMBEDDING_CREATED: Embedding geradoVECTOR_STORED: Vetor armazenado no QdrantQUESTION_RECEIVED: Pergunta recebidaDOCUMENTS_RETRIEVED: Documentos relevantes recuperadosANSWER_GENERATED: Resposta final gerada
🧪 Testes
Execute os testes com:
pytest
📝 Licença
Este projeto está sob a licença MIT. Veja o arquivo LICENSE para mais detalhes.
🤝 Contribuindo
- Faça o fork do projeto
- Crie sua feature branch (
git checkout -b feature/AmazingFeature) - Commit suas mudanças (
git commit -m 'Add some AmazingFeature') - Push para a branch (
git push origin feature/AmazingFeature) - Abra um Pull Request
📞 Suporte
Para suporte, abra uma issue no GitHub ou entre em contato via [email].
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file veolia_rag_core-0.1.1.tar.gz.
File metadata
- Download URL: veolia_rag_core-0.1.1.tar.gz
- Upload date:
- Size: 28.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
37cbe97296566c71a2ce9079bc84a219426ff73932bce26c48364c677d5c7b6a
|
|
| MD5 |
7b597a92d2a1027e26cb718edeea8fac
|
|
| BLAKE2b-256 |
c8f735f0fe35b5faaf6e229e93211abad2c68f9e8b073576a45f7f4e5990a04d
|
File details
Details for the file veolia_rag_core-0.1.1-py3-none-any.whl.
File metadata
- Download URL: veolia_rag_core-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89967e6226684ab42aacd2912e478146f31392fc992df4a42521c7306d5a3d3f
|
|
| MD5 |
b7eac92f76df229ec2e30fbfdc0b14b5
|
|
| BLAKE2b-256 |
412b64f4b54cf70d3b6b12931016bbb8d8868959cd6cf0e764f24a80da90b6fe
|