This project demonstrates how to implement vector search using Sentence-Transformers locally and on MongoDB Atlas, followed by integrating OpenAI’s Model Context Protocol (MCP) for intelligent routing and semantic querying. For more details, see the Gen AI & Vector Search guide.
The project begins with populating data from the AG News dataset and showcases:
- Local Vector Search using Sentence-Transformers
- MongoDB Atlas Vector Search using
$vectorSearch
- Intent Routing via MCP to direct user input using semantic understanding
- OpenAI Integration with Azure to power a natural language interface
Install dependencies:
pip install -r requirements.txt
You can set environment variables in a .env
file or export them in your shell. Required variables include:
MONGO_URL
AZURE_OPENAI_API_KEY
AZURE_OPENAI_ENDPOINT
OPENAI_API_KEY
USE_AZURE_OPENAI
(set totrue
to use Azure OpenAI)
Example for Azure OpenAI (if using mcp_news_server.py
):
export AZURE_OPENAI_API_KEY=your_key
export AZURE_OPENAI_ENDPOINT=https://your-endpoint.openai.azure.com/
Populates the ag_news
collection with news data for use in local and Atlas vector search.
Performs vector search locally using Sentence-Transformers (all-MiniLM-L6-v2
).
Uses MongoDB Atlas's $vectorSearch
operator to run vector search on the cloud.
Demonstrates a simple MCP-based server and client setup to handle tool routing using user intent.
Extends mcp_server
by integrating Azure OpenAI to route user input intelligently and combine it with local vector search.
Provides a unified client for querying OpenAI or Azure OpenAI models.
-
Populate the database:
python load_data.py
-
Run local vector search demo:
python sbert_vector_search.py
-
Run Atlas vector search demo:
python atlas_vector_search.py
-
Start the MCP server:
python mcp_server.py
-
Send a query:
python mcp_client.py
-
Optional: For the AI-powered experience:
python mcp_news_server.py
To run all unit and integration tests:
python -m unittest discover -s tests
Licensed under the Apache License, Version 2.0. See the LICENSE file for more information.