Skip to content

Conversation

@dhrubo-os
Copy link
Collaborator

@dhrubo-os dhrubo-os commented Aug 11, 2025

Description

[code refactoring + add unit test [memory module]

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.

@dhrubo-os dhrubo-os changed the title code refactoring + add unit test [memory module' code refactoring + add unit test [memory module] Aug 11, 2025
Signed-off-by: Dhrubo Saha <dhrubo@amazon.com>
@dhrubo-os dhrubo-os changed the title code refactoring + add unit test [memory module] code refactoring + add unit test [memory module][Draft] Aug 11, 2025
@dhrubo-os dhrubo-os had a problem deploying to ml-commons-cicd-env August 11, 2025 05:41 — with GitHub Actions Failure
@dhrubo-os dhrubo-os had a problem deploying to ml-commons-cicd-env August 11, 2025 05:41 — with GitHub Actions Failure
Signed-off-by: Dhrubo Saha <dhrubo@amazon.com>
@dhrubo-os
Copy link
Collaborator Author

ERROR][o.o.m.e.a.r.MLSdkAsyncHttpResponseHandler] [integTest-0] Received error from remote service with status code 403, response headers: {Connection=[keep-alive], Content-Length=[1829], Content-Type=[application/json], Date=[Mon, 11 Aug 2025 15:36:36 GMT], x-amzn-ErrorType=[InvalidSignatureException:http://internal.amazon.com/coral/com.amazon.coral.service/], x-amzn-RequestId=[c8bd00ff-b0b6-430a-8ccb-6f0e9d977ad1]}
» ERROR][o.o.m.e.a.r.MLSdkAsyncHttpResponseHandler] [integTest-0] Remote service returned error: Error from remote service: {"message":"The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.\n\nThe Canonical String for this request should have been\n'POST\n/model/anthropic.claude-3-5-sonnet-20240620-v1%3A0/converse\n\ncontent-length:137686\ncontent-type:application/json\nhost:bedrock-runtime.us-west-2.amazonaws.com\nx-amz-date:20250811T153636Z\nx-amz-security-token:***\n\ncontent-length;content-type;host;x-amz-date;x-amz-security-token\nf3f50a7c8135014bda4728d8ed4e8dc142c212589a674633166e33e1f062f355'\n\nThe String-to-Sign should have been\n'AWS4-HMAC-SHA256\n20250811T153636Z\n20250811/us-west-2/bedrock/aws4_request\n80504b1f309ffea64b6496b558cac04cd81f6063d6cae96af7a4b692179e33f3'\n"} with status: FORBIDDEN
» ERROR][o.o.m.e.a.r.MLSdkAsyncHttpResponseHandler] [integTest-0] Received error from remote service with status code 401, response headers: {alt-svc=[h3=":443"; ma=86400], cf-cache-status=[DYNAMIC], CF-RAY=[96d8d13b4e737ab2-SJC], Connection=[keep-alive], Content-Length=[496], Content-Type=[application/json; charset=utf-8], Date=[Mon, 11 Aug 2025 15:37:58 GMT], Server=[cloudflare], Set-Cookie=[__cf_bm=pM3h9ZZBZMi0H8XmcaUtUN5a6AKRMehqFZKTYi4GqGk-1754926678-1.0.1.1-Iaft3dMjoltzfn4Z4oaTgDh1PjAtH4k7ispbWWxXrdaAg2mq3J4GWuioMJP9cYSzWtM0YApULNb5Cba3ojfVxqVKy2d5vQZB903uIfNSVoo; path=/; expires=Mon, 11-Aug-25 16:07:58 GMT; domain=.api.openai.com; HttpOnly; Secure, _cfuvid=JTcSX.Kj71zUlVrrFKEtNlB1e1qnqb0I3bIEXh53t7g-1754926678307-0.0.1.1-604800000; path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None], Strict-Transport-Security=[max-age=31536000; includeSubDomains; preload], vary=[Origin], X-Content-Type-Options=[nosniff], x-envoy-upstream-service-time=[0], x-request-id=[req_26db08bd2cd049d5946840005520fa13]}
» ERROR][o.o.m.e.a.r.MLSdkAsyncHttpResponseHandler] [integTest-0] Received error from remote service with status code 401, response headers: {alt-svc=[h3=":443"; ma=86400], cf-cache-status=[DYNAMIC], CF-RAY=[96d8d1bcd95b7ab2-SJC], Connection=[keep-alive], Content-Length=[496], Content-Type=[application/json; charset=utf-8], Date=[Mon, 11 Aug 2025 15:38:19 GMT], Server=[cloudflare], Set-

This is not introduced by this PR.

@dhrubo-os dhrubo-os temporarily deployed to ml-commons-cicd-env August 11, 2025 16:45 — with GitHub Actions Inactive
@dhrubo-os dhrubo-os temporarily deployed to ml-commons-cicd-env August 11, 2025 16:45 — with GitHub Actions Inactive
@dhrubo-os dhrubo-os had a problem deploying to ml-commons-cicd-env August 11, 2025 16:45 — with GitHub Actions Failure
@dhrubo-os dhrubo-os changed the title code refactoring + add unit test [memory module][Draft] code refactoring + add unit test [memory module] Aug 11, 2025
@dhrubo-os dhrubo-os had a problem deploying to ml-commons-cicd-env August 11, 2025 19:02 — with GitHub Actions Failure
Copy link
Contributor

@rithin-pullela-aws rithin-pullela-aws left a comment

Choose a reason for hiding this comment

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

Reviewed the business logic files, mostly LGTM apart from very minor nitpicks.
Will review the test files in some time

Comment on lines +22 to +24
public String getId() {
return id;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can we add @ Getter instead?
same applies for other fields as well

BulkItemResponse[] items = bulkResponse.getItems();
int itemIndex = 0;

for (int i = 0; i < results.size(); i++) {
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 have itemIndex condition in the for loop since we are anyways skipping the operations id itemIndex is out of bounds

for (int i = 0; i < results.size() && itemIndex < items.length ; i++) {

Comment on lines +53 to +57
public void extractFactsFromConversation(
List<MessageInput> messages,
MemoryStorageConfig storageConfig,
ActionListener<List<String>> listener
) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to understand the underlying design, do we extract facts from a bunch of messages and not a single message from the user?

Comment on lines +290 to +291
if (responseContent.startsWith("```json") && responseContent.endsWith("```")) {
responseContent = responseContent.substring(7, responseContent.length() - 3).trim();
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: While this is a good way to handle the LLM output parsing, these instructions should be ideally provided in the prompt of the LLM to never output the code blocks. If the current prompt sometimes leads to such outputs, it is an indication that there is a scope of improvement in the prompt

Some resources for prompt optimization from anthropic:

@dhrubo-os dhrubo-os had a problem deploying to ml-commons-cicd-env August 11, 2025 21:57 — with GitHub Actions Failure
@dhrubo-os dhrubo-os temporarily deployed to ml-commons-cicd-env August 12, 2025 01:19 — with GitHub Actions Inactive
@codecov
Copy link

codecov bot commented Aug 12, 2025

Codecov Report

❌ Patch coverage is 87.55274% with 59 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.89%. Comparing base (8ef3528) to head (81b2399).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...emorycontainer/memory/MemoryProcessingService.java 88.46% 10 Missing and 11 partials ⚠️
...emorycontainer/memory/MemoryOperationsService.java 89.56% 9 Missing and 10 partials ⚠️
...rycontainer/memory/TransportAddMemoriesAction.java 73.17% 10 Missing and 1 partial ⚠️
...on/memorycontainer/memory/MemorySearchService.java 90.47% 3 Missing and 1 partial ⚠️
...h/ml/action/memorycontainer/memory/MemoryInfo.java 83.33% 2 Missing ⚠️
...rg/opensearch/ml/helper/MemoryEmbeddingHelper.java 71.42% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #4086      +/-   ##
============================================
+ Coverage     79.06%   80.89%   +1.82%     
- Complexity     8621     8727     +106     
============================================
  Files           755      760       +5     
  Lines         38352    38090     -262     
  Branches       4287     4245      -42     
============================================
+ Hits          30324    30813     +489     
+ Misses         6220     5442     -778     
- Partials       1808     1835      +27     
Flag Coverage Δ
ml-commons 80.89% <87.55%> (+1.82%) ⬆️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dhrubo-os
Copy link
Collaborator Author

@rithin-pullela-aws I'll address all your comment in the next followup. Merging to unblock @b4sjoo

@dhrubo-os dhrubo-os merged commit 85a3135 into opensearch-project:main Aug 12, 2025
33 of 44 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Aug 12, 2025
* code refactoring

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

* add more unit tests and bug fix

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

---------

Signed-off-by: Dhrubo Saha <dhrubo@amazon.com>
(cherry picked from commit 85a3135)
dhrubo-os added a commit that referenced this pull request Aug 12, 2025
* code refactoring



* add more unit tests and bug fix



---------


(cherry picked from commit 85a3135)

Signed-off-by: Dhrubo Saha <dhrubo@amazon.com>
Co-authored-by: Dhrubo Saha <dhrubo@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.

4 participants