.ipynb
.pdf
 Contents 
Commented out until further notice
MongoDB Atlas Vector Search
MongoDB Atlas is a fully-managed cloud database available in AWS , Azure, and GCP.  It now has support for native Vector Search on your MongoDB document data.
This notebook shows how to use MongoDB Atlas Vector Search to store your embeddings in MongoDB documents, create a vector search index, and perform KNN search with an approximate nearest neighbor algorithm.
It uses the knnBeta Operator available in MongoDB Atlas Search. This feature is in Public Preview and available for evaluation purposes, to validate functionality, and to gather feedback from public preview users. It is not recommended for production deployments as we may introduce breaking changes.
To use MongoDB Atlas, you must first deploy a cluster. We have a Forever-Free tier of clusters available.
To get started head over to Atlas here: quick start.
!pip install pymongo
import os
import getpass
MONGODB_ATLAS_CLUSTER_URI = getpass.getpass('MongoDB Atlas Cluster URI:')
MONGODB_ATLAS_CLUSTER_URI = os.environ['MONGODB_ATLAS_CLUSTER_URI']
We want to use OpenAIEmbeddings so we need to set up our OpenAI API Key.
os.environ['OPENAI_API_KEY'] = getpass.getpass('OpenAI API Key:')
OPENAI_API_KEY = os.environ['OPENAI_API_KEY']
Now, let’s create a vector search index on your cluster. In the below example, embedding is the name of the field that contains the embedding vector. Please refer to the documentation to get more details on how to define an Atlas Vector Search index.
You can name the index langchain_demo and create the index on the namespace lanchain_db.langchain_col. Finally, write the following definition in the JSON editor on MongoDB Atlas:
{
  "mappings": {
    "dynamic": true,
    "fields": {
rtdocs_stable/api.python.langchain.com/en/stable/modules/indexes/vectorstores/examples/mongodb_atlas_vector_search.html