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

add tutorial for RAG with DeepSeek R1 model on Sagemaker #3455

Merged
merged 5 commits into from
Jan 29, 2025

Conversation

ylwu-amzn
Copy link
Collaborator

Description

This tutorial introduces how to use DeepSeek model deployed on Sagemaker to build RAG in OpenSearch

Related Issues

Resolves #[Issue number to be closed when this PR is merged]

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.

Signed-off-by: Yaliang Wu <ylwu@amazon.com>
Signed-off-by: Yaliang Wu <ylwu@amazon.com>
@ylwu-amzn ylwu-amzn temporarily deployed to ml-commons-cicd-env January 29, 2025 09:33 — with GitHub Actions Inactive

### Deploy DeepSeek R1 model to Sagemaker

Follow this [blog](https://community.aws/content/2sG84dNUCFzA9z4HdfqTI0tcvKP/deploying-deepseek-r1-on-amazon-sagemaker) to deploy DeepSeek R1 model to Sagemaker.
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 interesting. Have you followed the steps and deployed successfully in SageMaker?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, the result is from test cluster, not fake one

Comment on lines 153 to 163
Add DeepSeek API endpoint to trusted URLs
```
PUT /_cluster/settings
{
"persistent": {
"plugins.ml_commons.trusted_connector_endpoints_regex": [
"^https://api\\.deepseek\\.com/.*$"
]
}
}
```
Copy link
Contributor

Choose a reason for hiding this comment

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

this will not be needed from v2.19, so should we mention that here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can add after 2.19

"status": "COMPLETED"
}
```
4. Predict
Copy link
Contributor

Choose a reason for hiding this comment

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

should we link the deepseek chat api here? so users can be aware of which api we are hitting internally

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The first sentence already mentioned the API

This tutorial introduces how to build RAG in Amazon managed OpenSearch with DeepSeek Chat Model.

```
4. Predict
```
POST /_plugins/_ml/models/Sym9sJQBts7fa6byEh1-/_predict
Copy link
Contributor

Choose a reason for hiding this comment

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

same here? is it possible to provide some reference so users are aware of how this parameters work

Copy link
Collaborator Author

@ylwu-amzn ylwu-amzn Jan 29, 2025

Choose a reason for hiding this comment

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

This is somehow not easy. Sagemaker team owns how the API works. I don't have clear view about this, no docs found

Signed-off-by: Yaliang Wu <ylwu@amazon.com>
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.

I made suggestions for the first 2 files. The 3rd one is almost the same, so please apply my suggestions to that one as well. Thanks.

## 5. RAG

### 5.1 create search pipeline
Create search pipeline with [RAG processor](https://opensearch.org/docs/latest/search-plugins/search-pipelines/rag-processor/).
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 search pipeline with [RAG processor](https://opensearch.org/docs/latest/search-plugins/search-pipelines/rag-processor/).
Create search pipeline with a [RAG processor](https://opensearch.org/docs/latest/search-plugins/search-pipelines/rag-processor/):

}
```
### 5.2 create vector database
Follow this [neural search tutorial](https://opensearch.org/docs/latest/search-plugins/neural-search-tutorial/) to create embedding model, K-NN index `my-nlp-index`, and ingest data
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
Follow this [neural search tutorial](https://opensearch.org/docs/latest/search-plugins/neural-search-tutorial/) to create embedding model, K-NN index `my-nlp-index`, and ingest data
Follow the [neural search tutorial](https://opensearch.org/docs/latest/search-plugins/neural-search-tutorial/) to create an embedding model and a k-NN index. Then ingest data into the index:

```


### 5.3 search
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
### 5.3 search
### 5.3 Search the index



### 5.3 search
Run neural search to retrieve documents from vector database, then use DeepSeek model to do RAG.
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
Run neural search to retrieve documents from vector database, then use DeepSeek model to do RAG.
Run vector search to retrieve documents from the vector database, then use the DeepSeek model for RAG:

}
}
```
Response
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
Response
The response contains the matching documents:

Co-authored-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com>
Signed-off-by: Yaliang Wu <ylwu@amazon.com>
Signed-off-by: Yaliang Wu <ylwu@amazon.com>
@ylwu-amzn ylwu-amzn merged commit 8830a43 into opensearch-project:main Jan 29, 2025
5 of 7 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jan 29, 2025
* add tutorial for RAG with DeepSeek R1 model on Sagemaker

Signed-off-by: Yaliang Wu <ylwu@amazon.com>

* add tutorials for RAG with DeepSeek Chat model

Signed-off-by: Yaliang Wu <ylwu@amazon.com>

* add tutorial for RAG with DeepSeek R1 model on Sagemaker

Signed-off-by: Yaliang Wu <ylwu@amazon.com>

* Apply suggestions from code review

Co-authored-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com>
Signed-off-by: Yaliang Wu <ylwu@amazon.com>

* apply comments to sagemkaer tutorial

Signed-off-by: Yaliang Wu <ylwu@amazon.com>

---------

Signed-off-by: Yaliang Wu <ylwu@amazon.com>
Co-authored-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com>
(cherry picked from commit 8830a43)
ylwu-amzn added a commit that referenced this pull request Jan 30, 2025
* add tutorial for RAG with DeepSeek R1 model on Sagemaker

Signed-off-by: Yaliang Wu <ylwu@amazon.com>

* add tutorials for RAG with DeepSeek Chat model

Signed-off-by: Yaliang Wu <ylwu@amazon.com>

* add tutorial for RAG with DeepSeek R1 model on Sagemaker

Signed-off-by: Yaliang Wu <ylwu@amazon.com>

* Apply suggestions from code review

Co-authored-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com>
Signed-off-by: Yaliang Wu <ylwu@amazon.com>

* apply comments to sagemkaer tutorial

Signed-off-by: Yaliang Wu <ylwu@amazon.com>

---------

Signed-off-by: Yaliang Wu <ylwu@amazon.com>
Co-authored-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com>
(cherry picked from commit 8830a43)

Co-authored-by: Yaliang Wu <ylwu@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants