The DBA Agent now supports Azure AI Search for enhanced RAG (Retrieval-Augmented Generation) capabilities. This provides:
- Vector Search: Semantic similarity using embeddings
- Hybrid Search: Combines vector + keyword search for best results
- Persistent Storage: No data loss on restart (vs in-memory cache)
- Scalability: Handle millions of documents
- Semantic Ranking: Azure's AI-powered relevance scoring
- Advanced Filtering: Filter by connection, type, tables, etc.
| Feature | In-Memory Cache | Azure AI Search |
|---|---|---|
| Persistence | Lost on restart | Persistent storage |
| Scalability | Limited by RAM | Millions of documents |
| Search Quality | Cosine similarity only | Hybrid search (vector + keyword + semantic) |
| Performance | Re-calculate scores each time | Pre-indexed, optimized queries |
| Filtering | Manual in code | Native filter support |
| Distributed | Single server | Cloud-scale distributed |
# Create resource group (if needed)
az group create --name dba-agent-rg --location eastus
# Create Azure AI Search service
az search service create \
--name dba-agent-search \
--resource-group dba-agent-rg \
--sku basic \
--partition-count 1 \
--replica-count 1Or use the Azure Portal:
- Search for "Azure AI Search"
- Click "Create"
- Choose resource group, name, and region
- Select pricing tier (Basic for dev, Standard+ for production)
# Get admin API key
az search admin-key show \
--service-name dba-agent-search \
--resource-group dba-agent-rgOr from Azure Portal:
- Go to your Search service
- Click "Keys" in left menu
- Copy the Admin Key
- Note your Search Endpoint (format:
https://<name>.search.windows.net)
Update application.properties or set environment variables:
# Enable Azure AI Search
azure.search.enabled=true
# Connection details
azure.search.endpoint=https://<your-search-resource>.search.windows.net
azure.search.api-key=YOUR_ADMIN_API_KEY_HERE
azure.search.index-name=dba-agent-training-dataOr using environment variables:
export AZURE_SEARCH_ENABLED=true
export AZURE_SEARCH_ENDPOINT=https://<your-search-resource>.search.windows.net
export AZURE_SEARCH_API_KEY=your-admin-keyThe search index will be automatically created on startup with:
- Vector search configuration (3072 dimensions for text-embedding-3-large)
- HNSW algorithm for fast approximate nearest neighbor search
- Hybrid search capabilities
- Semantic ranking enabled
User Query → ChatService → TrainingService
↓
EmbeddingService (Azure OpenAI)
↓
Create Embedding (3072-dim vector)
↓
┌───────────────────────┐
│ Azure AI Search │
│ ✓ Store document │
│ ✓ Index vector │
│ ✓ Index keywords │
└───────────────────────┘
User Question → Create Embedding
↓
┌──────────────────────────────┐
│ Azure AI Search │
│ Hybrid Search: │
│ 1. Vector similarity │
│ 2. Keyword matching │
│ 3. Semantic ranking │
└──────────────────────────────┘
↓
Top-K Most Relevant Results
↓
ChatService (Context)
// Automatically indexes to Azure Search when enabled
trainingService.trainWithSchema(connectionId);This:
- Scans database schema
- Creates embeddings for each table
- Indexes to Azure Search with:
- Full DDL as searchable text
- Vector embedding
- Metadata (table name, column count)
- Filterable by connectionId
trainingService.trainWithQueryExample(
connectionId,
"Show me all active users",
"SELECT * FROM users WHERE active = 1",
queryResult,
userId
);Indexed with:
- Natural language question (searchable)
- SQL query (searchable, optimized analyzer)
- Execution metrics
- Tables used (filterable)
List<TrainingDataEmbedding> relevant =
trainingService.retrieveRelevant(
connectionId,
"How many orders were placed last month?",
topK: 5
);Azure Search returns:
- Vector matches: Similar questions/schemas
- Keyword matches: Exact term matches (e.g., "orders", "month")
- Semantic ranking: AI-powered relevance scoring
- Combined: Best of all three methods
For pure semantic similarity without keyword matching:
List<TrainingDataSearchDocument> results =
azureSearchService.vectorSearch(
connectionId,
queryVector,
topK: 10,
typeFilter: "QUERY_EXAMPLE" // Optional
);// Only search documentation for specific tables
String filter = "connectionId eq 'conn-123' and type eq 'DOCUMENTATION' and tablesUsed eq 'users'";Map<String, Long> stats = azureSearchService.getConnectionStats(connectionId);
// Returns: { "schema_ddl": 50, "query_example": 120, "documentation": 30 }Azure AI Search pricing depends on tier:
| Tier | Storage | Price/Month (approx) | Best For |
|---|---|---|---|
| Free | 50 MB | $0 | Development/Testing |
| Basic | 2 GB | $75 | Small production |
| Standard S1 | 25 GB | $250 | Production |
| Standard S2 | 100 GB | $1,000 | Large scale |
Note: Vector search available on Basic tier and above.
View index statistics in Azure Portal:
- Go to your Search service
- Click "Indexes"
- Select "dba-agent-training-data"
- View document count, storage size, query stats
If Azure Search is disabled or unavailable:
- ✅ Automatically falls back to in-memory cache
- ✅ No functionality loss
⚠️ Performance degradation for large datasets⚠️ Data lost on restart
- Enable Azure Search in config
- Restart application (index created automatically)
- Re-train existing connections:
# Call training endpoints for each connection
curl -X POST http://localhost:8080/api/training/schema/{connectionId}- Set
azure.search.enabled=false - Restart application
- Data automatically loaded from database on first query
Error: "Index creation failed"
Solution: Check admin API key permissions
# Verify key works
curl -X GET "https://<service>.search.windows.net/indexes?api-version=2023-11-01" \
-H "api-key: YOUR_KEY"Possible causes:
- No data indexed yet → Train with schema/examples
- Wrong connectionId filter → Check logs
- Vector dimensions mismatch → Verify embedding model (3072 for text-embedding-3-large)
Solutions:
- Increase replica count for read throughput
- Use Standard tier for better performance
- Reduce
topKparameter - Add more specific filters
- Index Regularly: Re-index when schema changes
- Use Filters: Always filter by connectionId for multi-tenant scenarios
- Batch Operations: Use
indexDocuments()for bulk indexing - Monitor Costs: Set up Azure cost alerts
- Semantic Search: Enable for best relevance
- Hybrid Search: Use for highest accuracy
- Vector-Only: Use when keywords don't matter