Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tutorial for using Asymmetric models #3258

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

brianf-aws
Copy link
Contributor

Description

This PR implements the tutorial required for local asymmetric model embeddings. In this specific tutorial it is done using a docker container, to help users take advantage of multi node clusters using ML Nodes.

Related Issues

Resolves #3255

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

 After replicating the local model embeddings. I am able to provide a high level solution of what the tutorial entails.

Signed-off-by: Brian Flores <[email protected]>
@brianf-aws brianf-aws requested a deployment to ml-commons-cicd-env-require-approval December 6, 2024 01:44 — with GitHub Actions Waiting
@brianf-aws brianf-aws requested a deployment to ml-commons-cicd-env-require-approval December 6, 2024 01:44 — with GitHub Actions Waiting
Provides more context to each step

Signed-off-by: Brian Flores <[email protected]>
Expands on the context of the previous commit and improvements in grammar and structure

Signed-off-by: Brian Flores <[email protected]>
Signed-off-by: Brian Flores <[email protected]>
@brianf-aws brianf-aws temporarily deployed to ml-commons-cicd-env-require-approval December 6, 2024 21:36 — with GitHub Actions Inactive
@brianf-aws brianf-aws had a problem deploying to ml-commons-cicd-env-require-approval December 6, 2024 21:36 — with GitHub Actions Failure
@brianf-aws brianf-aws marked this pull request as ready for review December 6, 2024 21:36
@brianf-aws
Copy link
Contributor Author

There is a flaky test in the CI, can I get a retry please? :

org.opensearch.client.ResponseException: method [DELETE], host [http://127.0.0.1:33403/], URI [/_plugins/_ml/models/ooAcnpMBnp1fQxLKssuf], status line [HTTP/1.1 400 Bad Request]
    {"error":{"root_cause":[{"type":"status_exception","reason":"Model cannot be deleted in deploying or deployed state. Try undeploy model first then delete"}],"type":"status_exception","reason":"Model cannot be deleted in deploying or deployed state. Try undeploy model first then delete"},"status":400}


## Step 1: Spin Up a Docker OpenSearch Cluster

To run OpenSearch in a local development environment, you can use Docker and a pre-configured `docker-compose` file.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a requirement? I think the step 2-6 can also be done if you run an OpenSearch cluster locally without a docker?

Copy link
Contributor Author

@brianf-aws brianf-aws Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats true, I chose a docker setup since there aren't many tutorials using it. Also its better with creating the tutorial with not having to register and deploy it again when I go back to use docker.

@brianf-aws brianf-aws temporarily deployed to ml-commons-cicd-env-require-approval December 6, 2024 23:21 — with GitHub Actions Inactive
@mingshl
Copy link
Collaborator

mingshl commented Dec 6, 2024

can you please add the configuring the knn index using ml inference ingest processors, and also search using ml inference request processors? So we can give the full tutorials about how to use this model during ingest and search


### b. Zip the Model Files

In order to upload the model to OpenSearch, you must zip the necessary model files (`model.onnx`, `sentencepiece.bpe.model`, and `tokenizer.json`). The `model.onnx` file is located in the `onnx` directory of the cloned repository.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the onnx the only format that this model provided? Can we add pytorch format tutorial here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Zane! I can see why you ask Ill clarify that this is only for onnx, I havent used pytorch models so thats I wrote it like that

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, my suggestion is we can add both onnx and pytorch cases so that user can choose between them based on their cases.

@brianf-aws brianf-aws temporarily deployed to ml-commons-cicd-env-require-approval December 17, 2024 00:02 — with GitHub Actions Inactive
@brianf-aws brianf-aws temporarily deployed to ml-commons-cicd-env-require-approval December 17, 2024 00:02 — with GitHub Actions Inactive
@brianf-aws
Copy link
Contributor Author

In order for this tutorial for all users following it, the following PR has to be merged to avoid the MLInput being null
#3281

@brianf-aws brianf-aws had a problem deploying to ml-commons-cicd-env-require-approval December 17, 2024 01:03 — with GitHub Actions Failure
Copy link
Contributor

@kolchfa-aws kolchfa-aws left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions to clarify the text. In general, use sentence case capitalization and refer to the user as "you". Thanks!

@@ -0,0 +1,539 @@
# Tutorial: Running Asymmetric Semnantic Search within OpenSearch

This tutorial demonstrates how to generate text embeddings using an asymmetric embedding model in OpenSearch which will be used
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This tutorial demonstrates how to generate text embeddings using an asymmetric embedding model in OpenSearch which will be used
This tutorial demonstrates generating text embeddings using an asymmetric embedding model in OpenSearch. The embeddings will be used

# Tutorial: Running Asymmetric Semnantic Search within OpenSearch

This tutorial demonstrates how to generate text embeddings using an asymmetric embedding model in OpenSearch which will be used
to run semantic search. This is implemented within a Docker container, the example model used in this tutorial is the multilingual
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you replace "this" with a noun? Is it the search that is implemented within a Docker container?

Suggested change
to run semantic search. This is implemented within a Docker container, the example model used in this tutorial is the multilingual
to run semantic search, implemented within a Docker container. The example model used in this tutorial is the multilingual

This tutorial demonstrates how to generate text embeddings using an asymmetric embedding model in OpenSearch which will be used
to run semantic search. This is implemented within a Docker container, the example model used in this tutorial is the multilingual
`intfloat/multilingual-e5-small` model from Hugging Face.
You will learn how to prepare the model, register it in OpenSearch, and run inference to generate embeddings.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
You will learn how to prepare the model, register it in OpenSearch, and run inference to generate embeddings.
In this tutorial, you'll learn how to prepare the model, register it in OpenSearch, and run inference to generate embeddings.


- Docker Desktop installed and running on your local machine.
- Basic familiarity with Docker and OpenSearch.
- Access to the Hugging Face model `intfloat/multilingual-e5-small` (or another model of your choice).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Access to the Hugging Face model `intfloat/multilingual-e5-small` (or another model of your choice).
- Access to the Hugging Face `intfloat/multilingual-e5-small` model (or another model of your choice).

- Access to the Hugging Face model `intfloat/multilingual-e5-small` (or another model of your choice).
---

## Step 1: Spin Up a Docker OpenSearch Cluster
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Step 1: Spin Up a Docker OpenSearch Cluster
## Step 1: Spin up a Docker OpenSearch cluster

```

### 2.4 Test ingest data
Perform bulk ingestion, this will now trigger the ingest pipeline to have embeddings for each document.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Perform bulk ingestion, this will now trigger the ingest pipeline to have embeddings for each document.
When you perform bulk ingestion, the ingest pipeline will generate embeddings for each document:


## 3. Run Semantic Search

### 3.1 Create the Search Pipeline
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### 3.1 Create the Search Pipeline
### 3.1 Create a search pipeline

## 3. Run Semantic Search

### 3.1 Create the Search Pipeline
Create the search pipeline which will convert your query into a embedding and run KNN on the index to return the best documents.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Create the search pipeline which will convert your query into a embedding and run KNN on the index to return the best documents.
Create a search pipeline that will convert your query into a embedding and run a k-NN search on the index to return the best-matching documents:

```

### 3.1 Run Semantic Search
In this scenario we are going to see the top 3 results, when asking about sporting activities in New York City.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In this scenario we are going to see the top 3 results, when asking about sporting activities in New York City.
Run a query about sporting activities in New York City:

}
```

Which yields the following
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Which yields the following
The response contains the top 3 matching documents:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Documentation] Tutorial for using Asymmetric models
5 participants