Private RAG Architecture with MySQL and Embeddings
Technical prompt to create RAG pipelines using MySQL as the vector store. Ideal for companies that need to keep data private without using external services.
Create a private and secure RAG (Retrieval-Augmented Generation) architecture. ## Context - Company: [NOME_EMPRESA] - Knowledge base: [TIPO: PDF / banco de dados / wiki] - Volume: [MB/GB] - Privacy: maximum (no data leaving for external APIs) - LLM: [Ollama Llama3 / Claude / GPT-4] ## Architecture ### 1. Ingestion - Parser for PDF, DOCX, TXT, HTML - Chunking: 512 tokens, overlap: 50 - Cleaning and normalization - Metadata per chunk ### 2. Embeddings - Model: nomic-embed-text or text-embedding-3-small - Dimension: 768 or 1536 - Batch processing ### 3. MySQL Storage CREATE TABLE documents ( id BIGINT PRIMARY KEY AUTO_INCREMENT, content TEXT NOT NULL, embedding JSON NOT NULL, source VARCHAR(255), chunk_index INT, metadata JSON, created_at DATETIME DEFAULT CURRENT_TIMESTAMP ); ### 4. Semantic search - Cosine similarity in SQL - Threshold: 0.75 - Top-K: 5 - Reranking by relevance ### 5. Generation - Context building - Prompt with citations - Response with references ### 6. REST API - POST /query - POST /ingest - GET /documents - DELETE /document/:id ## Stack - Python 3.11 + FastAPI - SQLAlchemy + MySQL 8+ - LangChain or LlamaIndex Generate the complete code for the RAG system.