You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/tutorials/semantic_search/asymmetric_embedding_model.md
+166-4Lines changed: 166 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,23 +5,185 @@ This tutorial shows how to generate embeddings using a local asymmetric embeddin
5
5
Note: Replace the placeholders that start with `your_` with your own values.
6
6
7
7
# Steps
8
+
8
9
## 1. Spin up a docker OpenSearch Cluster
9
10
10
-
### a. Use a docker compose file
11
+
With docker you can create a multi node cluster follow this docker-compose file as an example https://opensearch.org/docs/latest/install-and-configure/install-opensearch/docker/#sample-docker-compose-file-for-development
12
+
.Make sure you have docker desktop installed
11
13
12
-
## 2. Prepare the model for OpenSearch
14
+
### a. Update cluster settings
15
+
The current step uses a docker-compose file that uses two opensearch Non-ML nodes. This requires you to update cluster settings
Now that you have the docker-compose file you can use it by having docker dektop running in the background and then running
32
+
the command (within the same directory of the compose file) `docker-compose up -d` which will start opensearch in the background.
13
33
14
-
### a. Clone the model
34
+
## 2. Prepare the model for OpenSearch
35
+
In this tutorial you will use a Hugging Face intfloat/multilingual-e5-small model (https://huggingface.co/intfloat/multilingual-e5-small) an asymmetric
36
+
text embedding model capable of handling different languages.
37
+
38
+
### a. Clone the model
39
+
You can find the steps within the models homepage click on the three dots just left of the train button. Then click **clone repository**
40
+
for this specific tutorial you will have to execture teh following. Making sure you find a approriate place to host the model.
In order to send the OpenSearch the embedding model make sure to zip the model contents more specifically you will need to zip the following
45
+
items in the directory that has the items `model.onnx, sentencepiece.bpe.model, tokenizer.json`. The **model.onnx** file is found within the
46
+
onnx directory of the repository you cloned. Now that you have the contents run the following in the relevant directory `zip -r intfloat-multilingual-e5-small-onnx.zip model.onnx tokenizer.json sentencepiece.bpe.model`
47
+
This will create a zip file with the name **intfloat-multilingual-e5-small-onnx.zip**
16
48
### c. Calculate hash
49
+
Now that you have the zip file you must now calculate its hash so that you can use it on model registration. RUn the following within
50
+
the directory that has the zip `shasum -a 256 intfloat-multilingual-e5-small-onnx.zip`.
17
51
### d. service the zip file using a python server
52
+
With the zip file and its hash we should service it so that OpenSearch can find it and download it. Since this is for a local development
53
+
we can simply host this locally using python. Navigate to the directory that has the zip file and run the following `python3 -m http.server 8080 --bind 0.0.0.0
54
+
` After step 4 you can cancel this server by executing ctrl + c.
18
55
19
-
- can cancel the server now
20
56
21
57
## 3. Register a model group
58
+
We will create a model group to associate the model run the following and take note of the model group id.
59
+
```
60
+
POST /_plugins/_ml/model_groups/_register
61
+
{
62
+
"name": "Asymmetric Model Group",
63
+
"description": "A model group for local assymetric models"
64
+
}
65
+
```
66
+
22
67
## 4. Register the model
68
+
Now we can register the model which will retrieve the model from the python server since this is running within a docker
69
+
container you will have to use the url `http://host.docker.internal:8080/intfloat-multilingual-e5-small-onnx.zip`. When
70
+
running the command below make sure to take note of the model id returned by the OpenSearch call after calling the task API.
0 commit comments