Skip to content

Commit 310647c

Browse files
Add Hugging Face Inference Endpoints as a rest embedder guide (#3053)
--------- Co-authored-by: gui machiavelli <[email protected]>
1 parent fd3aff8 commit 310647c

File tree

3 files changed

+100
-9
lines changed

3 files changed

+100
-9
lines changed

config/sidebar-guides.json

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,20 @@
5555
"title": "Artificial Intelligence",
5656
"slug": "ai",
5757
"routes": [
58+
{
59+
"source": "guides/embedders/openai.mdx",
60+
"label": "Semantic search with OpenAI embeddings",
61+
"slug": "openai"
62+
},
5863
{
5964
"source": "guides/langchain.mdx",
6065
"label": "Implementing semantic search with LangChain",
6166
"slug": "langchain"
6267
},
6368
{
64-
"source": "guides/computing_hugging_face_embeddings_gpu.mdx",
65-
"label": "Computing Hugging Face embeddings with the GPU",
66-
"slug": "computing_hugging_face_embeddings_gpu"
69+
"source": "guides/embedders/huggingface.mdx",
70+
"label": "Implementing semantic search with Hugging Face Inference Endpoints",
71+
"slug": "huggingface"
6772
},
6873
{
6974
"source": "guides/embedders/cloudflare.mdx",
@@ -80,15 +85,15 @@
8085
"label": "Semantic search with Mistral embeddings",
8186
"slug": "mistral"
8287
},
83-
{
84-
"source": "guides/embedders/openai.mdx",
85-
"label": "Semantic search with OpenAI embeddings",
86-
"slug": "openai"
87-
},
8888
{
8989
"source": "guides/embedders/voyage.mdx",
9090
"label": "Semantic search with Voyage embeddings",
9191
"slug": "voyage"
92+
},
93+
{
94+
"source": "guides/computing_hugging_face_embeddings_gpu.mdx",
95+
"label": "Computing Hugging Face embeddings with the GPU",
96+
"slug": "computing_hugging_face_embeddings_gpu"
9297
}
9398
]
9499
},

guides/embedders/cloudflare.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ In this request:
8888
- `q`: Represents the user's search query.
8989
- `hybrid`: Specifies the configuration for the hybrid search.
9090
- `semanticRatio`: Allows you to control the balance between semantic search and traditional search. A value of 1 indicates pure semantic search, while a value of 0 represents full-text search. You can adjust this parameter to achieve a hybrid search experience.
91-
- `embedder`: The name of the embedder used for generating embeddings. Make sure to use the same name as specified in the embedder configuration, which in this case is "cf-bge-small-en-v1.5".
91+
- `embedder`: The name of the embedder used for generating embeddings. Make sure to use the same name as specified in the embedder configuration, which in this case is "cloudflare".
9292

9393
You can use the Meilisearch API or client libraries to perform searches and retrieve the relevant documents based on semantic similarity.
9494

guides/embedders/huggingface.mdx

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
title: Semantic Search with Hugging Face Inference Endpoints - Meilisearch documentation
3+
description: This guide will walk you through the process of setting up Meilisearch with Hugging Face Inference Endpoints.
4+
---
5+
6+
# Semantic search with Hugging Face Inference Endpoints
7+
8+
## Introduction
9+
10+
This guide will walk you through the process of setting up a Meilisearch REST embedder with [Hugging Face Inference Endpoints](https://ui.endpoints.huggingface.co/) to enable semantic search capabilities.
11+
12+
<Capsule intent="note" title="`rest` or `huggingface`?">
13+
You can use Hugging Face and Meilisearch in two ways: running the model locally by setting the embedder source to `huggingface`, or remotely in Hugging Face's servers by setting the embeder source to `rest`.
14+
</Capsule>
15+
16+
## Requirements
17+
18+
To follow this guide, you'll need:
19+
20+
- A [Meilisearch Cloud](https://www.meilisearch.com/cloud) project running version 1.10 or above with the Vector store activated
21+
- A [Hugging Face account](https://huggingface.co/) with a deployed inference endpoint
22+
- The endpoint URL and API key of the deployed model on your Hugging Face account
23+
24+
## Configure the embedder
25+
26+
Set up an embedder using the update settings endpoint:
27+
28+
```json
29+
{
30+
"hf-inference": {
31+
"source": "rest",
32+
"url": "ENDPOINT_URL",
33+
"apiKey": "API_KEY",
34+
"dimensions": 384,
35+
"documentTemplate": "CUSTOM_LIQUID_TEMPLATE",
36+
"request": {
37+
"inputs": ["{{text}}", "{{..}}"],
38+
"model": "baai/bge-small-en-v1.5"
39+
},
40+
"response": ["{{embedding}}", "{{..}}"]
41+
}
42+
}
43+
```
44+
45+
In this configuration:
46+
47+
- `source`: declares Meilisearch should connect to this embedder via its REST API
48+
- `url`: replace `ENDPOINT_URL` with the address of your Hugging Face model endpoint
49+
- `apiKey`: replace `API_KEY` with your Hugging Face API key
50+
- `dimensions`: specifies the dimensions of the embeddings, which are 384 for `baai/bge-small-en-v1.5`
51+
- `documentTemplate`: an optional but recommended [template](/learn/ai_powered_search/getting_started_with_ai_search) for the data you will send the embedder
52+
- `request`: defines the structure and parameters of the request Meilisearch will send to the embedder
53+
- `response`: defines the structure of the embedder's response
54+
55+
Once you've configured the embedder, Meilisearch will automatically generate embeddings for your documents. Monitor the task using the Cloud UI or the [get task endpoint](/reference/api/tasks).
56+
57+
<Capsule intent="note">
58+
This example uses [BAAI/bge-small-en-v1.5](https://huggingface.co/BAAI/bge-small-en-v1.5) as its model, but Hugging Face offers [other options that may fit your dataset better](https://ui.endpoints.huggingface.co/catalog?task=sentence-embeddings).
59+
</Capsule>
60+
61+
## Perform a semantic search
62+
63+
With the embedder set up, you can now perform semantic searches. Make a search request with the `hybrid` search parameter, setting `semanticRatio` to `1`:
64+
65+
```json
66+
{
67+
"q": "QUERY_TERMS",
68+
"hybrid": {
69+
"semanticRatio": 1,
70+
"embedder": "hf-inference"
71+
}
72+
}
73+
```
74+
75+
In this request:
76+
77+
- `q`: the search query
78+
- `hybrid`: enables AI-powered search functionality
79+
- `semanticRatio`: controls the balance between semantic search and full-text search. Setting it to `1` means you will only receive semantic search results
80+
- `embedder`: the name of the embedder used for generating embeddings
81+
82+
## Conclusion
83+
84+
You have set up with an embedder using Hugging Face Inference Endpoints. This allows you to use pure semantic search capabilities in your application.
85+
86+
Consult the [embedder setting documentation](/reference/api/settings#embedders-experimental) for more information on other embedder configuration options.

0 commit comments

Comments
 (0)