Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# MongoDB Documentation Notebooks

This repository contains Jupyter Notebooks that follow
tutorials and code examples in MongoDB's official [Atlas Vector Search documentation](https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-overview/). You can run, download, and modify these notebooks as you learn how to use MongoDB Atlas Vector Search for your use case.
tutorials and code examples in the official [MongoDB Vector Search documentation](https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-overview/). You can run, download, and modify these notebooks as you learn how to use MongoDB Vector Search for your use case.

## Overview

Expand All @@ -22,7 +22,7 @@ The following table summarizes the contents of the notebooks in each directory:

## Other Resources

- [MongoDB Official Documentation](https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-overview/)
- [MongoDB Vector Search Documentation](https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-overview/)
- [Generative AI Use Cases Repository](https://github.com/mongodb-developer/GenAI-Showcase/tree/main)

## License
Expand Down
10 changes: 5 additions & 5 deletions ai-integrations/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# AI Integrations

This folder contains Jupyter Notebooks that demonstrate how to integrate various AI frameworks with MongoDB. These notebooks show you how to implement RAG and other features for your AI-powered and agentic applications by leveraging MongoDB Atlas as both a vector database and document database.
This folder contains Jupyter Notebooks that demonstrate how to integrate various AI frameworks with MongoDB. These notebooks show you how to implement RAG and other features for your AI-powered and agentic applications by leveraging MongoDB as both a vector database and document database.

| Notebook | Description |
|----------|-------------|
| [langchain](https://github.com/mongodb/docs-notebooks/blob/main/ai-integrations/langchain.ipynb) | Implement basic RAG with LangChain and MongoDB Atlas Vector Search |
| [langchain](https://github.com/mongodb/docs-notebooks/blob/main/ai-integrations/langchain.ipynb) | Implement basic RAG with LangChain and MongoDB Vector Search |
| [langchain-memory-semantic-cache](https://github.com/mongodb/docs-notebooks/blob/main/ai-integrations/langchain-memory-semantic-cache.ipynb) | Implement RAG with memory with LangChain and MongoDB |
| [langchain-hybrid-search](https://github.com/mongodb/docs-notebooks/blob/main/ai-integrations/langchain-hybrid-search.ipynb) | Combine vector search with full-text search using LangChain and MongoDB |
| [langchain-parent-document-retrieval](https://github.com/mongodb/docs-notebooks/blob/main/ai-integrations/langchain-parent-document-retrieval.ipynb) | Perform parent-document retrieval with LangChain and MongoDB |
Expand All @@ -13,6 +13,6 @@ This folder contains Jupyter Notebooks that demonstrate how to integrate various
| [langchain-graphrag](https://github.com/mongodb/docs-notebooks/blob/main/ai-integrations/langchain-graphrag.ipynb) | Implement graph-based RAG with LangChain and MongoDB |
| [langchain-natural-language](https://github.com/mongodb/docs-notebooks/blob/main/ai-integrations/langchain-natural-language.ipynb) | Perform natural language querying with LangChain and MongoDB |
| [langgraph](https://github.com/mongodb/docs-notebooks/blob/main/ai-integrations/langgraph.ipynb) | Build an AI agent with LangGraph and MongoDB |
| [llamaindex](https://github.com/mongodb/docs-notebooks/blob/main/ai-integrations/llamaindex.ipynb) | Implement basic RAG with LlamaIndex and MongoDB Atlas |
| [haystack](https://github.com/mongodb/docs-notebooks/blob/main/ai-integrations/haystack.ipynb) | Implement basic RAG with Haystack and MongoDB Atlas |
| [semantic-kernel](https://github.com/mongodb/docs-notebooks/blob/main/ai-integrations/semantic-kernel.ipynb) | Implement basic RAG with Microsoft Semantic Kernel and MongoDB Atlas |
| [llamaindex](https://github.com/mongodb/docs-notebooks/blob/main/ai-integrations/llamaindex.ipynb) | Implement basic RAG with LlamaIndex and MongoDB |
| [haystack](https://github.com/mongodb/docs-notebooks/blob/main/ai-integrations/haystack.ipynb) | Implement basic RAG with Haystack and MongoDB |
| [semantic-kernel](https://github.com/mongodb/docs-notebooks/blob/main/ai-integrations/semantic-kernel.ipynb) | Implement basic RAG with Microsoft Semantic Kernel and MongoDB |
2 changes: 1 addition & 1 deletion ai-integrations/haystack.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Atlas Vector Search - Haystack Integration"
"# MongoDB Vector Search - Haystack Integration"
]
},
{
Expand Down
24 changes: 12 additions & 12 deletions ai-integrations/langchain-graphrag.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"\n",
"This notebook is a companion to the [GraphRAG with MongoDB and LangChain](https://www.mongodb.com/docs/atlas/ai-integrations/langchain/graph-rag/) tutorial. Refer to the page for set-up instructions and detailed explanations.\n",
"\n",
"This notebook demonstrates a GraphRAG implementation using MongoDB Atlas and LangChain. Compared to vector-based RAG, which structures your data as vector embeddings, GraphRAG structures data as a knowledge graph with entities and their relationships. This enables relationship-aware retrieval and multi-hop reasoning.\n",
"This notebook demonstrates a GraphRAG implementation using MongoDB and LangChain. Compared to vector-based RAG, which structures your data as vector embeddings, GraphRAG structures data as a knowledge graph with entities and their relationships. This enables relationship-aware retrieval and multi-hop reasoning.\n",
"\n",
"<a target=\"_blank\" href=\"https://colab.research.google.com/github/mongodb/docs-notebooks/blob/main/ai-integrations/langchain-graphrag.ipynb\">\n",
" <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/>\n",
Expand Down Expand Up @@ -37,7 +37,7 @@
"\n",
"Before you begin, make sure you have the following:\n",
"\n",
"- An Atlas cluster up and running (you'll need the [connection string](https://www.mongodb.com/docs/guides/atlas/connection-string/))\n",
"- A MongoDB cluster up and running (you'll need the [connection string](https://www.mongodb.com/docs/manual/reference/connection-string/))\n",
"- An API key to access an LLM (This tutorial uses a model from OpenAI, but you can use any model [supported by LangChain](https://python.langchain.com/docs/integrations/chat/))"
]
},
Expand All @@ -51,17 +51,17 @@
"import os\n",
"\n",
"os.environ[\"OPENAI_API_KEY\"] = \"<api-key>\"\n",
"ATLAS_CONNECTION_STRING = \"<connection-string>\"\n",
"ATLAS_DB_NAME = \"langchain_db\" # MongoDB database to store the knowledge graph\n",
"ATLAS_COLLECTION = \"wikipedia\" # MongoDB collection to store the knowledge graph"
"MONGODB_URI = \"<connection-string>\"\n",
"DB_NAME = \"langchain_db\" # MongoDB database to store the knowledge graph\n",
"COLLECTION = \"wikipedia\" # MongoDB collection to store the knowledge graph"
]
},
{
"cell_type": "markdown",
"id": "0adf66a8",
"metadata": {},
"source": [
"## Use MongoDB Atlas as a knowledge graph\n",
"## Use MongoDB as a knowledge graph\n",
"\n",
"Use the `MongoDBGraphStore` component to store your data as a knowledge graph. This component allows you to implement GraphRAG by storing entities (nodes) and their relationships (edges) in a MongoDB collection. It stores each entity as a document with relationship fields that reference other documents in your collection."
]
Expand Down Expand Up @@ -111,9 +111,9 @@
"from langchain_mongodb.graphrag.graph import MongoDBGraphStore\n",
"\n",
"graph_store = MongoDBGraphStore(\n",
" connection_string = ATLAS_CONNECTION_STRING,\n",
" database_name = ATLAS_DB_NAME,\n",
" collection_name = ATLAS_COLLECTION,\n",
" connection_string = MONGODB_URI,\n",
" database_name = DB_NAME,\n",
" collection_name = COLLECTION,\n",
" entity_extraction_model = chat_model\n",
")"
]
Expand All @@ -125,7 +125,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Extract entities and create knowledge graph in Atlas\n",
"# Extract entities and create knowledge graph in MongoDB\n",
"# This might take a few minutes; you can ignore any warnings\n",
"graph_store.add_documents(wikipedia_docs)"
]
Expand Down Expand Up @@ -222,9 +222,9 @@
"from IPython.display import HTML, display\n",
"from pymongo import MongoClient\n",
"\n",
"client = MongoClient(ATLAS_CONNECTION_STRING)\n",
"client = MongoClient(MONGODB_URI)\n",
"\n",
"collection = client[ATLAS_DB_NAME][ATLAS_COLLECTION]\n",
"collection = client[DB_NAME][COLLECTION]\n",
"html = visualize_graph(collection)\n",
"\n",
"display(HTML(html))"
Expand Down
6 changes: 3 additions & 3 deletions ai-integrations/langchain-hybrid-search.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"\n",
"os.environ[\"OPENAI_API_KEY\"] = \"<api-key>\"\n",
"os.environ[\"VOYAGE_API_KEY\"] = \"<voyage-api-key>\"\n",
"ATLAS_CONNECTION_STRING = \"<connection-string>\""
"MONGODB_URI = \"<connection-string>\""
]
},
{
Expand All @@ -55,7 +55,7 @@
"\n",
"# Create the vector store\n",
"vector_store = MongoDBAtlasVectorSearch.from_connection_string(\n",
" connection_string = ATLAS_CONNECTION_STRING,\n",
" connection_string = MONGODB_URI,\n",
" embedding = VoyageAIEmbeddings(model = \"voyage-3-large\", output_dimension = 2048),\n",
" namespace = \"sample_mflix.embedded_movies\",\n",
" text_key = \"plot\",\n",
Expand Down Expand Up @@ -87,7 +87,7 @@
"from pymongo import MongoClient\n",
"\n",
"# Connect to your cluster\n",
"client = MongoClient(ATLAS_CONNECTION_STRING)\n",
"client = MongoClient(MONGODB_URI)\n",
"\n",
"# Use helper method to create the search index\n",
"create_fulltext_search_index(\n",
Expand Down
2 changes: 1 addition & 1 deletion ai-integrations/langchain-local-rag.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
"from langchain_core.runnables import RunnablePassthrough\n",
"import pprint\n",
"\n",
"# Instantiate Atlas Vector Search as a retriever\n",
"# Instantiate MongoDB Vector Search as a retriever\n",
"retriever = vector_store.as_retriever()\n",
"\n",
"# Define prompt template\n",
Expand Down
58 changes: 29 additions & 29 deletions ai-integrations/langchain-natural-language.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
"id": "f9696293",
"metadata": {},
"source": [
"# Query Atlas with Natural Language Using LangChain and LangGraph"
"# Query MongoDB with Natural Language Using LangChain and LangGraph"
]
},
{
"cell_type": "markdown",
"id": "e696dea0",
"metadata": {},
"source": [
"This notebook is a companion to the [Query Atlas with Natural Language Using LangChain and LangGraph](https://www.mongodb.com/docs/atlas/ai-integrations/langchain/natural-language-to-mql/) tutorial. Refer to the page for set-up instructions and detailed explanations.\n",
"This notebook is a companion to the [Query MongoDB with Natural Language Using LangChain and LangGraph](https://www.mongodb.com/docs/atlas/ai-integrations/langchain/natural-language-to-mql/) tutorial. Refer to the page for set-up instructions and detailed explanations.\n",
"\n",
"This notebook demonstrates how to query an Atlas cluster with a natural language prompt using an AI agent built with the [LangChain MongoDB Toolkit](https://langchain-mongodb.readthedocs.io/en/latest/langchain_mongodb/agent_toolkit/langchain_mongodb.agent_toolkit.toolkit.MongoDBDatabaseToolkit.html#langchain_mongodb.agent_toolkit.toolkit.MongoDBDatabaseToolkit) and the [LangGraph ReAct Agent Framework](https://langchain-ai.github.io/langgraph/agents/agents/).\n",
"This notebook demonstrates how to query a MongoDB cluster with a natural language prompt using an AI agent built with the [LangChain MongoDB Toolkit](https://langchain-mongodb.readthedocs.io/en/latest/langchain_mongodb/agent_toolkit/langchain_mongodb.agent_toolkit.toolkit.MongoDBDatabaseToolkit.html#langchain_mongodb.agent_toolkit.toolkit.MongoDBDatabaseToolkit) and the [LangGraph ReAct Agent Framework](https://langchain-ai.github.io/langgraph/agents/agents/).\n",
"\n",
"<a target=\"_blank\" href=\"https://colab.research.google.com/github/mongodb/docs-notebooks/blob/main/ai-integrations/langchain-natural-language.ipynb\">\n",
" <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/>\n",
Expand Down Expand Up @@ -45,7 +45,7 @@
"\n",
"Before you begin, make sure you have the following:\n",
"\n",
"- An Atlas cluster up and running (you'll need the [connection string](https://www.mongodb.com/docs/guides/atlas/connection-string/))\n",
"- A MongoDB cluster up and running (you'll need the [connection string](https://www.mongodb.com/docs/manual/reference/connection-string/))\n",
"- An API key to access an LLM (This tutorial uses a model from OpenAI, but you can use any model [supported by LangChain](https://python.langchain.com/docs/integrations/chat/))"
]
},
Expand All @@ -57,8 +57,8 @@
"outputs": [],
"source": [
"os.environ[\"OPENAI_API_KEY\"] = '<api-key>'\n",
"ATLAS_CONNECTION_STRING = '<atlas-connection-string>'\n",
"ATLAS_DB_NAME = 'sample_restaurants'\n",
"MONGODB_URI = '<connection-string>'\n",
"DB_NAME = 'sample_restaurants'\n",
"NATURAL_LANGUAGE_QUERY = 'Find all restaurants that serve hamburgers.'"
]
},
Expand Down Expand Up @@ -107,8 +107,8 @@
" self.llm = ChatOpenAI(model=\"gpt-4o-mini\", timeout=60)\n",
" self.system_message = MONGODB_AGENT_SYSTEM_PROMPT.format(top_k=5)\n",
" self.db_wrapper = MongoDBDatabase.from_connection_string(\n",
" ATLAS_CONNECTION_STRING, \n",
" database=ATLAS_DB_NAME)\n",
" MONGODB_URI, \n",
" database=DB_NAME)\n",
" self.toolkit = MongoDBDatabaseToolkit(db=self.db_wrapper, llm=self.llm)\n",
" self.agent = create_react_agent(\n",
" self.llm, \n",
Expand Down Expand Up @@ -158,25 +158,25 @@
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"nbformat": 4,
"nbformat_minor": 2
}
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
4 changes: 2 additions & 2 deletions ai-integrations/langchain-parent-document-retrieval.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"\n",
"os.environ[\"VOYAGE_API_KEY\"] = \"<voyage-api-key>\"\n",
"os.environ[\"OPENAI_API_KEY\"] = \"<openai-api-key>\"\n",
"ATLAS_CONNECTION_STRING = \"<connection-string>\""
"MONGODB_URI = \"<connection-string>\""
]
},
{
Expand Down Expand Up @@ -86,7 +86,7 @@
"\n",
"# Create the parent document retriever\n",
"parent_doc_retriever = MongoDBAtlasParentDocumentRetriever.from_connection_string(\n",
" connection_string = ATLAS_CONNECTION_STRING,\n",
" connection_string = MONGODB_URI,\n",
" child_splitter = child_splitter,\n",
" embedding_model = embedding_model,\n",
" database_name = database_name,\n",
Expand Down
2 changes: 1 addition & 1 deletion ai-integrations/langchain-self-query-retrieval.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
"id": "a5762ee0",
"metadata": {},
"source": [
"## Create the Atlas Vector Search index with filters"
"## Create the Vector Search index with filters"
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions ai-integrations/langchain.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"\n",
"os.environ[\"VOYAGE_API_KEY\"] = \"<voyage-api-key>\"\n",
"os.environ[\"OPENAI_API_KEY\"] = \"<openai-api-key>\"\n",
"ATLAS_CONNECTION_STRING = \"<connection-string>\""
"MONGODB_URI = \"<connection-string>\""
]
},
{
Expand Down Expand Up @@ -76,7 +76,7 @@
"\n",
"# Instantiate the vector store using your MongoDB connection string\n",
"vector_store = MongoDBAtlasVectorSearch.from_connection_string(\n",
" connection_string = ATLAS_CONNECTION_STRING,\n",
" connection_string = MONGODB_URI,\n",
" namespace = \"langchain_db.test\",\n",
" embedding = VoyageAIEmbeddings(model=\"voyage-3-large\"),\n",
" index_name = \"vector_index\"\n",
Expand Down Expand Up @@ -184,7 +184,7 @@
"from langchain_openai import ChatOpenAI\n",
"from langchain.prompts import PromptTemplate\n",
"\n",
"# Instantiate Atlas Vector Search as a retriever\n",
"# Instantiate MongoDB Vector Search as a retriever\n",
"retriever = vector_store.as_retriever(\n",
" search_type = \"similarity\",\n",
" search_kwargs = { \"k\": 10 }\n",
Expand Down Expand Up @@ -241,7 +241,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Instantiate Atlas Vector Search as a retriever\n",
"# Instantiate MongoDB Vector Search as a retriever\n",
"retriever = vector_store.as_retriever(\n",
" search_type = \"similarity\",\n",
" search_kwargs = {\n",
Expand Down
8 changes: 4 additions & 4 deletions ai-integrations/langgraph.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"This notebook is a companion to the [Build AI Agents with LangGraph and MongoDB](https://www.mongodb.com/docs/atlas/ai-integrations/langgraph/build-agents) page. For the complete Python application and detailed explanations of the code, refer to the tutorial on the page.\n",
"\n",
"This notebook takes you through how to use LangGraph to implement agentic RAG and agent memory (short and long-term) \n",
"by using MongoDB Atlas as the vector database, LangChain to implement retrieval tools, and LangGraph to orchestrate the agent workflow.\n",
"by using MongoDB as the vector database, LangChain to implement retrieval tools, and LangGraph to orchestrate the agent workflow.\n",
"\n",
"<a target=\"_blank\" href=\"https://colab.research.google.com/github/mongodb/docs-notebooks/blob/main/ai-integrations/langgraph.ipynb\">\n",
" <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/>\n",
Expand All @@ -33,7 +33,7 @@
"[langchain-voyageai](https://pypi.org/project/langchain-voyageai/) package\n",
"to ensure you're using a compatible Python version.\n",
"\n",
"Before you begin, load the `sample_mflix` dataset into your Atlas cluster if you haven't already. To learn more, see [Load Data into Atlas](https://www.mongodb.com/docs/atlas/sample-data/)."
"Before you begin, load the `sample_mflix` dataset into your MongoDB cluster if you haven't already. To learn more, see [Sample Data](https://www.mongodb.com/docs/atlas/sample-data/)."
]
},
{
Expand Down Expand Up @@ -75,7 +75,7 @@
"id": "UUf3jtFzO4-V"
},
"source": [
"## Use Atlas as a vector database"
"## Use MongoDB as a vector database"
]
},
{
Expand Down Expand Up @@ -195,7 +195,7 @@
" \n",
" # Initialize the retriever\n",
" retriever = MongoDBAtlasFullTextSearchRetriever(\n",
" collection = collection, # MongoDB Collection in Atlas\n",
" collection = collection, # MongoDB Collection\n",
" search_field = \"title\", # Name of the field to search\n",
" search_index_name = \"search_index\", # Name of the search index\n",
" top_k = 1, # Number of top results to return \n",
Expand Down
Loading