marqo-ai / local-image-search-demo

This is a demo of E-Commerce search using Marqo that can be run locally on a laptop or desktop with or without a GPU.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Marqo E-Commerce Local Search Demo

This is an image search demo that uses Marqo to do multimodel search with weighted queries. The entire program is designed to run locally using the Marqo docker image on your own machine. All data is provided by Marqo via S3 and will be automatically indexed when you run the app. The model used for the application is open_clip/ViT-B-32/laion2b_s34b_b79k, but Marqo can also support hundreds of other open source embedding models, see: https://docs.marqo.ai/2.0.0/Guides/Models-Reference/dense_retrieval/

NOTE: By default this application starts with 10,000 images which means that there may not be relevant results for all searches. The images you get are randomised. (Edit .env.local to add more images).

Index

Running Marqo

The steps and command for different devices are provided below.

Running on CPU

docker run --name marqo -p 8882:8882 marqoai/marqo:2.0.0

Running on GPU

Currently, only CUDA capable (Nvidia) GPU's are supported. If you have a GPU on the host machine and want to use it with Marqo, there are two things to do:

  1. Install NVIDIA Container Toolkit.
  2. Add a --gpus all flag to the Docker run command. Note that this flag should appear after the run command but before the end.

Install NVIDIA Container Toolkit which is required for the GPU to work with Docker. For more detail refer to the original instructions.

Once NVIDIA Container Toolkit is installed, you can run Marqo with --gpus all:

docker run --name --gpus all marqo -p 8882:8882 marqoai/marqo:2.0.0

Dependencies

Install the dependencies in a virtual environment.

Make virutal environment

python -m venv venv

Activate the virtual environment

Windows:

.\venv\Scripts\activate

Linux/Mac:

source venv/bin/activate

Install requirements

pip install -r requirements.txt

Running the Application

Before you run the application you may want to configure the environment variable to suite your system. There are two that are used:

N_DOCUMENTS=<number of documents to use in the index, removing the will use all documents>
MARQO_INDEX_NAME=<the name of the index to create and use, the default should be fine>

If you are on CPU then a high N_DOCUMENTS may take hours to index.

Index the data:

python3 index_data.py

Run the server (Note: search may be slow if indexing is still running - especially on a CPU):

python3 app.py

(This will first check if the index exists on your machine. If it doesn't then it will be automatically created using N_DOCUMENTS documents.)

About

This is a demo of E-Commerce search using Marqo that can be run locally on a laptop or desktop with or without a GPU.


Languages

Language:Python 50.3%Language:CSS 29.1%Language:HTML 20.6%