Skip to content

Adding query planning tool search template validation and integration tests#4177

Merged
mingshl merged 6 commits intoopensearch-project:mainfrom
joshpalis:integ
Sep 25, 2025
Merged

Adding query planning tool search template validation and integration tests#4177
mingshl merged 6 commits intoopensearch-project:mainfrom
joshpalis:integ

Conversation

@joshpalis
Copy link
Copy Markdown
Member

Description

  • Adds field validation for QueryPlanningTool field search_templates to require both template_id and template_description
  • Adds null check for StoredScript response, defaults to default search template if script response is null
  • Adds integration tests for Search template field

Additionally includes changes from #4176, will rebase once its 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.

@joshpalis joshpalis had a problem deploying to ml-commons-cicd-env-require-approval September 17, 2025 21:00 — with GitHub Actions Failure
@joshpalis joshpalis had a problem deploying to ml-commons-cicd-env-require-approval September 17, 2025 21:00 — with GitHub Actions Error
@joshpalis joshpalis had a problem deploying to ml-commons-cicd-env-require-approval September 17, 2025 21:00 — with GitHub Actions Failure
@joshpalis joshpalis had a problem deploying to ml-commons-cicd-env-require-approval September 17, 2025 21:00 — with GitHub Actions Failure
@joshpalis joshpalis had a problem deploying to ml-commons-cicd-env-require-approval September 17, 2025 21:02 — with GitHub Actions Failure
@joshpalis joshpalis had a problem deploying to ml-commons-cicd-env-require-approval September 17, 2025 21:02 — with GitHub Actions Failure
@joshpalis joshpalis had a problem deploying to ml-commons-cicd-env-require-approval September 17, 2025 21:02 — with GitHub Actions Failure
@joshpalis joshpalis had a problem deploying to ml-commons-cicd-env-require-approval September 17, 2025 21:02 — with GitHub Actions Failure
private static final String DEFAULT_SYSTEM_PROMPT =
"You are an OpenSearch Query DSL generation assistant, translating natural language questions to OpenSeach DSL Queries";

private static final Logger logger = LogManager.getLogger(QueryPlanningTool.class);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can you use the same logger like the rest of the repo?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ill remove the logger, left over from debugging

private void validateTemplateFields(Map<String, String> template) {
// Validate templateId
String templateId = template.get(TEMPLATE_ID_FIELD);
if (templateId == null || templateId.trim().isEmpty()) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

is it the same validation of search template or similar to opensearch core?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This validation is specifically for the query planning tool configuration, it ensures that each entry of the search_templates field contains both template_id and template_description

@joshpalis joshpalis had a problem deploying to ml-commons-cicd-env-require-approval September 17, 2025 21:13 — with GitHub Actions Failure
@joshpalis joshpalis had a problem deploying to ml-commons-cicd-env-require-approval September 17, 2025 21:13 — with GitHub Actions Failure
@joshpalis joshpalis had a problem deploying to ml-commons-cicd-env-require-approval September 17, 2025 21:13 — with GitHub Actions Failure
@joshpalis joshpalis had a problem deploying to ml-commons-cicd-env-require-approval September 17, 2025 21:13 — with GitHub Actions Error

// Validate templateDescription
String templateDescription = template.get(TEMPLATE_DESCRIPTION_FIELD);
if (templateDescription == null || templateDescription.trim().isEmpty()) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: can we use .isBlank() instead of .trim().isEmpty()
isBalnk() is more efficient

Comment on lines +71 to +73
zipArchive("org.opensearch.plugin:opensearch-job-scheduler:${opensearch_build}")
zipArchive("org.opensearch.plugin:opensearch-knn:${opensearch_build}")
zipArchive("org.opensearch.plugin:neural-search:${opensearch_build}")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we remove these?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ah yeah, left over from debugging, Ill remove in the next commit

Comment on lines +264 to +285
plugin(provider(new Callable<RegularFile>(){
@Override
RegularFile call() throws Exception {
return new RegularFile() {
@Override
File getAsFile() {
return configurations.zipArchive.asFileTree.matching{include "**/opensearch-knn-${opensearch_build}.zip"}.getSingleFile()
}
}
}
}))
plugin(provider(new Callable<RegularFile>(){
@Override
RegularFile call() throws Exception {
return new RegularFile() {
@Override
File getAsFile() {
return configurations.zipArchive.asFileTree.matching{include "**/neural-search-${opensearch_build}.zip"}.getSingleFile()
}
}
}
}))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we remove these too

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we need to have these plugins in the integTest setup?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

will do

Copy link
Copy Markdown
Member

@owaiskazi19 owaiskazi19 left a comment

Choose a reason for hiding this comment

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

Looks good overall

GetStoredScriptRequest getStoredScriptRequest = new GetStoredScriptRequest(templateId);
client.admin().cluster().getStoredScript(getStoredScriptRequest, ActionListener.wrap(getStoredScriptResponse -> {
parameters.put(TEMPLATE_FIELD, gson.toJson(getStoredScriptResponse.getSource().getSource()));
if (getStoredScriptResponse.getSource() == null) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can just check and replace TEMPLATE_FIELD

 if (getStoredScriptResponse.getSource() != null) {
      parameters.put(TEMPLATE_FIELD, gson.toJson(getStoredScriptResponse.getSource().getSource()));
 }

and add

                    parameters.put(TEMPLATE_FIELD, DEFAULT_SEARCH_TEMPLATE);

at the top of both the conditions

@joshpalis joshpalis had a problem deploying to ml-commons-cicd-env-require-approval September 17, 2025 21:39 — with GitHub Actions Failure
@joshpalis joshpalis had a problem deploying to ml-commons-cicd-env-require-approval September 19, 2025 00:43 — with GitHub Actions Error
@joshpalis joshpalis had a problem deploying to ml-commons-cicd-env-require-approval September 19, 2025 00:43 — with GitHub Actions Error
@joshpalis joshpalis had a problem deploying to ml-commons-cicd-env-require-approval September 19, 2025 00:43 — with GitHub Actions Failure
@joshpalis joshpalis had a problem deploying to ml-commons-cicd-env-require-approval September 19, 2025 00:43 — with GitHub Actions Failure
@joshpalis joshpalis temporarily deployed to ml-commons-cicd-env-require-approval September 19, 2025 17:32 — with GitHub Actions Inactive
@joshpalis joshpalis had a problem deploying to ml-commons-cicd-env-require-approval September 19, 2025 17:32 — with GitHub Actions Error
@joshpalis joshpalis had a problem deploying to ml-commons-cicd-env-require-approval September 19, 2025 17:32 — with GitHub Actions Failure
@joshpalis joshpalis had a problem deploying to ml-commons-cicd-env-require-approval September 19, 2025 17:32 — with GitHub Actions Failure
@mingshl
Copy link
Copy Markdown
Collaborator

mingshl commented Sep 19, 2025

you need to meet the codecov for your if else condition

@joshpalis joshpalis had a problem deploying to ml-commons-cicd-env-require-approval September 22, 2025 19:54 — with GitHub Actions Failure
@joshpalis joshpalis had a problem deploying to ml-commons-cicd-env-require-approval September 22, 2025 19:54 — with GitHub Actions Failure
@joshpalis joshpalis had a problem deploying to ml-commons-cicd-env-require-approval September 22, 2025 19:54 — with GitHub Actions Failure
@joshpalis joshpalis had a problem deploying to ml-commons-cicd-env-require-approval September 22, 2025 19:54 — with GitHub Actions Failure
Signed-off-by: Joshua Palis <jpalis@amazon.com>
@joshpalis joshpalis temporarily deployed to ml-commons-cicd-env-require-approval September 22, 2025 20:06 — with GitHub Actions Inactive
@joshpalis joshpalis had a problem deploying to ml-commons-cicd-env-require-approval September 22, 2025 20:06 — with GitHub Actions Error
@joshpalis joshpalis temporarily deployed to ml-commons-cicd-env-require-approval September 22, 2025 20:06 — with GitHub Actions Inactive
@joshpalis joshpalis had a problem deploying to ml-commons-cicd-env-require-approval September 22, 2025 20:06 — with GitHub Actions Failure
@joshpalis joshpalis had a problem deploying to ml-commons-cicd-env-require-approval September 22, 2025 21:21 — with GitHub Actions Failure
@joshpalis joshpalis had a problem deploying to ml-commons-cicd-env-require-approval September 22, 2025 21:21 — with GitHub Actions Error
@joshpalis joshpalis had a problem deploying to ml-commons-cicd-env-require-approval September 24, 2025 18:04 — with GitHub Actions Failure
@joshpalis joshpalis had a problem deploying to ml-commons-cicd-env-require-approval September 24, 2025 18:04 — with GitHub Actions Error
@joshpalis joshpalis temporarily deployed to ml-commons-cicd-env-require-approval September 24, 2025 18:04 — with GitHub Actions Inactive
@mingshl
Copy link
Copy Markdown
Collaborator

mingshl commented Sep 25, 2025

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.

5 participants