Spaces:
Build error
Build error
Delete INSTRUCTIONS.md
Browse files- INSTRUCTIONS.md +0 -170
INSTRUCTIONS.md
DELETED
|
@@ -1,170 +0,0 @@
|
|
| 1 |
-
# 📘 Para.AI RAG Cluster - Instructions
|
| 2 |
-
|
| 3 |
-
## 🎯 Objetivo
|
| 4 |
-
|
| 5 |
-
Deploy de micro-cluster RAG no Hugging Face Spaces (free tier) para indexar ~300k jurisprudências do TJPR.
|
| 6 |
-
|
| 7 |
-
## 📋 Arquivos do Projeto
|
| 8 |
-
|
| 9 |
-
| Arquivo | Função |
|
| 10 |
-
|---------|---------|
|
| 11 |
-
| `config.yaml` | Configuração (EDITE AQUI!) |
|
| 12 |
-
| `Dockerfile` | Container Docker |
|
| 13 |
-
| `entrypoint.sh` | Script de inicialização |
|
| 14 |
-
| `requirements.txt` | Dependências Python |
|
| 15 |
-
| `filter_fields.py` | Filtrar campos JSONL |
|
| 16 |
-
| `rag_builder.py` | Construir ChromaDB |
|
| 17 |
-
| `query_engine.py` | Engine de busca |
|
| 18 |
-
| `app.py` | FastAPI REST API |
|
| 19 |
-
| `README.md` | Documentação básica |
|
| 20 |
-
| `.gitignore` | Arquivos ignorados |
|
| 21 |
-
|
| 22 |
-
## 🚀 Deploy Step-by-Step
|
| 23 |
-
|
| 24 |
-
### 1. Preparar Configuração
|
| 25 |
-
|
| 26 |
-
Editar `config.yaml`:
|
| 27 |
-
|
| 28 |
-
```yaml
|
| 29 |
-
cluster_id: "RAG-0301" # Seu ID único
|
| 30 |
-
chunk_start: 301 # Primeiro chunk
|
| 31 |
-
chunk_end: 600 # Último chunk (300 chunks = ~300k registros)
|
| 32 |
-
github_repo: "https://github.com/SEU-USUARIO/para-ai-data.git"
|
| 33 |
-
```
|
| 34 |
-
|
| 35 |
-
### 2. Criar Space no HF
|
| 36 |
-
|
| 37 |
-
```bash
|
| 38 |
-
# Login
|
| 39 |
-
huggingface-cli login
|
| 40 |
-
|
| 41 |
-
# Criar Space
|
| 42 |
-
huggingface-cli repo create para-ai-rag-0301 --type space --space_sdk docker
|
| 43 |
-
```
|
| 44 |
-
|
| 45 |
-
### 3. Fazer Upload
|
| 46 |
-
|
| 47 |
-
```bash
|
| 48 |
-
cd hf_space_rag_example
|
| 49 |
-
|
| 50 |
-
# Inicializar Git
|
| 51 |
-
git init
|
| 52 |
-
git remote add origin https://huggingface.co/spaces/SEU-USUARIO/para-ai-rag-0301
|
| 53 |
-
|
| 54 |
-
# Commit
|
| 55 |
-
git add .
|
| 56 |
-
git commit -m "Initial deployment"
|
| 57 |
-
|
| 58 |
-
# Push
|
| 59 |
-
git push origin main
|
| 60 |
-
```
|
| 61 |
-
|
| 62 |
-
### 4. Aguardar Build
|
| 63 |
-
|
| 64 |
-
- Acesse: https://huggingface.co/spaces/SEU-USUARIO/para-ai-rag-0301
|
| 65 |
-
- Status: Building (5-10 min) → Running (5-10 min) → Ready ✅
|
| 66 |
-
|
| 67 |
-
### 5. Testar
|
| 68 |
-
|
| 69 |
-
```bash
|
| 70 |
-
# Info do cluster
|
| 71 |
-
curl https://SEU-USUARIO-para-ai-rag-0301.hf.space/cluster/info
|
| 72 |
-
|
| 73 |
-
# Busca semântica
|
| 74 |
-
curl -X POST https://SEU-USUARIO-para-ai-rag-0301.hf.space/search/embedding \
|
| 75 |
-
-H "Content-Type: application/json" \
|
| 76 |
-
-d '{"query": "despejo falta pagamento", "top_k": 5}'
|
| 77 |
-
```
|
| 78 |
-
|
| 79 |
-
## 🌐 Arquitetura Distribuída
|
| 80 |
-
|
| 81 |
-
Para cobrir todos os 4.5M registros, crie 15 Spaces:
|
| 82 |
-
|
| 83 |
-
| Space | Chunks | Config |
|
| 84 |
-
|-------|--------|--------|
|
| 85 |
-
| para-ai-rag-0001 | 1-300 | chunk_start: 1, chunk_end: 300 |
|
| 86 |
-
| para-ai-rag-0301 | 301-600 | chunk_start: 301, chunk_end: 600 |
|
| 87 |
-
| para-ai-rag-0601 | 601-900 | chunk_start: 601, chunk_end: 900 |
|
| 88 |
-
| ... | ... | ... |
|
| 89 |
-
| para-ai-rag-4201 | 4201-4500 | chunk_start: 4201, chunk_end: 4500 |
|
| 90 |
-
|
| 91 |
-
**Script de deploy automático** (bash):
|
| 92 |
-
|
| 93 |
-
```bash
|
| 94 |
-
#!/bin/bash
|
| 95 |
-
for START in 1 301 601 901 1201 1501 1801 2101 2401 2701 3001 3301 3601 3901 4201; do
|
| 96 |
-
END=$((START + 299))
|
| 97 |
-
SPACE_NAME="para-ai-rag-$(printf "%04d" $START)"
|
| 98 |
-
|
| 99 |
-
huggingface-cli repo create $SPACE_NAME --type space --space_sdk docker
|
| 100 |
-
git clone https://huggingface.co/spaces/SEU-USUARIO/$SPACE_NAME
|
| 101 |
-
cd $SPACE_NAME
|
| 102 |
-
|
| 103 |
-
# Copiar template e atualizar config
|
| 104 |
-
cp -r ../hf_space_rag_example/* .
|
| 105 |
-
sed -i "s/chunk_start: .*/chunk_start: $START/" config.yaml
|
| 106 |
-
sed -i "s/chunk_end: .*/chunk_end: $END/" config.yaml
|
| 107 |
-
|
| 108 |
-
git add .
|
| 109 |
-
git commit -m "Deploy cluster $START-$END"
|
| 110 |
-
git push
|
| 111 |
-
cd ..
|
| 112 |
-
done
|
| 113 |
-
```
|
| 114 |
-
|
| 115 |
-
## 🔧 Customização
|
| 116 |
-
|
| 117 |
-
### Adicionar Mais Campos
|
| 118 |
-
|
| 119 |
-
Em `config.yaml`:
|
| 120 |
-
|
| 121 |
-
```yaml
|
| 122 |
-
campos_filter:
|
| 123 |
-
- id
|
| 124 |
-
- ementa
|
| 125 |
-
- data_decisao # Adicionar
|
| 126 |
-
- relator # Adicionar
|
| 127 |
-
```
|
| 128 |
-
|
| 129 |
-
### Trocar Modelo de Embedding
|
| 130 |
-
|
| 131 |
-
```yaml
|
| 132 |
-
# Opção 1: Mais leve (padrão)
|
| 133 |
-
embedding_model: "sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2"
|
| 134 |
-
embedding_dim: 384
|
| 135 |
-
|
| 136 |
-
# Opção 2: Melhor qualidade
|
| 137 |
-
embedding_model: "sentence-transformers/paraphrase-multilingual-mpnet-base-v2"
|
| 138 |
-
embedding_dim: 768
|
| 139 |
-
```
|
| 140 |
-
|
| 141 |
-
## 🐛 Troubleshooting
|
| 142 |
-
|
| 143 |
-
### Build muito lento
|
| 144 |
-
- Verificar se sparse checkout está funcionando
|
| 145 |
-
- Reduzir número de chunks temporariamente
|
| 146 |
-
|
| 147 |
-
### Out of Memory
|
| 148 |
-
- Usar modelo menor: `all-MiniLM-L6-v2`
|
| 149 |
-
- Reduzir `embedding_batch_size: 32`
|
| 150 |
-
- Diminuir intervalo de chunks
|
| 151 |
-
|
| 152 |
-
### API retorna 503
|
| 153 |
-
- Ver logs do Space no HF
|
| 154 |
-
- Verificar se ChromaDB foi construído
|
| 155 |
-
|
| 156 |
-
## 📊 Recursos Utilizados
|
| 157 |
-
|
| 158 |
-
| Recurso | Usado | Disponível (Free) |
|
| 159 |
-
|---------|-------|-------------------|
|
| 160 |
-
| RAM | ~2GB | 16GB ✅ |
|
| 161 |
-
| Disco | ~2.6GB | 50GB ✅ |
|
| 162 |
-
| CPU | 1 core | 2 cores ✅ |
|
| 163 |
-
|
| 164 |
-
## ⚖️ Sobre Para.AI
|
| 165 |
-
|
| 166 |
-
Projeto open-source para democratizar o acesso à justiça no Paraná usando IA.
|
| 167 |
-
|
| 168 |
-
🐝 **InJustiça não para o Paraná!**
|
| 169 |
-
|
| 170 |
-
📧 github.com/caarleexx/para-ai
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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