Skip to content

CODERTG2/MDDS

Repository files navigation

MDDS - Medical Diagnostic Device Search

Overview

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.

πŸ—οΈ Architecture

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

System Architecture

πŸš€ Getting Started

Prerequisites

  • Node.js (v14 or higher)
  • Python 3.8+ with virtual environment
  • MongoDB Atlas account (for caching)
  • Azure OpenAI API access

Setup and Installation

  1. Install Node.js Dependencies

    npm install
  2. Setup Python Environment

    python -m venv .venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
    pip install -r requirements.txt
  3. Environment Configuration Create a .env file in the project root:

    AZURE_OPEN_AI_KEY="your-azure-openai-api-key"
    MONGO_URI="your-mongodb-connection-string"
  4. Start the Application

    Terminal 1 - Start the MCP Server:

    source .venv/bin/activate
    python src/MCPServer.py

    Terminal 2 - Start the Express Server:

    npm start

    Access the application at http://localhost:3000

✨ Search Modes

1. Normal Search (normal_search)

  • 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

2. Deep Search (deep_search)

  • 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

3. Intelligent Search (intelligent_search)

  • 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

πŸ”§ Core Technologies

AI/ML Stack

  • 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

Data Infrastructure

  • 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

Development Stack

  • 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

πŸ” System Components

Query Processing (UserQuery.py)

  • Multi-query generation for comprehensive search coverage
  • Temperature-controlled response generation (default: 0.5)
  • Specialized prompting for medical device contexts

Context Retrieval (ContextRetrieval.py)

  • Dual-mode retrieval: vector similarity + knowledge graph
  • Entity-based filtering and relevance scoring
  • Configurable search depth (k=15 normal, k=30 deep)

Deep Search (DeepSearch.py)

  • Real-time ArXiv paper retrieval
  • Keyword extraction and query optimization
  • PDF processing and semantic chunking
  • FAISS indexing for rapid similarity search

Intelligent Ranking (Ranking.py)

  • Context deduplication and relevance scoring
  • Multi-source information integration
  • Top-k selection for optimal response generation

Quality Assessment (Evaluation.py)

  • RAGAS-based evaluation metrics
  • Answer drafting and improvement (threshold: 0.7)
  • Faithfulness and relevance scoring

Caching System (CacheDB.py, CacheHit.py)

  • MongoDB-based semantic caching
  • Query similarity matching for cache hits
  • Separate caching for normal and deep search results

Citation Generation (ScholarLink.py)

  • Automatic Google Scholar link generation
  • Source metadata extraction and formatting
  • Academic citation support

οΏ½ Usage

Web Interface

  1. Open http://localhost:3000 in your browser
  2. Use the modern, responsive interface with dark/light mode toggle
  3. Enter your medical device query in the search field
  4. Results include automatic citations and quality metrics

API Endpoints

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 content
  • deep_search - Comprehensive search with real-time papers
  • intelligent_search - AI-powered automatic method selection
  • test_search - Connectivity testing

Search Tips

  • 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

πŸ—‚οΈ Project Structure

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

πŸ”§ Configuration

Azure OpenAI Setup

endpoint = "https://aoai-camp.openai.azure.com/"
deployment = "medical-device-research-model"  
model_name = "gpt-4o-mini"
api_version = "2024-12-01-preview"

MongoDB Configuration

  • Database: Automatic connection via MONGO_URI
  • Collection: cache with compound indexes
  • Models: CacheDB with query/answer/tag structure

Search Parameters

  • 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)

πŸš€ Performance Features

Concurrent Processing

  • Parallel vector and graph retrieval
  • Asynchronous cache checking
  • ThreadPoolExecutor for multi-query processing

Intelligent Caching

  • Semantic similarity matching for cache hits
  • Separate normal/deep search result storage
  • Automatic cache invalidation and updates

Quality Assurance

  • RAGAS evaluation metrics integration
  • Automatic answer improvement below 0.7 threshold
  • Source validation and metadata preservation

πŸ› οΈ Development

Running in Development Mode

# 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.log

Testing Connectivity

curl -X POST http://localhost:3000/api/mcp \
  -H "Content-Type: application/json" \
  -d '{"name": "test_search", "arguments": {"input_query": "test"}}'

πŸ†˜ Troubleshooting

Common Issues

  1. MCP Connection Failed

    # Ensure Python virtual environment is activated
    source .venv/bin/activate
    # Check Python path in MCPClientManager.js matches your setup
  2. ModuleNotFoundError:

    pip install -r requirements.txt
    # Ensure all 171+ dependencies are installed
  3. FAISS Index Error:

    # Verify data files exist
    ls -la data/chunks\(1\).index data/chunks_with_entities\(1\).json
  4. MongoDB Connection Issues:

    # Verify MongoDB URI format
    echo $MONGO_URI
    # Check network connectivity to MongoDB Atlas
  5. Azure OpenAI API Errors:

    # Verify API key and endpoint
    echo $AZURE_OPEN_AI_KEY
    # Check deployment name matches configuration
  6. Server Port Conflicts:

    # Check if port 3000 is available
    lsof -i :3000
    # Use different port: PORT=3001 npm start

Performance Optimization

  • 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

Logging and Debugging

# 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"}}'

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Follow the existing code style and architecture
  4. Add tests for new MCP tools
  5. Update documentation for new features
  6. Commit your changes (git commit -m 'Add some AmazingFeature')
  7. Push to the branch (git push origin feature/AmazingFeature)
  8. Open a Pull Request

Development Guidelines

  • MCP Tools: Add new tools to MCPServer.py with proper logging
  • Frontend: Maintain responsive design and accessibility
  • Documentation: Update README for any architectural changes
  • Testing: Include test queries for new search capabilities

πŸ“ License

This project is licensed under the ISC License - see the LICENSE file for details.

πŸ“ž Support

For questions or issues:

  1. Check logs: Review mcp_server.log for detailed error information
  2. Verify setup: Ensure all environment variables are configured
  3. Test connectivity: Use the test_search tool to verify MCP communication
  4. GitHub Issues: Report bugs with detailed error logs and system information

πŸ”¬ Research & Citations

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. πŸ”¬

About

Multi-layer RAG for smart literature review

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •