|
| 1 | +--- |
| 2 | +title: Image search with user-provided embeddings — Meilisearch documentation |
| 3 | +description: This article shows you the main steps for performing multimodal text-to-image searches |
| 4 | +--- |
| 5 | + |
| 6 | +# Image search with user-provided embeddings |
| 7 | + |
| 8 | +This article shows you the main steps for performing multimodal searches where you can use text to search through a database of images with no associated metadata. |
| 9 | + |
| 10 | +## Requirements |
| 11 | + |
| 12 | +- A database of images |
| 13 | +- A Meilisearch project |
| 14 | +- An embedding generation provider you can install locally |
| 15 | + |
| 16 | +## Configure your local embedding generation pipeline |
| 17 | + |
| 18 | +First, set up a system that sends your images to your chosen embedding generation provider, then integrates the returned embeddings into your dataset. |
| 19 | + |
| 20 | +The exact procedure depends heavily on your specific setup, but should include these main steps: |
| 21 | + |
| 22 | +1. Choose a provider you can run locally |
| 23 | +2. Choose a model that supports both image and text input |
| 24 | +3. Send your images to the embedding generation provider |
| 25 | +4. Add the returned embeddings to the `_vector` field for each image in your database |
| 26 | + |
| 27 | +In most cases your system should run these steps periodically or whenever you update your database. |
| 28 | + |
| 29 | +## Configure a user-provided embedder |
| 30 | + |
| 31 | +Configure the `embedder` index setting, settings its source to `userProvided`: |
| 32 | + |
| 33 | +```sh |
| 34 | +curl \ |
| 35 | + -X PATCH 'MEILISEARCH_URL/indexes/movies/settings' \ |
| 36 | + -H 'Content-Type: application/json' \ |
| 37 | + --data-binary '{ |
| 38 | + "embedders": { |
| 39 | + "EMBEDDER_NAME": { |
| 40 | + "source": "userProvided", |
| 41 | + "dimensions": MODEL_DIMENSIONS |
| 42 | + } |
| 43 | + } |
| 44 | + }' |
| 45 | +``` |
| 46 | + |
| 47 | +Replace `EMBEDDER_NAME` with the name you wish to give your embedder. Replace `MODEL_DIMENSIONS` with the number of dimensions of your chosen model. |
| 48 | + |
| 49 | +## Add documents to Meilisearch |
| 50 | + |
| 51 | +Next, use [the `/documents` endpoint](/reference/api/documents) to upload the vectorized images. |
| 52 | + |
| 53 | +In most cases, you should automate this step so Meilisearch is up to date with your primary database. |
| 54 | + |
| 55 | +## Set up pipeline for vectorizing queries |
| 56 | + |
| 57 | +Since you are using a `userProvided` embedder, you must also generate the embeddings for the search query. This process should be similar to generating embeddings for your images: |
| 58 | + |
| 59 | +1. Receive user query from your front-end |
| 60 | +2. Send query to your local embedding generation provider |
| 61 | +3. Perform search using the returned query embedding |
| 62 | + |
| 63 | +## Vector search with user-provided embeddings |
| 64 | + |
| 65 | +Once you have the query's vector, pass it to the `vector` search parameter to perform a semantic AI-powered search: |
| 66 | + |
| 67 | +```sh |
| 68 | +curl -X POST -H 'content-type: application/json' \ |
| 69 | + 'localhost:7700/indexes/products/search' \ |
| 70 | + --data-binary '{ |
| 71 | + "vector": VECTORIZED_QUERY, |
| 72 | + "hybrid": { |
| 73 | + "embedder": "EMBEDDER_NAME", |
| 74 | + } |
| 75 | + }' |
| 76 | +``` |
| 77 | + |
| 78 | +Replace `VECTORIZED_QUERY` with the embedding generated by your provider and `EMBEDDER_NAME` with your embedder. |
| 79 | + |
| 80 | +If your images have any associated metadata, you may perform a hybrid search by including the original `q`: |
| 81 | + |
| 82 | +```sh |
| 83 | +curl -X POST -H 'content-type: application/json' \ |
| 84 | + 'localhost:7700/indexes/products/search' \ |
| 85 | + --data-binary '{ |
| 86 | + "vector": VECTORIZED_QUERY, |
| 87 | + "hybrid": { |
| 88 | + "embedder": "EMBEDDER_NAME", |
| 89 | + } |
| 90 | + "q": "QUERY", |
| 91 | + }' |
| 92 | +``` |
| 93 | + |
| 94 | +## Conclusion |
| 95 | + |
| 96 | +You have seen the main steps for implementing image search with Meilisearch: |
| 97 | + |
| 98 | +1. Prepare a pipeline that converts your images into vectors |
| 99 | +2. Index the vectorized images with Meilisearch |
| 100 | +3. Prepare a pipeline that converts your users' queries into vectors |
| 101 | +4. Perform searches using the converted queries |
0 commit comments