from langchain.embeddings.openai import OpenAIEmbeddings
import os
MONGODB_ATLAS_URI = os.environ['MONGODB_ATLAS_URI']
# initialize MongoDB python client
client = MongoClient(MONGODB_ATLAS_URI)
db_name = "langchain_db"
collection_name = "langchain_col"
collection = client[db_name][collection_name]
index_name = "langchain_index"
# initialize vector store
vectorStore = MongoDBAtlasVectorSearch(
    collection, OpenAIEmbeddings(), index_name=index_name)
# perform a similarity search between the embedding of the query and the embeddings of the documents
query = "What did the president say about Ketanji Brown Jackson"
docs = vectorStore.similarity_search(query)
print(docs[0].page_content)
previous
Milvus
next
MyScale
 Contents
  
By Harrison Chase
    
      © Copyright 2023, Harrison Chase.
      
  Last updated on Jun 16, 2023.
rtdocs_stable/api.python.langchain.com/en/stable/modules/indexes/vectorstores/examples/mongodb_atlas_vector_search.html