|
| 1 | +--- |
| 2 | +title: Retrieve related search results |
| 3 | +description: This guide shows you how to use the similar documents endpoint to create an AI-powered movie recommendation workflow. |
| 4 | +--- |
| 5 | + |
| 6 | +This guide shows you how to use the [similar documents endpoint](/reference/api/similar) to create an AI-powered movie recommendation workflow. |
| 7 | + |
| 8 | +First, you will create an embedder and add documents to your index. You will then perform a search, and use the top result's primary key to retrieve similar movies in your database. |
| 9 | + |
| 10 | +## Prerequisites |
| 11 | + |
| 12 | +- A running Meilisearch project |
| 13 | +- A [tier >=2](https://platform.openai.com/docs/guides/rate-limits#usage-tiers) OpenAI API key |
| 14 | + |
| 15 | +## Create a new index |
| 16 | + |
| 17 | +Create an index called `movies` and add this <ButtonLink as="a" id="downloadMovie" href="/movies.json" download="movies.json">`movies.json`</ButtonLink> dataset to it. If necessary, consult the [getting started](/learn/getting_started/cloud_quick_start) for more instructions on index creation. |
| 18 | + |
| 19 | +Each document in the dataset represents a single movie and has the following structure: |
| 20 | + |
| 21 | +- `id`: a unique identifier for each document in the database |
| 22 | +- `title`: the title of the movie |
| 23 | +- `overview`: a brief summary of the movie's plot |
| 24 | +- `genres`: an array of genres associated with the movie |
| 25 | +- `poster`: a URL to the movie's poster image |
| 26 | +- `release_date`: the release date of the movie, represented as a Unix timestamp |
| 27 | + |
| 28 | +## Configure an embedder |
| 29 | + |
| 30 | +Next, use the Cloud UI to configure an OpenAI embedder: |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | +You may also use the `/settings/embedders` API subroute to configure your embedder: |
| 35 | + |
| 36 | +<CodeSamples id="related_results_embedder_1" /> |
| 37 | + |
| 38 | +Replace `MEILISEARCH_URL`, `MEILISEARCH_API_KEY`, and `OPENAI_API_KEY` with the corresponding values in your application. |
| 39 | + |
| 40 | +Meilisearch will start generating the embeddings for all movies in your dataset. Use the returned `taskUid` to [track the progress of this task](/learn/async/asynchronous_operations). Once it is finished, you are ready to start searching. |
| 41 | + |
| 42 | +## Perform a hybrid search |
| 43 | + |
| 44 | +With your documents added and all embeddings generated, you can perform a search: |
| 45 | + |
| 46 | +<CodeSamples id="related_results_search_1" /> |
| 47 | + |
| 48 | +This request returns a list of movies. Pick the top result and take note of its primary key in the `id` field. In this case, it's the movie "Batman" with `id` 192. |
| 49 | + |
| 50 | +## Return similar documents |
| 51 | + |
| 52 | +Pass "Batman"'s `id` to your index's [`/similar` route](/reference/api/similar), specifying `movies-text` as your embedder: |
| 53 | + |
| 54 | +<CodeSamples id="related_results_similar_1" /> |
| 55 | + |
| 56 | +Meilisearch will return a list of the 20 documents most similar to the movie you chose. You may then choose to display some of these similar results to your users, pointing them to other movies that may also interest them. |
| 57 | + |
| 58 | +## Conclusion |
| 59 | + |
| 60 | +Congratulations! You have successfully built an AI-powered movie search and recommendation system using Meilisearch by: |
| 61 | + |
| 62 | +- Setting up a Meilisearch project and configured it for AI-powered search |
| 63 | +- Implementing hybrid search combining keyword and semantic search capabilities |
| 64 | +- Integrating Meilisearch's similarity search for movie recommendations |
| 65 | + |
| 66 | +In a real-life application, you would now start integrating this workflow into a front end, like the one in this [official Meilisearch blog post](https://www.meilisearch.com/blog/add-ai-powered-search-to-react). |
0 commit comments