Author : Georgios Ioannou
Copyright © 2024 by Georgios Ioannou
Setting Up MongoDB with Atlas Vector Search
Initial Setup
Create and log in to your MongoDB account at mongodb.com
Create Organization and Project
- Create a new MongoDB organization
- Name your organization as desired
- Create a new MongoDB project
- Name your project as desired
Create Cluster
- Select M0 (FREE) tier
- Wait 1-3 minutes for cluster creation
Security Setup
Create Database User
- Create username and password
- Important: Save these credentials securely
Configure Network Access
- Navigate on the left menu to Security -> Network Access
- Add IP Address:
0.0.0.0/0
(Allows access from anywhere)
Database Creation
- Set Up Database and Collection
- Click "Browse Collections"
- Click "Add My Own Data"
- Create database (e.g., "txts")
- Create collection (e.g., "txts_collection")
- Click "Create"
Vector Search Configuration
- Create Vector Search Index
- Click "Search Indexes" (This will bring you to "Atlas Search" tab)
- Click "Create Search Index"
- Select "JSON Editor" under "Atlas Vector Search"
- Click "Next"
- Configure index settings:
{ "name": "vector_index", // Adjust it to your desired name. "type": "vector", "path": "embedding", // Adjust it to your index/embedding column. "numDimensions": 384, // Adjust based on your model. (e.g., 384 for all-MiniLM-l6-v2) "similarity": "euclidean" // Adjust it to your desired similarity function. }
- Optional: Add filter fields if needed:
{ "type": "filter", "path": "source" // Adjust it to the column you would like to filter with. }
- Assign your index to the collection name created in step 6 using the drop down menu on the left.
- Click "Next"
- Click "Create Search Index"
- Wait for status to change from "Pending" to "Active"
Note: While vector search index creation can be done programmatically, the GUI method described above is recommended for simplicity.
Connection String
- Get Your MongoDB URI
- Click "Clusters" under DATABASE on the left menu
- Click "Connect" next to name of your cluster
- Select "Drivers"
- Copy the connection/MongoURI string at the very end of the modal that just opened
- Replace
<password>
with your database user password