A Retrieval-Augmented Generation (RAG) pipeline that ingests technical SQL + text specifications and generates configuration files or code snippets based on user instructions.
- Backend: Python 3.11 + Flask
- Database: MongoDB Atlas Cloud (vector search enabled)
- Vector Embeddings: sentence-transformers/all-MiniLM-L6-v2
- LLM Generation: Google Gemini (gemini-2.5-flash)
- Frontend: React single-page app
- Python 3.11+
- Node.js 16+ and npm
- MongoDB Atlas account with vector search enabled
cd backend
pip install -r requirements.txtCreate a .env file in the root directory (already created with default values):
MONGODB_URI="mongodb+srv://<username>:<password>@cluster0.mongodb.net/?retryWrites=true&w=majority"
MONGODB_DB="ragdb"
MONGODB_COLLECTION="chunks"
EMBEDDING_MODEL="sentence-transformers/all-MiniLM-L6-v2"
GEMINI_API_KEY="your_gemini_api_key_here"
GEMINI_MODEL="gemini-2.5-flash"
GEN_TEMPERATURE="0.2"
TOP_K="5"Note: Update MONGODB_URI with your actual MongoDB Atlas cluster hostname.
In MongoDB Atlas, create a vector search index on your collection:
- Go to Atlas Search → Create Search Index
- Use JSON Editor and paste:
{
"fields": [
{
"type": "vector",
"path": "embedding",
"numDimensions": 384,
"similarity": "cosine"
}
]
}- Name the index:
idx_embedding
cd frontend
npm installTerminal 1 - Backend:
cd backend
python app.pyTerminal 2 - Frontend (development):
cd frontend
npm startOr build for production:
cd frontend
npm run buildThe backend will serve the frontend from the build folder when running in production mode.
Health check endpoint to verify MongoDB connection.
Response:
{
"status": "healthy",
"mongodb": "connected",
"database": "ragdb",
"collection": "chunks"
}Upload and ingest SQL or text files.
Request: Multipart form data with file field (.sql or .txt)
Response:
{
"status": "success",
"message": "Ingested 5 chunks from example.sql",
"chunks": 5,
"source_id": "example.sql"
}Generate configuration based on user instruction.
Request:
{
"instruction": "Generate YAML config for firewall rule X"
}Response:
{
"config_output": "generated config code...",
"references": [
{
"chunk_id": "...",
"source_id": "example.sql",
"text_preview": "...",
"score": 0.95
}
],
"full_response": "..."
}-
Upload Specifications: Use the upload section to upload
.sqlor.txtfiles containing technical specifications, commands, or expected configurations. -
Generate Configurations: Enter an instruction in the textarea (e.g., "Generate YAML for command X") and click "Generate Config". The system will:
- Embed your instruction
- Retrieve the most relevant chunks from uploaded specs
- Generate a configuration using the LLM
- Display the result with context references
- Intelligent Chunking: Automatically chunks SQL files by statements or text files by ~1000 characters
- Vector Search: Uses MongoDB Atlas vector search for semantic retrieval
- Context-Aware Generation: LLM generates configurations based on retrieved context
- Reference Tracking: Shows which chunks were used for generation
- Fallback Mechanism: Manual cosine similarity if vector index is not available
- The first run will download the embedding model (~90MB)
- Ensure you have a valid GEMINI_API_KEY
- MongoDB Atlas vector search requires a dedicated cluster with vector search enabled
- MongoDB Connection Issues: Verify your connection string and network access in Atlas
- Vector Search Not Working: Check that the vector index
idx_embeddingis created - Model Loading Errors: Ensure sufficient disk space and RAM
- CORS Errors: Make sure Flask-CORS is installed and configured