MCP_Server_For_VectorDB

saishshinde15/MCP_Server_For_VectorDB

3.2

If you are the rightful owner of MCP_Server_For_VectorDB and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

This project implements a simplified agentic RAG system using LangChain, Google's Gemini 2.0 Flash model, Serper API, Chroma, and MCP for the agent framework.

Tools
4
Resources
0
Prompts
0

Simplified Agentic RAG with LangChain, Gemini 2.0 Flash, and Serper API

This project implements a simplified agentic RAG (Retrieval Augmented Generation) system using:

Quick Start

  1. Clone this repository

    git clone https://github.com/YOUR_USERNAME/rag-gemini-system.git
    cd rag-gemini-system
    
  2. Install dependencies

    pip install -r requirements.txt
    
  3. Set up API keys

    • Create a .env file in the project root
    • Add your API keys:
      GOOGLE_API_KEY=your_google_api_key_here
      SERPER_API_KEY=your_serper_api_key_here
      
  4. Run the demo

    python demo.py
    

Important Note on Dependencies

This project uses the latest LangChain packages with their updated import structure. The code includes fallbacks to ensure compatibility with both newer and older versions of LangChain.

For the best experience, install the recommended packages:

pip install -r requirements.txt

If you encounter any import errors, you may need to install additional packages:

pip install langchain-huggingface langchain-chroma

Project Structure

  • vector_store.py: All-in-one file that manages the vector database, Gemini integration, and web search
  • server.py: Implements the MCP server with tools for RAG
  • demo.py: Simple script to test the RAG system
  • demo_notebook.ipynb: Jupyter notebook demonstrating the system
  • rag_notebook.ipynb: Step-by-step notebook explaining RAG implementation with LangChain
  • requirements.txt: List of required Python packages

Setup and Installation

Prerequisites

  • Python 3.9 or later
  • Google Gemini API key
  • Serper API key

API Keys

  1. Google Gemini API Key:

    • Go to Google AI Studio
    • Create an API key
    • Add it to your .env file as GOOGLE_API_KEY
  2. Serper API Key:

    • Go to Serper.dev and sign up
    • Create an API key
    • Add it to your .env file as SERPER_API_KEY

Environment Setup

  1. Clone this repository:

    git clone <repository-url>
    cd <repository-directory>
    
  2. Create a .env file with your API keys:

    GOOGLE_API_KEY="your_google_api_key_here"
    SERPER_API_KEY="your_serper_api_key_here"
    
  3. Install dependencies:

    pip install -r requirements.txt
    

Running the System

Run the Demo

To test the system without MCP, run the demo script:

python demo.py

Or use one of the Jupyter notebooks:

jupyter notebook demo_notebook.ipynb  # For a quick demo of the system
jupyter notebook rag_notebook.ipynb   # For a detailed step-by-step explanation

Start the MCP Server

To use the system with MCP, run the server script:

python server.py

Configure MCP in Different Environments

Option 1: Cursor IDE
  1. Open Cursor IDE settings

  2. Select MCP

  3. Add a new global MCP server with the following configuration:

    {
      "mcpServers": {
          "MCP-RAG-Gemini-app": {
              "command": "python",
              "args": ["/absolute/path/to/server.py"], ## Server absolute path
              "host": "127.0.0.1",
              "port": 8080,
              "timeout": 30000
          }
      }
    }
    

    Important: Make sure to replace /absolute/path/to/server.py with the actual absolute path to the server.py file on your system.

  4. After configuring the MCP server:

    • Restart Cursor IDE
    • Open the AI panel (usually by clicking on the AI icon in the sidebar)
    • Select "MCP-RAG-Gemini-app" from the dropdown menu of available AI models
    • You can now ask questions about machine learning, and the RAG system will provide answers using the vector store and web search as needed
Option 2: Augment
  1. Open Augment settings
  2. Go to the MCP section
  3. Click "New MCP Server"
  4. Fill out the form:
    • Name: MCP-RAG-Gemini-app
    • Command: python /absolute/path/to/server.py (Replace with the actual path to your server.py file)
    • No environment variables needed if your .env file is set up correctly
  5. Click "Add"
  6. Make sure your server is running
  7. Select "MCP-RAG-Gemini-app" from the model dropdown in Augment
Option 3: Claude Desktop
  1. Open Claude Desktop settings
  2. Go to the MCP section
  3. Add the following configuration:
    {
      "mcpServers": {
          "MCP-RAG-Gemini-app": {
              "command": "python",
              "args": ["/absolute/path/to/server.py"],
              "host": "127.0.0.1",
              "port": 8080,
              "timeout": 30000
          }
      }
    }
    
  4. Replace /absolute/path/to/server.py with the actual path
  5. Restart Claude Desktop
  6. Select "MCP-RAG-Gemini-app" from the model dropdown

Troubleshooting MCP Connection

If you encounter "Module not found" errors:

  1. Make sure the MCP package is installed:

    pip install mcp
    
  2. Try running the server manually first:

    cd /path/to/project
    python server.py
    
  3. If using Windows, use proper path formatting:

    C:\\Users\\username\\path\\to\\server.py
    

    or

    C:/Users/username/path/to/server.py
    
  4. Create a batch file (Windows) or shell script (Linux/Mac) to run the server with the correct environment

How It Works

All-in-One RAG System

The RAGSystem class in vector_store.py handles all aspects of the RAG pipeline:

  1. Vector Store: Uses Chroma to store and retrieve embeddings

    • Automatically creates and persists the vector database
    • Uses HuggingFace's sentence-transformers for embeddings
    • Supports both langchain_community and langchain_chroma implementations
    • Stores documents in a local directory (./chroma_db)
    • Includes rich metadata for better retrieval
  2. LLM Integration: Directly integrates Google's Gemini 2.0 Flash model

    • Uses LangChain's ChatGoogleGenerativeAI wrapper
    • Implements RetrievalQA for answering questions with context
    • Includes fallbacks for compatibility with different versions
  3. Web Search: Includes built-in Serper API integration

    • Uses LangChain's GoogleSerperAPIWrapper for web search
    • Falls back to web search when vector store doesn't have relevant information
    • Formats search results for easy reading
  4. Complete RAG Pipeline: Combines all components

    • First tries to answer from the vector store
    • Falls back to web search if needed
    • Uses Gemini to generate the final answer

MCP Server

The MCP server in server.py exposes several tools:

  • search_vector_store: Retrieves information from the vector database
  • search_web: Searches the web using Serper API
  • answer_question: Generates answers using Gemini with vector store context
  • rag_pipeline: Combines all tools into a complete RAG pipeline

Extending the System

Adding New Data

To add new data to the vector store:

  1. Prepare your text data
  2. Use the RAGSystem.ingest_data() method to add it to the database

Using Different Embedding Models

To use a different embedding model:

  1. Modify the model_name parameter in the HuggingFaceEmbeddings initialization

Using Different LLMs

To use a different LLM:

  1. Replace the ChatGoogleGenerativeAI initialization with your preferred LLM
  2. Update the RetrievalQA chain if needed

Troubleshooting

  • API Key Errors: Verify that your .env file contains the correct API keys
  • MCP Server Configuration: Ensure the path to server.py in your Cursor IDE configuration is correct
  • Missing Dependencies: Make sure all required packages are installed
  • Deprecation Warnings: The code includes fallbacks for both newer and older LangChain imports. If you see deprecation warnings, you can install the recommended packages:
    pip install langchain-huggingface langchain-chroma
    
  • Import Errors: If you encounter import errors, try installing the specific package mentioned in the error message

Using from GitHub

For Contributors

If you want to contribute to this project:

  1. Fork the repository on GitHub
  2. Clone your fork:
    git clone https://github.com/YOUR_USERNAME/rag-gemini-system.git
    cd rag-gemini-system
    
  3. Create a new branch:
    git checkout -b feature/your-feature-name
    
  4. Make your changes
  5. Test your changes
  6. Commit and push:
    git add .
    git commit -m "Add your feature description"
    git push origin feature/your-feature-name
    
  7. Create a Pull Request on GitHub

For Users

If you just want to use this project:

  1. Clone the repository:

    git clone https://github.com/ORIGINAL_OWNER/rag-gemini-system.git
    cd rag-gemini-system
    
  2. Create a virtual environment (recommended):

    # On Windows
    python -m venv venv
    venv\Scripts\activate
    
    # On macOS/Linux
    python -m venv venv
    source venv/bin/activate
    
  3. Install dependencies:

    pip install -r requirements.txt
    
  4. Set up your API keys in a .env file:

    GOOGLE_API_KEY=your_google_api_key_here
    SERPER_API_KEY=your_serper_api_key_here
    
  5. Run the system as described in the Quick Start section

Keeping Up to Date

To update your local copy with the latest changes:

git pull origin main

License

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

Acknowledgments

  • This project was inspired by the MCP-Agentic-RAG project
  • Thanks to the developers of LangChain, Chroma, and MCP for their excellent tools