langchain.vectorstores.mongodb_atlas.MongoDBAtlasVectorSearch¶
class langchain.vectorstores.mongodb_atlas.MongoDBAtlasVectorSearch(collection: Collection[MongoDBDocumentType], embedding: Embeddings, *, index_name: str = 'default', text_key: str = 'text', embedding_key: str = 'embedding')[source]¶
MongoDB Atlas Vector Search vector store.
To use, you should have both:
- the pymongo python package installed
- a connection string associated with a MongoDB Atlas Cluster having deployed an
Atlas Search index
Example
from langchain.vectorstores import MongoDBAtlasVectorSearch
from langchain.embeddings.openai import OpenAIEmbeddings
from pymongo import MongoClient
mongo_client = MongoClient("<YOUR-CONNECTION-STRING>")
collection = mongo_client["<db_name>"]["<collection_name>"]
embeddings = OpenAIEmbeddings()
vectorstore = MongoDBAtlasVectorSearch(collection, embeddings)
Parameters
collection – MongoDB collection to add the texts to.
embedding – Text embedding model to use.
text_key – MongoDB field that will contain the text for each
document.
embedding_key – MongoDB field that will contain the embedding for
each document.
index_name – Name of the Atlas Search index.
Attributes
embeddings
Access the query embedding object if available.
Methods
__init__(collection, embedding, *[, ...])
param collection
MongoDB collection to add the texts to.
aadd_documents(documents, **kwargs)
Run more documents through the embeddings and add to the vectorstore.
aadd_texts(texts[, metadatas])
Run more texts through the embeddings and add to the vectorstore.
add_documents(documents, **kwargs)
Run more documents through the embeddings and add to the vectorstore.
add_texts(texts[, metadatas])