I have successfully implemented the ProxySQL RAG (Retrieval-Augmented Generation) subsystem according to the requirements specified in the blueprint documents. Here's what has been accomplished:
- Created
RAG_Tool_Handlerclass inheriting fromMCP_Tool_Handler - Implemented all required MCP tools:
rag.search_fts- Keyword search using FTS5rag.search_vector- Semantic search using vector embeddingsrag.search_hybrid- Hybrid search with two modes (fuse and fts_then_vec)rag.get_chunks- Fetch chunk contentrag.get_docs- Fetch document contentrag.fetch_from_source- Refetch authoritative datarag.admin.stats- Operational statistics
- Added complete RAG schema to
AI_Features_Manager:rag_sources- Ingestion configurationrag_documents- Canonical documentsrag_chunks- Chunked contentrag_fts_chunks- FTS5 indexrag_vec_chunks- Vector indexrag_sync_state- Sync state trackingrag_chunk_view- Debugging view
- Added RAG tool handler to
MCP_Thread - Registered
/mcp/ragendpoint inProxySQL_MCP_Server - Integrated with existing MCP infrastructure
- Added RAG configuration variables to
GenAI_Thread:genai_rag_enabledgenai_rag_k_maxgenai_rag_candidates_maxgenai_rag_query_max_bytesgenai_rag_response_max_bytesgenai_rag_timeout_ms
- FTS Search: Full-text search using SQLite FTS5
- Vector Search: Semantic search using sqlite3-vec
- Hybrid Search: Two modes:
- Fuse mode: Parallel FTS + vector with Reciprocal Rank Fusion
- FTS-then-vector mode: Candidate generation + rerank
- Input validation and sanitization
- Query length limits
- Result size limits
- Timeouts for all operations
- Column whitelisting for refetch operations
- Row and byte limits
- Proper use of prepared statements
- Connection management
- SQLite3-vec integration
- FTS5 integration
- Proper indexing strategies
scripts/mcp/test_rag.sh- Tests RAG functionality via MCP endpointtest/test_rag_schema.cpp- Tests RAG database schema creationtest/build_rag_test.sh- Simple build script for RAG test
doc/rag-documentation.md- Comprehensive RAG documentationdoc/rag-examples.md- Examples of using RAG tools- Updated
scripts/mcp/README.mdto include RAG in architecture
include/RAG_Tool_Handler.h- Header filelib/RAG_Tool_Handler.cpp- Implementation filedoc/rag-documentation.md- Documentationdoc/rag-examples.md- Usage examplesscripts/mcp/test_rag.sh- Test scripttest/test_rag_schema.cpp- Schema testtest/build_rag_test.sh- Build scriptRAG_IMPLEMENTATION_SUMMARY.md- Implementation summaryRAG_FILE_SUMMARY.md- File summary- Updated
test/Makefile- Added RAG test target
include/MCP_Thread.h- Added RAG tool handler memberlib/MCP_Thread.cpp- Added initialization/cleanuplib/ProxySQL_MCP_Server.cpp- Registered RAG endpointlib/AI_Features_Manager.cpp- Added RAG schemainclude/GenAI_Thread.h- Added RAG config variableslib/GenAI_Thread.cpp- Added RAG config initializationscripts/mcp/README.md- Updated documentation
To enable RAG functionality:
-- Enable GenAI module
SET genai.enabled = true;
-- Enable RAG features
SET genai.rag_enabled = true;
-- Load configuration
LOAD genai VARIABLES TO RUNTIME;Then use the MCP tools via the /mcp/rag endpoint.
The implementation has been completed according to the v0 deliverables specified in the plan: ✓ SQLite schema initializer ✓ Source registry management ✓ Ingestion pipeline (framework) ✓ MCP server tools ✓ Unit/integration tests ✓ "Golden" examples
The RAG subsystem is now ready for integration testing and can be extended with additional features in future versions.