|
| 1 | +--- |
| 2 | +title: Implement image search — Meilisearch documentation |
| 3 | +description: |
| 4 | +--- |
| 5 | + |
| 6 | +# Use AI-powered search with user-provided embeddings |
| 7 | + |
| 8 | +This guide shows how to perform AI-powered searches with user-generated embeddings instead of relying on a third-party tool. |
| 9 | + |
| 10 | +## Requirements |
| 11 | + |
| 12 | +- A Meilisearch project with AI-powered search activated |
| 13 | + |
| 14 | +## Configure a custom embedder |
| 15 | + |
| 16 | +Configure the `embedder` index setting, settings its source to `userProvided`: |
| 17 | + |
| 18 | +```sh |
| 19 | +curl \ |
| 20 | + -X PATCH 'MEILISEARCH_URL/indexes/movies/settings' \ |
| 21 | + -H 'Content-Type: application/json' \ |
| 22 | + --data-binary '{ |
| 23 | + "embedders": { |
| 24 | + "image2text": { |
| 25 | + "source": "userProvided", |
| 26 | + "dimensions": 3 |
| 27 | + } |
| 28 | + } |
| 29 | + }' |
| 30 | +``` |
| 31 | + |
| 32 | +## Add documents to Meilisearch |
| 33 | + |
| 34 | +Next, use [the `/documents` endpoint](/reference/api/documents?utm_campaign=vector-search&utm_source=docs&utm_medium=vector-search-guide) to upload vectorized documents. Place vector data in your documents' `_vectors` field: |
| 35 | + |
| 36 | +```sh |
| 37 | +curl -X POST -H 'content-type: application/json' \ |
| 38 | +'localhost:7700/indexes/products/documents' \ |
| 39 | +--data-binary '[ |
| 40 | + { "id": 0, "_vectors": {"image2text": [0, 0.8, -0.2]}, "text": "frying pan" }, |
| 41 | + { "id": 1, "_vectors": {"image2text": [1, -0.2, 0]}, "text": "baking dish" } |
| 42 | +]' |
| 43 | +``` |
| 44 | + |
| 45 | +## Vector search with user-provided embeddings |
| 46 | + |
| 47 | +When using a custom embedder, you must vectorize both your documents and user queries. |
| 48 | + |
| 49 | +Once you have the query's vector, pass it to the `vector` search parameter to perform an AI-powered search: |
| 50 | + |
| 51 | +```sh |
| 52 | +curl -X POST -H 'content-type: application/json' \ |
| 53 | + 'localhost:7700/indexes/products/search' \ |
| 54 | + --data-binary '{ "vector": [0, 1, 2] }' |
| 55 | +``` |
| 56 | + |
| 57 | +`vector` must be an array of numbers indicating the search vector. You must generate these yourself when using vector search with user-provided embeddings. |
| 58 | + |
| 59 | +`vector` can be used together with [other search parameters](/reference/api/search?utm_campaign=vector-search&utm_source=docs&utm_medium=vector-search-guide), including [`filter`](/reference/api/search#filter) and [`sort`](/reference/api/search#sort): |
| 60 | + |
| 61 | +```sh |
| 62 | +curl -X POST -H 'content-type: application/json' \ |
| 63 | + 'localhost:7700/indexes/products/search' \ |
| 64 | + --data-binary '{ |
| 65 | + "vector": [0, 1, 2], |
| 66 | + "filter": "price < 10", |
| 67 | + "sort": ["price:asc"] |
| 68 | + }' |
| 69 | +``` |
0 commit comments