MongoDB Vector Store
MongoDB Vector Store stores documents in a MongoDB Atlas collection and searches it by meaning, using an Atlas vector search index.
A vector database stores texts so they can be searched by meaning, not just by exact words. That way an agent can find the paragraph of a manual that answers a question even if it uses different words.
When to use it
- Your data already lives in MongoDB Atlas and you want an agent to search it by meaning.
- You want to keep a knowledge base’s documents next to the rest of your application data.
- You need to search a large collection with an index managed by Atlas.
Configuration
The Operation field decides what the component does, and the fields and outputs change with your choice:
Add(default): stores in the database the documents it receives in Ingest Data.Search: finds the documents closest to the text in Search Query.Retriever: offers the database as a search engine for another component to use, for example an agent or a question-answering chain.
You need a MongoDB Connection credential with your MongoDB cluster details. See Credentials.
| Field | What it does |
|---|---|
| Credential (required) | The MongoDB Connection credential with the connection details. |
| Operation | What the component does: Add, Search or Retriever. |
| Ingest Data (required) | With Add. The documents to store, usually those coming out of a text splitter or a file loader. |
| Search Query | With Search. The text to search for. Required. |
| Embedding (required) | The connector where you plug the component that turns texts into numbers to compare them by meaning, such as OpenAI Embeddings. Always use the same one to store and to search. |
| Database Name (required) | The MongoDB database. |
| Collection Name (required) | The collection that holds the documents. |
| Vector Search Index Name (required) | The name of the vector search index created in Atlas for that collection. You can create it with Search Index. |
Advanced options
| Field | What it does |
|---|---|
| Number Of Results | How many documents each search returns. Default: 4. |
| Search Type | How to search: similarity, similarity_score_threshold. Similarity returns the closest; with a threshold, only those above Search Score Threshold. |
| Score Threshold | Minimum similarity score with the threshold search. Default: 0.7. |
Output
The outputs depend on Operation:
- Results: with
AddandSearch. WithSearch, the list of documents found, which you can pass to a prompt or an agent. - Vector Store: with
Add. The database, to connect it to components that work with a vector database. - Retriever: with
Retriever. The search engine, to connect it to components that ask for one.
In tool mode, an agent can use the component to search by itself. See Tool Mode.
Example
A course platform keeps its lessons in MongoDB Atlas and wants an assistant that quotes them.
- Create the collection’s vector index with Search Index.
- Add MongoDB Vector Store with Operation set to
Search, the database, the collection and the index name. - Put it in tool mode and connect it to the assistant’s agent.
Good practices
- This component does not filter by metadata: MongoDB Atlas only filters on the fields you declare as filters in the vector search index. If you need filters, use Qdrant, PGVector or Elasticsearch, which have metadata filters.
Related components
- Document and Search Index: manage MongoDB documents and indexes.
- Recursive Character Text Splitter: cuts documents into pieces before storing them.
- OpenAI Embeddings: converts texts so they can be searched by meaning.