Sign inSign up

jlmconsulting/mongo-vector-search

By jlmconsulting

Updated over 1 year ago

Vector similarity search on MongoDB documents; The application supports REST API endpoints.

Image
Machine learning & AI
0

1.3K

jlmconsulting/mongo-vector-search repository overview

Docker Hub

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.

Key Features

  • Vector Similarity Search: Query documents based on the cosine similarity of vector embeddings.
  • REST API Endpoints:
    • /ping: Health check endpoint.
    • /embedding: Generate vector embeddings for text.
    • /search: Perform vector similarity searches.
  • WebSocket Support: Stream search results in real-time via WebSocket.
  • Dockerized Deployment: Easily deployable as a Docker container.
  • Configurable via Environment Variables: Customize the application using environment variables for MongoDB connection and ports.
  • Volume Mount for Data Persistence: Persist data using Docker volumes.

Prerequisites

  • Docker installed on your host machine.
  • A MongoDB Atlas account and connection string.

Quick Start (Docker Compose)

The recommended way to run this image is using Docker Compose.

  1. 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
    
  2. 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
    
  3. Run Docker Compose:

    docker-compose up -d
    

    This will start the Mongo Vector Search application in detached mode.

Configuration (Environment Variables)

The following environment variables can be used to configure the Mongo Vector Search application:

VariableDescriptionRequiredDefault Value
MONGO_CONNECTION_STRINGRequired. Your MongoDB Atlas connection string. This is essential for the application to connect to your MongoDB database.YesNone
HTTPS_PORTPort 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.No8888
HTTP_PORTPort 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.No8887
CERT_KEY_PATHPath 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.NoNone
CERT_CERT_PATHPath 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.NoNone
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.NoNone

Important Notes:

  • MongoDB Connection String: Ensure the MONGO_CONNECTION_STRING is correctly configured and points to your MongoDB Atlas cluster.
  • HTTPS/SSL: If you intend to use HTTPS for the REST API, you will need to provide SSL certificate files and configure 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.
  • Ports: The default ports are 8888 for the REST API and 8887 for the WebSocket endpoint. You can change these using the HTTPS_PORT and HTTP_PORT environment variables.

Usage

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
}'

Tag summary

Content type

Image

Digest

sha256:dcc45bf39

Size

705.1 MB

Last updated

over 1 year ago

docker pull jlmconsulting/mongo-vector-search