MDDS (Medical Diagnostic Device Search) is an advanced Retrieval-Augmented Generation (RAG) system designed for intelligent medical diagnostic device research. Built with a modern MCP (Model Context Protocol) architecture, the system provides three distinct search modes: normal search for quick responses, deep search for comprehensive analysis, and intelligent search that automatically selects the optimal method based on query complexity.
The system is built on a client-server architecture using the Model Context Protocol (MCP):
- Frontend: Modern web interface with real-time search capabilities
- Express Server: Node.js server handling HTTP requests and MCP client management
- MCP Server: Python-based server providing advanced search tools and AI capabilities
- Data Layer: FAISS vector database, NetworkX knowledge graph, and MongoDB caching
- Node.js (v14 or higher)
- Python 3.8+ with virtual environment
- MongoDB Atlas account (for caching)
- Azure OpenAI API access
-
Install Node.js Dependencies
npm install
-
Setup Python Environment
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate pip install -r requirements.txt
-
Environment Configuration Create a
.envfile in the project root:AZURE_OPEN_AI_KEY="your-azure-openai-api-key" MONGO_URI="your-mongodb-connection-string"
-
Start the Application
Terminal 1 - Start the MCP Server:
source .venv/bin/activate python src/MCPServer.pyTerminal 2 - Start the Express Server:
npm start
Access the application at http://localhost:3000
- Purpose: Fast responses for straightforward medical device queries
- Features:
- Vector similarity search using S-BioBert embeddings
- Knowledge graph entity filtering for relevance
- Intelligent caching with semantic similarity matching
- Sub-query generation for comprehensive coverage
- Best for: Direct questions about specific devices, quick comparisons, general information
- Purpose: Comprehensive research including real-time scientific literature
- Features:
- All normal search capabilities
- Real-time ArXiv paper retrieval and processing
- Extended context analysis (30 items vs 15 in normal)
- Advanced document processing and chunking
- Best for: Complex research questions, latest developments, academic-level analysis
- Purpose: AI-powered decision making between normal and deep search
- Features:
- GPT-4o-mini analyzes query complexity
- Automatic method selection based on query characteristics
- Optimal performance without manual mode selection
- Best for: When you're unsure which search method to use
- Language Model: Azure OpenAI GPT-4o-mini (
medical-device-research-model) - Embeddings: S-BioBert (
pritamdeka/S-BioBert-snli-multinli-stsb) - Vector Database: FAISS with L2 normalization
- NLP Processing: spaCy with English core model
- Entity Recognition: Custom medical entity extraction
- Knowledge Graph: NetworkX-based medical entity relationships
- Document Processing: PyPDF2 for scientific paper parsing
- Caching: MongoDB with MongoEngine ODM
- Real-time Search: ArXiv API integration
- Backend: Python 3.8+ with asyncio support
- API Layer: Express.js with MCP protocol
- Protocol: Model Context Protocol (MCP) for tool communication
- Frontend: Modern HTML5 with responsive CSS
- Concurrency: ThreadPoolExecutor for parallel processing
- Multi-query generation for comprehensive search coverage
- Temperature-controlled response generation (default: 0.5)
- Specialized prompting for medical device contexts
- Dual-mode retrieval: vector similarity + knowledge graph
- Entity-based filtering and relevance scoring
- Configurable search depth (k=15 normal, k=30 deep)
- Real-time ArXiv paper retrieval
- Keyword extraction and query optimization
- PDF processing and semantic chunking
- FAISS indexing for rapid similarity search
- Context deduplication and relevance scoring
- Multi-source information integration
- Top-k selection for optimal response generation
- RAGAS-based evaluation metrics
- Answer drafting and improvement (threshold: 0.7)
- Faithfulness and relevance scoring
- MongoDB-based semantic caching
- Query similarity matching for cache hits
- Separate caching for normal and deep search results
- Automatic Google Scholar link generation
- Source metadata extraction and formatting
- Academic citation support
- Open http://localhost:3000 in your browser
- Use the modern, responsive interface with dark/light mode toggle
- Enter your medical device query in the search field
- Results include automatic citations and quality metrics
POST /api/mcp
{
"name": "normal_search",
"arguments": {
"input_query": "What are the latest glucose monitoring devices?",
"temp": 0.1
}
}Available Tools:
normal_search- Fast search with pre-indexed contentdeep_search- Comprehensive search with real-time papersintelligent_search- AI-powered automatic method selectiontest_search- Connectivity testing
- Specific queries: "Compare accuracy of CGM devices"
- Comparative analysis: "Pulse oximeter vs smartwatch heart rate monitoring"
- Latest research: Use deep search for cutting-edge developments
- Quick facts: Normal search for established information
MDDS_real/
βββ server.js # Express server with MCP client
βββ MCPClientManager.js # MCP protocol client management
βββ package.json # Node.js dependencies
βββ requirements.txt # Python dependencies (171 packages)
βββ public/
β βββ index.html # Modern web interface with dark mode
βββ src/ # Python MCP server modules
β βββ MCPServer.py # Main MCP server with search tools
β βββ UserQuery.py # Multi-query generation
β βββ ContextRetrieval.py # Vector + graph retrieval
β βββ DeepSearch.py # Real-time ArXiv integration
β βββ Ranking.py # Context ranking algorithm
β βββ Evaluation.py # RAGAS quality assessment
β βββ CacheDB.py # MongoDB cache models
β βββ CacheHit.py # Semantic cache matching
β βββ ScholarLink.py # Citation link generation
β βββ DrafterAgent.py # Answer improvement agent
β βββ util.py # Utility functions
βββ data/ # Pre-processed datasets
β βββ chunks_with_entities(1).json # Medical literature chunks
β βββ chunks(1).index # FAISS vector index
β βββ knowledge_graph(3).gexf # Medical entity graph
βββ temp/ # Temporary processing files
endpoint = "https://aoai-camp.openai.azure.com/"
deployment = "medical-device-research-model"
model_name = "gpt-4o-mini"
api_version = "2024-12-01-preview"- Database: Automatic connection via
MONGO_URI - Collection:
cachewith compound indexes - Models:
CacheDBwith query/answer/tag structure
- Normal Search: k=15 contexts, temperature=0.1
- Deep Search: k=30 contexts, k_articles=5, k_chunks=7
- Evaluation Threshold: 0.7 (triggers answer redrafting)
- Parallel vector and graph retrieval
- Asynchronous cache checking
- ThreadPoolExecutor for multi-query processing
- Semantic similarity matching for cache hits
- Separate normal/deep search result storage
- Automatic cache invalidation and updates
- RAGAS evaluation metrics integration
- Automatic answer improvement below 0.7 threshold
- Source validation and metadata preservation
# Terminal 1 - MCP Server with logging
source .venv/bin/activate
python src/MCPServer.py
# Terminal 2 - Express server
npm run start
# Monitor logs
tail -f mcp_server.logcurl -X POST http://localhost:3000/api/mcp \
-H "Content-Type: application/json" \
-d '{"name": "test_search", "arguments": {"input_query": "test"}}'-
MCP Connection Failed
# Ensure Python virtual environment is activated source .venv/bin/activate # Check Python path in MCPClientManager.js matches your setup
-
ModuleNotFoundError:
pip install -r requirements.txt # Ensure all 171+ dependencies are installed -
FAISS Index Error:
# Verify data files exist ls -la data/chunks\(1\).index data/chunks_with_entities\(1\).json
-
MongoDB Connection Issues:
# Verify MongoDB URI format echo $MONGO_URI # Check network connectivity to MongoDB Atlas
-
Azure OpenAI API Errors:
# Verify API key and endpoint echo $AZURE_OPEN_AI_KEY # Check deployment name matches configuration
-
Server Port Conflicts:
# Check if port 3000 is available lsof -i :3000 # Use different port: PORT=3001 npm start
- Startup Time: Ensure FAISS index and knowledge graph files are properly loaded
- Memory Usage: Monitor Python process during deep search operations
- Concurrent Requests: MCP server handles one request at a time
- Cache Performance: MongoDB indexes automatically created for optimal caching
# View MCP server logs
tail -f mcp_server.log
# Enable verbose logging
export LOG_LEVEL=DEBUG
# Test specific search modes
curl -X POST http://localhost:3000/api/mcp \
-H "Content-Type: application/json" \
-d '{"name": "test_search", "arguments": {"input_query": "test"}}'- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Follow the existing code style and architecture
- Add tests for new MCP tools
- Update documentation for new features
- Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- MCP Tools: Add new tools to
MCPServer.pywith proper logging - Frontend: Maintain responsive design and accessibility
- Documentation: Update README for any architectural changes
- Testing: Include test queries for new search capabilities
This project is licensed under the ISC License - see the LICENSE file for details.
For questions or issues:
- Check logs: Review
mcp_server.logfor detailed error information - Verify setup: Ensure all environment variables are configured
- Test connectivity: Use the
test_searchtool to verify MCP communication - GitHub Issues: Report bugs with detailed error logs and system information
Academic Use: This system is designed for medical device research and includes automatic citation generation for academic integrity.
Data Sources:
- Pre-indexed medical literature database
- Real-time ArXiv scientific papers
- Medical entity knowledge graph
- Google Scholar citation links
Don't search harder. Search smarter. π¬
