saishshinde15/MCP_Server_For_VectorDB
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.
Simplified Agentic RAG with LangChain, Gemini 2.0 Flash, and Serper API
This project implements a simplified agentic RAG (Retrieval Augmented Generation) system using:
- LangChain for the RAG pipeline
- Google's Gemini 2.0 Flash model for text generation
- Serper API for web search
- Chroma as the vector database
- MCP (Machine Conversation Protocol) for the agent framework
Quick Start
-
Clone this repository
git clone https://github.com/YOUR_USERNAME/rag-gemini-system.git cd rag-gemini-system
-
Install dependencies
pip install -r requirements.txt
-
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
- Create a
-
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 searchserver.py
: Implements the MCP server with tools for RAGdemo.py
: Simple script to test the RAG systemdemo_notebook.ipynb
: Jupyter notebook demonstrating the systemrag_notebook.ipynb
: Step-by-step notebook explaining RAG implementation with LangChainrequirements.txt
: List of required Python packages
Setup and Installation
Prerequisites
- Python 3.9 or later
- Google Gemini API key
- Serper API key
API Keys
-
Google Gemini API Key:
- Go to Google AI Studio
- Create an API key
- Add it to your
.env
file asGOOGLE_API_KEY
-
Serper API Key:
- Go to Serper.dev and sign up
- Create an API key
- Add it to your
.env
file asSERPER_API_KEY
Environment Setup
-
Clone this repository:
git clone <repository-url> cd <repository-directory>
-
Create a
.env
file with your API keys:GOOGLE_API_KEY="your_google_api_key_here" SERPER_API_KEY="your_serper_api_key_here"
-
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
-
Open Cursor IDE settings
-
Select MCP
-
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. -
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
- Open Augment settings
- Go to the MCP section
- Click "New MCP Server"
- 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
- Name:
- Click "Add"
- Make sure your server is running
- Select "MCP-RAG-Gemini-app" from the model dropdown in Augment
Option 3: Claude Desktop
- Open Claude Desktop settings
- Go to the MCP section
- 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 } } }
- Replace
/absolute/path/to/server.py
with the actual path - Restart Claude Desktop
- Select "MCP-RAG-Gemini-app" from the model dropdown
Troubleshooting MCP Connection
If you encounter "Module not found" errors:
-
Make sure the MCP package is installed:
pip install mcp
-
Try running the server manually first:
cd /path/to/project python server.py
-
If using Windows, use proper path formatting:
C:\\Users\\username\\path\\to\\server.py
or
C:/Users/username/path/to/server.py
-
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:
-
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
-
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
-
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
-
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 databasesearch_web
: Searches the web using Serper APIanswer_question
: Generates answers using Gemini with vector store contextrag_pipeline
: Combines all tools into a complete RAG pipeline
Extending the System
Adding New Data
To add new data to the vector store:
- Prepare your text data
- Use the
RAGSystem.ingest_data()
method to add it to the database
Using Different Embedding Models
To use a different embedding model:
- Modify the
model_name
parameter in the HuggingFaceEmbeddings initialization
Using Different LLMs
To use a different LLM:
- Replace the ChatGoogleGenerativeAI initialization with your preferred LLM
- 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:
- Fork the repository on GitHub
- Clone your fork:
git clone https://github.com/YOUR_USERNAME/rag-gemini-system.git cd rag-gemini-system
- Create a new branch:
git checkout -b feature/your-feature-name
- Make your changes
- Test your changes
- Commit and push:
git add . git commit -m "Add your feature description" git push origin feature/your-feature-name
- Create a Pull Request on GitHub
For Users
If you just want to use this project:
-
Clone the repository:
git clone https://github.com/ORIGINAL_OWNER/rag-gemini-system.git cd rag-gemini-system
-
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
-
Install dependencies:
pip install -r requirements.txt
-
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
-
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