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

Implement search alerts tool #1629

Conversation

ohltyler
Copy link
Member

@ohltyler ohltyler commented Nov 14, 2023

Description

Adds a search alerts tool. Utilizes getAlerts() exposed by the alerting interface in common utils.

Exposes all of the parameters offered by the interface, besides missing since that doesn't seem relevant (defaults to null). All parameters have defaults which match that of the get alerts API for now.

The amount of parameters and/or the default values may be changed later on depending on agent performance and accuracy. For example, too much parameter tuning may lead to messy or invalid results.

Additionally, further integration testing will need to be done to validate different alerting-related questions input to the agent that will have this tool associated to it.

Issues Resolved

Closes #1521

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.

@ohltyler
Copy link
Member Author

Relevant added tests pass:

./gradlew opensearch-ml-algorithms:test
=======================================
OpenSearch Build Hamster says Hello!
  Gradle Version        : 8.1.1
  OS Info               : Linux 5.4.258-178.360.amzn2int.x86_64 (amd64)
  JDK Version           : 14 (OpenJDK)
  JAVA_HOME             : /opt/jdk-14
  Random Testing Seed   : 8F9A68BC7C4A7742
  In FIPS 140 mode      : false
=======================================

> Task :opensearch-ml-common:compileJava
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /local/home/ohltyler/workspace/fractal/ml-commons/common/src/main/java/org/opensearch/ml/common/conversation/Interaction.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

> Task :opensearch-ml-algorithms:compileJava
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

> Task :opensearch-ml-algorithms:compileTestJava
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/8.1.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 39s

final int tableSize = parameters.containsKey("size") ? Integer.parseInt(parameters.get("size")) : 20;
final String searchString = parameters.getOrDefault("searchString", null);

// not exposing "missing" or "startIndex" from the table, using defaults of null/0, respectively
Copy link
Member

Choose a reason for hiding this comment

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

We would need to expose the start index to paginate the responses.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is pagination something feasible from the agent? It would need to process and combine multiple alert results after making multiple calls to the tools with different start index values. Is that possible?

Copy link
Member

Choose a reason for hiding this comment

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

Well one call will get a list of alerts. I think this is a good question where we need to understand the limit of data we should be fetching, so we don't overwhelm the LLM. @jngz-es, do you have any recommendations here?

Copy link
Contributor

Choose a reason for hiding this comment

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

With CoT agent it will be feasible to let LLM/agent to paginate the request to fetch more data. However, as part of tool output it must need to specify if it is a partial or complete output.

I would prefer to make the tool configurable to specify the max result size so that the agent configuration will have flexibility to tweak tool usage based on underlying model.

Copy link
Member Author

Choose a reason for hiding this comment

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

Max results size will already be covered from tableSize value. I'll change to expose startIndex. My reasoning was to try to limit / scope what we expose and expand later when needed to try to keep things simple.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.

@@ -47,6 +47,7 @@ dependencies {
implementation("ai.djl.onnxruntime:onnxruntime-engine:0.21.0") {
exclude group: "com.microsoft.onnxruntime", module: "onnxruntime"
}
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.50"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why need to add this dependency?

Copy link
Member Author

Choose a reason for hiding this comment

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

For pulling in kotlin code from AlertingPluginInterface

Copy link
Member

Choose a reason for hiding this comment

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

Does just using common-utils not provide this?

api "org.opensearch:common-utils:${common_utils_version}@jar"

Copy link
Collaborator

Choose a reason for hiding this comment

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

@ohltyler Could you please update the response here?

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
@ohltyler
Copy link
Member Author

Rebased, confirmed all tests still passing.

@ylwu-amzn
Copy link
Collaborator

Rebased, confirmed all tests still passing.

@ohltyler , I see Github CI still failed. Have you ran gradlew build locally to verify?

@ohltyler
Copy link
Member Author

ohltyler commented Nov 15, 2023

Rebased, confirmed all tests still passing.

@ohltyler , I see Github CI still failed. Have you ran gradlew build locally to verify?

Yes, relevant tests pass, the error is unrelated to any of these changes. I'm just merging this to the dev branch.

From my understanding this branch is not prioritized to have passing CI, and most changes are being directly merged, which is probably why there are failures. I'm still ensuring these changes aren't causing new failures.

@ylwu-amzn
Copy link
Collaborator

ylwu-amzn commented Nov 15, 2023

Check the CI error, and find these

»  org.opensearch.bootstrap.StartupException: java.lang.IllegalStateException: codebase property already set: codebase.annotations -> file:/home/runner/work/ml-commons/ml-commons/plugin/build/testclusters/integTest-0/distro/2.11.0-ARCHIVE/plugins/opensearch-ml/annotations-13.0.jar, cannot set to file:/home/runner/work/ml-commons/ml-commons/plugin/build/testclusters/integTest-0/distro/2.11.0-ARCHIVE/plugins/opensearch-ml/annotations-2.21.15.jar

From the error , seems opensearch can't start up. If that's the case, that's not just unit test issue, that mean the OS can't startup, that will block other guys to work on this dev branch.

@dbwiddis
Copy link
Member

codebase property already set

Could this be from the kotlin dependency (trying to set the codebase as kotlin)? That dependency might need some excludes.

You also have a very old version (1.3.50) of that JAR, latest is 1.9.20

@ohltyler
Copy link
Member Author

codebase property already set

Could this be from the kotlin dependency (trying to set the codebase as kotlin)? That dependency might need some excludes.

You also have a very old version (1.3.50) of that JAR, latest is 1.9.20

Thanks for the inputs, confirmed this dependency is causing some problems now, somehow only has started happening after the rebases. I've been testing different versions and using alerting plugin for reference on the kotlin integration. I will push a change after some more testing.

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
@ohltyler
Copy link
Member Author

I've changed to 1.8.21 to match that of alerting and ensure this isn't pulling in new/unknown dependencies.

Copy link

codecov bot commented Nov 16, 2023

Codecov Report

Attention: 13 lines in your changes are missing coverage. Please review.

Comparison is base (39111f9) 67.13% compared to head (8a63aeb) 67.20%.
Report is 1 commits behind head on feature/agent_framework_dev.

Files Patch % Lines
...g/opensearch/ml/engine/tools/SearchAlertsTool.java 76.92% 6 Missing and 6 partials ⚠️
...h/ml/action/models/UpdateModelTransportAction.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@                        Coverage Diff                        @@
##             feature/agent_framework_dev    #1629      +/-   ##
=================================================================
+ Coverage                          67.13%   67.20%   +0.06%     
- Complexity                          2488     2496       +8     
=================================================================
  Files                                225      226       +1     
  Lines                              12113    12163      +50     
  Branches                            1249     1257       +8     
=================================================================
+ Hits                                8132     8174      +42     
- Misses                              3436     3437       +1     
- Partials                             545      552       +7     
Flag Coverage Δ
ml-commons 67.20% <75.47%> (+0.06%) ⬆️

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.

@ylwu-amzn ylwu-amzn merged commit 742f920 into opensearch-project:feature/agent_framework_dev Nov 16, 2023
4 of 7 checks passed
@ohltyler ohltyler deleted the search-alerts-tool-2 branch November 16, 2023 17:26
ohltyler added a commit to ohltyler/ml-commons that referenced this pull request Dec 11, 2023
* Add search alerts tool

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>

* Clean up test params; change validate()

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>

* Add kotlin dependency

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>

* remove spotless

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>

* revert one dep

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>

* Remove clusterservice; simplify param parsing

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>

* Add TYPE; cast o/p to String

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>

* Support null params passed

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>

* Expose startIndex

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>

* Bump kotlin to 1.8.21

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>

---------

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
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.

7 participants