Vector similarity search on MongoDB documents; The application supports REST API endpoints.
1.3K
Mongo Vector Search is a Dockerized application that demonstrates vector similarity search on MongoDB documents. It uses TensorFlow.js with the Universal Sentence Encoder to generate vector embeddings and provides REST API and WebSocket endpoints for performing and streaming search results.
/ping: Health check endpoint./embedding: Generate vector embeddings for text./search: Perform vector similarity searches.The recommended way to run this image is using Docker Compose.
Create a docker-compose.yml file:
version: "3.8"
services:
mongo-vector-search:
image: jlmconsulting/mongo-vector-search:latest
container_name: mongo-vector-search
platform: linux/amd64
ports:
- "8888:8888" # REST API Port & WebSocket Port
- "8887:8887" # HTTP Only
environment:
- MONGO_CONNECTION_STRING=mongodb+srv://youruser:[email protected]/ # Replace with your MongoDB connection string
- HTTPS_PORT=8888 # REST API HTTPS Port (if applicable in your setup)
- HTTP_PORT=8887 # WebSocket HTTP Port (if applicable in your setup)
- CERT_KEY_PATH=/app/data/certs/privkey1.pem # Path inside container (if using HTTPS/SSL)
- CERT_CERT_PATH=/app/data/certs/fullchain1.pem # Path inside container (if using HTTPS/SSL)
- CERT_CA_PATH=/app/data/certs/ca.pem # Path inside container (Optional CA cert, if using HTTPS/SSL)
volumes:
- ./data:/app/data # Mount volume for data persistence
restart: always
Create a .env file (optional but recommended):
Create a .env file in the same directory as your docker-compose.yml and set the MONGO_CONNECTION_STRING environment variable. This keeps your connection string out of your docker-compose.yml.
MONGO_CONNECTION_STRING=mongodb+srv://youruser:[email protected]/yourdb
Run Docker Compose:
docker-compose up -d
This will start the Mongo Vector Search application in detached mode.
The following environment variables can be used to configure the Mongo Vector Search application:
| Variable | Description | Required | Default Value |
|---|---|---|---|
MONGO_CONNECTION_STRING | Required. Your MongoDB Atlas connection string. This is essential for the application to connect to your MongoDB database. | Yes | None |
HTTPS_PORT | Port number for the HTTPS server (if you are configuring HTTPS for the REST API). If not set, the application might default to HTTP for the REST API on the port specified by HTTP_PORT. | No | 8888 |
HTTP_PORT | Port number for the HTTP server, used for the localhost endpoint and potentially for the REST API if HTTPS is not configured. Defaults to 8887 for WebSocket. | No | 8887 |
CERT_KEY_PATH | Path to your private key file (privkey1.pem) inside the container. This is only required if you are configuring HTTPS/SSL. When using Docker Compose and volume mounting ./data:/app/data, place your certificates in ./data/certs and set this to /app/data/certs/privkey1.pem. | No | None |
CERT_CERT_PATH | Path to your full chain certificate file (fullchain1.pem) inside the container. This is only required if you are configuring HTTPS/SSL. When using Docker Compose and volume mounting ./data:/app/data, place your certificates in ./data/certs and set this to /app/data/certs/fullchain1.pem. | No | None |
CERT_CA_PATH | (Optional) Path to your CA certificate file (ca.pem) inside the container. This is only required if you are using an intermediate CA certificate for HTTPS/SSL. When using Docker Compose and volume mounting ./data:/app/data, place your certificates in ./data/certs and set this to /app/data/certs/ca.pem. | No | None |
Important Notes:
MONGO_CONNECTION_STRING is correctly configured and points to your MongoDB Atlas cluster.CERT_KEY_PATH, CERT_CERT_PATH, and potentially CERT_CA_PATH. The provided docker-compose.yml example assumes certificates are placed in a data/certs directory on the host and mounted to /app/data/certs inside the container.8888 for the REST API and 8887 for the WebSocket endpoint. You can change these using the HTTPS_PORT and HTTP_PORT environment variables.Once the container is running, you can access the API endpoints.
Example curl command for Search:
curl --location 'http://localhost:8888/search' \
--header 'Content-Type: application/json' \
--data '{
"query": "Portable Cosmetic Travel Makeup Case",
"databaseName": "your-db-name", # Replace with your database name
"vectorField": "vectorArray", # Replace with your vector field name
"collectionName": "your-collection-name" # Replace with your collection name
}'
Content type
Image
Digest
sha256:dcc45bf39…
Size
705.1 MB
Last updated
over 1 year ago
docker pull jlmconsulting/mongo-vector-search