Skip to content

Latest commit

 

History

History
92 lines (75 loc) · 5.66 KB

README.md

File metadata and controls

92 lines (75 loc) · 5.66 KB
Blog Hugging Face Blog Blog Slack

Ecommerce Search with Marqo

This repository contains a multimodal ecommerce search application built using Marqo's Cloud-based search engine and Marqo's state-of-the-art ecommerce embedding models.

Step 1. Set Up

First, you will need a Marqo Cloud API Key. To obtain this, visit this article. Once you have your API Key, place it inside a .env file such that:

MARQO_API_KEY = "XXXXXXXX"   # Visit https://www.marqo.ai/blog/finding-my-marqo-api-key 

To install all packages needed for this search demo:

python3 -m venv venv
source venv/bin/activate   # or venv\Scripts\activate for Windows
pip install -r requirements.txt

Now you're ready to create your Marqo Index!

Step 2: Create Your Marqo Index

For this search demo, we will be using Marqo's state-of-the-art ecommerce embedding models, marqo-ecommerce-embeddings-B and marqo-ecommerce-embeddings-L. The file marqo/create_index.py provides code for each of these models. Feel free to change this to suit whichever model you want. By default, this search demo will use marqo-ecommerce-embeddings-L. For more information on these models, see our Hugging Face.

To create your index:

python3 marqo/create_index.py
python3 marqo/add_documents.py

If you visit Marqo Cloud, you will be able to see the status of your index (and when it's ready to add documents to). The second line here adds data from data/marqo-gs_100k.csv which is a 100k subset of the Marqo-GS-10M dataset. Note, we also have a csv containing 200k items across all categories in the Google Shopping dataset. Feel free to use this dataset if you'd prefer. To check the status of your index when documents are being added, you can run:

python3 marqo/get_stats.py

This will tell you how many documents and vectors are in your index. These numbers will continue to increase as more data is added to your index.

Step 3: Run the Application

While documents are being added to your index, you can run the UI. To run the search demo:

python3 app.py

This will create a UI exactly like the video at the top of this README.md.

Step 4 (Optional): Deploy on Hugging Face

We set up this ecommerce search demo with the ability to deploy onto Hugging Face. Simply set up a Gradio Hugging Face Space and copy the contents of the app.py file. Note, you will need to define your Marqo API Key as a secret variable in your Hugging Face Space for this to work.

To see this demo live on Hugging Face, visit our Ecommerce Search Space!

Step 5: Clean Up

If you follow the steps in this guide, you will create an index with CPU large inference and a basic storage shard. This index will cost $0.38 per hour. When you are done with the index you can delete it with the following code:

import marqo
import os

mq = marqo.Client("https://api.marqo.ai", api_key=os.getenv("MARQO_API_KEY"))
mq.delete_index(index_name)

If you do not delete your index you will continue to be charged for it.

Running This Project Locally

If you'd prefer to run this project locally rather than with Marqo Cloud, you can do so using our open source version of Marqo. To run Marqo using Docker:

docker rm -f marqo
docker pull marqoai/marqo:latest
docker run --name marqo -it -p 8882:8882 marqoai/marqo:latest

Once Marqo is running, you can deploy in the same way as above but please note, mq = marqo.Client("https://api.marqo.ai", api_key=api_key) will need to be replaced with mq = marqo.Client("http://localhost:8882", api_key=None) in app.py, marqo/create_index.py, marqo/add_documents.py and marqo/get_stats.py.

Questions? Contact Us!

If you have any questions about this search demo or about Marqo's capabilities, you can: