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

Added Conversation API in MLClient #2211

Closed
wants to merge 10 commits into from

Conversation

owaiskazi19
Copy link
Member

Description

Added Conversation API in MLClient

Issues Resolved

[List any issues this PR will resolve]

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

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.

rbhavna and others added 8 commits November 17, 2023 01:19
* fix parameter name in preprocess function; fix remote model function … (opensearch-project#1362)

* fix parameter name in preprocess function; fix remote model function name

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

* fix failed unit test

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

---------

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

* throw exception when model group not found during update request (opensearch-project#1447)

Signed-off-by: Bhavana Ramaram <rbhavna@amazon.com>

* add status code to model tensor (opensearch-project#1443) (opensearch-project#1453)

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

* register new versions to a model group based on the name provided (opensearch-project#1452)

Signed-off-by: Bhavana Ramaram <rbhavna@amazon.com>

* fixing metrics correlation algorithm (opensearch-project#1448)

* fixing metrics correlation algorithm

Signed-off-by: Dhrubo Saha <dhrubo@amazon.com>

* if model version fails to register, update model group accordingly (opensearch-project#1463)

* if model version fails to register, update model group accordingly

Signed-off-by: Bhavana Ramaram <rbhavna@amazon.com>

* Update Model API (opensearch-project#1350)

* Update Model API POC

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* Using GetRequest to get model

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* Finalize model update API

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* Fix compile

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* Fix compileTest

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* Add Unit Test Cases for Update Model API

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* Tune back test coverage thereshold

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* Add more unit tests on Update model API

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* Add unit test for TransportUpdateModelAction class

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* Fix a test error

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* Change exception thrown to failure response

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* Move the function judgement to the outter block

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* Check if model is undeployed before update model

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* Add more unit test for update model API

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* Fix unit test due to blocking java 11 CI workflow

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* Enabling auto bumping model version during registering to a new model group and address reviewers' other concern

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* Autobump new model groups' latest version when register to a new model

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* Change the REST API method from POST to PUT

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* Change the update REST API endpoint

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

---------

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* Add a setting to control the update connector API (opensearch-project#1465)

* Add a setting to control the update connector API

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* Enabling the update connnector setting in unit test

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* Enabling the update connnector setting in corresponding unit test

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

---------

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* fix update connector API (opensearch-project#1484)

* fix update connector API

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

* Performance enhacement for predict action by caching model info (opensearch-project#1472) (opensearch-project#1508)

* Performance enhacement for predict action by caching model info

Signed-off-by: zane-neo <zaniu@amazon.com>

* Add context.restore() to avoid missing info

Signed-off-by: zane-neo <zaniu@amazon.com>

---------

Signed-off-by: zane-neo <zaniu@amazon.com>
(cherry picked from commit a985f6e)

Co-authored-by: zane-neo <zaniu@amazon.com>

* fix failed ut from PR 1472 (opensearch-project#1479) (opensearch-project#1510)

* fix failed ut from PR 1472

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

* exclude class for low coverage

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

---------

Signed-off-by: Yaliang Wu <ylwu@amazon.com>
(cherry picked from commit da5d829)

Co-authored-by: Yaliang Wu <ylwu@amazon.com>

* [Backport to 2.11] throw exception if remote model doesn't return 2xx status code; fix p… (opensearch-project#1477) (opensearch-project#1509)

* throw exception if remote model doesn't return 2xx status code; fix p… (opensearch-project#1473)

* throw exception if remote model doesn't return 2xx status code; fix predict runner

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

* fix kmeans model deploy bug

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

* support multiple docs for remote embedding model

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

* fix ut

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

---------

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

* fix wrong class

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

---------

Signed-off-by: Yaliang Wu <ylwu@amazon.com>
(cherry picked from commit 201c8a8)

Co-authored-by: Yaliang Wu <ylwu@amazon.com>

* fix no worker node exception for remote embedding model (opensearch-project#1482) (opensearch-project#1511)

* fix no worker node exception for remote embedding model

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

* only add model info to cache if model cache exist

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

---------

Signed-off-by: Yaliang Wu <ylwu@amazon.com>
(cherry picked from commit 6f83b9f)

Co-authored-by: Yaliang Wu <ylwu@amazon.com>

* fix for delete model group API throwing incorrect error when model index not created (opensearch-project#1485) (opensearch-project#1486) (opensearch-project#1512)

* fix for delete model group API throwing incorrect error when model index not created

Signed-off-by: Bhavana Ramaram <rbhavna@amazon.com>
(cherry picked from commit 60ef0fd)

Co-authored-by: Bhavana Ramaram <rbhavna@amazon.com>
(cherry picked from commit 5544681)

Co-authored-by: opensearch-trigger-bot[bot] <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com>

* fix no worker node error on multi-node cluster (opensearch-project#1487) (opensearch-project#1513)

Signed-off-by: Yaliang Wu <ylwu@amazon.com>
(cherry picked from commit cea1cd6)

Co-authored-by: Yaliang Wu <ylwu@amazon.com>

* add prefix to show the error is from remote service (opensearch-project#1499) (opensearch-project#1515)

Signed-off-by: Yaliang Wu <ylwu@amazon.com>
(cherry picked from commit 3897ad1)

Co-authored-by: Yaliang Wu <ylwu@amazon.com>

* fix multiple docs support (opensearch-project#1516)

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

* adding another fix issue to the release note (opensearch-project#1498) (opensearch-project#1514)

Signed-off-by: Dhrubo Saha <dhrubo@amazon.com>
(cherry picked from commit 440155c)

Co-authored-by: Dhrubo Saha <dhrubo@amazon.com>

* add bedrockURL to trusted connector regex list (opensearch-project#1461)

Signed-off-by: Bhavana Ramaram <rbhavna@amazon.com>

* return parsing exception 400 for parsing errors

Signed-off-by: Xun Zhang <xunzh@amazon.com>

* add more ut in restupdateconnector

Signed-off-by: Xun Zhang <xunzh@amazon.com>

* fix format violations

Signed-off-by: Bhavana Ramaram <rbhavna@amazon.com>

* Fix model/connector update API to address security concern (opensearch-project#1595)

* Fix model/connector update API to address appsec concern

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* Fix compile and build failure

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* Improve unit test coverage

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* Fix spotless

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* Merge update connector feature flag to remote inference feature flag

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* Fix compile

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* Fix exception status

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* Keep fixing exception status

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* Spotless fix

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* Add UT on parsing exception

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

---------

Signed-off-by: Sicheng Song <sicheng.song@outlook.com>

* change XContentFactory to MediaTypeRegistry builder in MLRegisterModelInputTest class

Signed-off-by: Bhavana Ramaram <rbhavna@amazon.com>

---------

Signed-off-by: Yaliang Wu <ylwu@amazon.com>
Signed-off-by: Bhavana Ramaram <rbhavna@amazon.com>
Signed-off-by: Dhrubo Saha <dhrubo@amazon.com>
Signed-off-by: Sicheng Song <sicheng.song@outlook.com>
Signed-off-by: Xun Zhang <xunzh@amazon.com>
Co-authored-by: Yaliang Wu <ylwu@amazon.com>
Co-authored-by: Dhrubo Saha <dhrubo@amazon.com>
Co-authored-by: Sicheng Song <sicheng.song@outlook.com>
Co-authored-by: opensearch-trigger-bot[bot] <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com>
Co-authored-by: zane-neo <zaniu@amazon.com>
Co-authored-by: Xun Zhang <xunzh@amazon.com>
@owaiskazi19
Copy link
Member Author

@dhrubo-os @jngz-es @rbhavna can you take a look? Thanks

Signed-off-by: Owais Kazi <owaiskazi19@gmail.com>
@owaiskazi19 owaiskazi19 temporarily deployed to ml-commons-cicd-env March 18, 2024 19:42 — with GitHub Actions Inactive
@owaiskazi19 owaiskazi19 temporarily deployed to ml-commons-cicd-env March 18, 2024 19:42 — with GitHub Actions Inactive
@owaiskazi19 owaiskazi19 temporarily deployed to ml-commons-cicd-env March 18, 2024 19:42 — with GitHub Actions Inactive
@@ -67,4 +73,20 @@ public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params par
return builder;
}

public static CreateConversationResponse fromActionResponse(ActionResponse actionResponse) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's add a test.

@@ -16,6 +16,7 @@ plugins {
dependencies {
implementation project(path: ":${rootProject.name}-spi", configuration: 'shadow')
implementation project(path: ":${rootProject.name}-common", configuration: 'shadow')
implementation project(path: ":${rootProject.name}-memory")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just curious to know if we should mark this as shadow?

Copy link
Member Author

Choose a reason for hiding this comment

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

Memory package doesn't have a publishing task that's why @jngz-es suggested to keep it like this.

Signed-off-by: Owais Kazi <owaiskazi19@gmail.com>
Copy link

codecov bot commented Mar 18, 2024

Codecov Report

Attention: Patch coverage is 55.55556% with 8 lines in your changes are missing coverage. Please review.

Project coverage is 81.89%. Comparing base (c233356) to head (1e74bab).

❗ Current head 1e74bab differs from pull request most recent head 03d19b1. Consider uploading reports for the commit 03d19b1 to get more accurate results

Files Patch % Lines
...ction/conversation/CreateConversationResponse.java 0.00% 8 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2211      +/-   ##
============================================
- Coverage     81.91%   81.89%   -0.02%     
- Complexity     5719     5724       +5     
============================================
  Files           547      547              
  Lines         23064    23082      +18     
  Branches       2378     2378              
============================================
+ Hits          18892    18903      +11     
- Misses         3227     3235       +8     
+ Partials        945      944       -1     
Flag Coverage Δ
ml-commons 81.89% <55.55%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

* @param name name of the conversation, refer: https://opensearch.org/docs/latest/ml-commons-plugin/api/memory-apis/create-memory/
* @return the result future
*/
default ActionFuture<CreateConversationResponse> createConversation(String name) {
Copy link
Collaborator

@ylwu-amzn ylwu-amzn Mar 18, 2024

Choose a reason for hiding this comment

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

I don't think we should add this API. We should create a new conversation automatically when conversation id not set.

Copy link
Member

@amitgalitz amitgalitz Mar 18, 2024

Choose a reason for hiding this comment

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

Oh okay @ylwu-amzn so if we want users to be able to do one click creation for conversation use case with some defaults for demo/poc purpose, we can just skip this step and not give rag processor the conversation ID?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you do want the ability to give conversations human-readable names.

cc: @HenryL27

Copy link
Member

Choose a reason for hiding this comment

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

The main reason I am currently adding this is so we can have default use cases ready to go for conversational search opensearch-project/flow-framework#588

We want to be able to do something like setting up the whole e2e with just:

http://localhost:9200/_plugins/_flow_framework/workflow?use_case=conversationl_search&provision=true
{
    "create_connector.credential.key" : "123"
}

all fields can be overriden but at least for easy poc/dev I thought it would be useful,

If we have some nice human-readable name in the processor for memory will it even be seen. I was thinking this part creates the memory id to give here, not conversation ID:

GET /my_rag_test_data/_search
{
 "query": {
   "match": {
     "text": "What's the population of NYC metro area in 2023"
   }
 },
 "ext": {
   "generative_qa_parameters": {
     "llm_model": "gpt-3.5-turbo",
     "llm_question": "What's the population of NYC metro area in 2023",
     "memory_id": "znCqcI0BfUsSoeNTntd7",
     "context_size": 5,
     "message_size": 5,
     "timeout": 15
   }
 }
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was thinking this part creates the memory id to give here, not conversation ID

memory=conversation. message=interaction. Sorry about the confusion here... we probably need to rename the internal classes to match the API names.

Copy link
Collaborator

@Zhangxunmt Zhangxunmt Mar 19, 2024

Choose a reason for hiding this comment

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

Yes, we need to follow the new names. Use Memory to replace Conversation, and Message to replace Interaction. Can you update based on the API name in the doc https://opensearch.org/docs/latest/ml-commons-plugin/api/memory-apis/create-memory?

Copy link
Collaborator

@HenryL27 HenryL27 left a comment

Choose a reason for hiding this comment

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

Do you wanna add any more APIs than just "CreateConversation" / "CreateMemory"? Also @Zhangxunmt which name scheme we going with?

@Zhangxunmt
Copy link
Collaborator

Yes, we need to follow the new names. Use Memory to replace Conversation, and Message to replace Interaction.

@austintlee
Copy link
Collaborator

@owaiskazi19 Do you want to try to get this into 2.18?

@dhrubo-os
Copy link
Collaborator

@owaiskazi19 any update on this PR?

@owaiskazi19
Copy link
Member Author

Sorry for the delay here. Raised #3475 and closing this

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.

8 participants