From 996b125c7cdaee2f1bed0a2421079e26bcd0cdb7 Mon Sep 17 00:00:00 2001 From: Emanuele Ferrelli Date: Fri, 16 Jan 2026 09:22:24 +0100 Subject: [PATCH] Update openSearch step --- .../stepSolvers/OpenSearchQuerySolver.java | 220 +++++++++--------- 1 file changed, 110 insertions(+), 110 deletions(-) diff --git a/src/main/java/com/olympus/hermione/stepSolvers/OpenSearchQuerySolver.java b/src/main/java/com/olympus/hermione/stepSolvers/OpenSearchQuerySolver.java index d0a8bba..bb5421a 100644 --- a/src/main/java/com/olympus/hermione/stepSolvers/OpenSearchQuerySolver.java +++ b/src/main/java/com/olympus/hermione/stepSolvers/OpenSearchQuerySolver.java @@ -24,26 +24,26 @@ import ch.qos.logback.classic.Logger; public class OpenSearchQuerySolver extends StepSolver { private String opensearch_base_url; - // private String opensearch_project; + private String opensearch_project; private String opensearch_query; private String opensearch_search_type; - private Integer opensearch_k; + private Integer opensearch_topk; private Integer opensearch_max_context_chars; private Double opensearch_vector_weight; private Double opensearch_entity_weight; private String opensearch_output_variable; // Optional Ks* filter fields - // private String opensearch_ks_application_name; - // private String opensearch_ks_doctype; - // private String opensearch_ks_doc_source; - // private String opensearch_ks_file_source; - // private String opensearch_ks_document_id; - // private String opensearch_ks_project_name; - // private String opensearch_ks_knowledge_path; + private String opensearch_ks_application_name; + private String opensearch_ks_doctype; + private String opensearch_ks_doc_source; + private String opensearch_ks_file_source; + private String opensearch_ks_document_id; + private String opensearch_ks_project_name; + private String opensearch_ks_knowledge_path; // Optional tags filter (as JSON string) - // private String opensearch_tags; + private String opensearch_tags; Logger logger = (Logger) LoggerFactory.getLogger(OpenSearchQuerySolver.class); @@ -59,12 +59,12 @@ public class OpenSearchQuerySolver extends StepSolver { } // Project (required) - // if(this.step.getAttributes().get("opensearch_project") != null){ - // this.opensearch_project = (String) this.step.getAttributes().get("opensearch_project"); - // logger.info("opensearch_project: " + this.opensearch_project); - // } else { - // throw new IllegalArgumentException("opensearch_project is required"); - // } + if(this.step.getAttributes().get("opensearch_project") != null){ + this.opensearch_project = (String) this.step.getAttributes().get("opensearch_project"); + logger.info("opensearch_project: " + this.opensearch_project); + } else { + throw new IllegalArgumentException("opensearch_project is required"); + } // Query (required) if(this.step.getAttributes().get("opensearch_query") != null){ @@ -83,17 +83,17 @@ public class OpenSearchQuerySolver extends StepSolver { logger.info("opensearch_search_type: " + this.opensearch_search_type); // K (number of results, default: 5) - if(this.step.getAttributes().get("opensearch_k") != null){ + if(this.step.getAttributes().get("opensearch_topk") != null){ Object kValue = this.step.getAttributes().get("opensearch_k"); if(kValue instanceof Integer){ - this.opensearch_k = (Integer) kValue; + this.opensearch_topk = (Integer) kValue; } else { - this.opensearch_k = Integer.parseInt(kValue.toString()); + this.opensearch_topk = Integer.parseInt(kValue.toString()); } } else { - this.opensearch_k = 5; + this.opensearch_topk = 5; } - logger.info("opensearch_k: " + this.opensearch_k); + logger.info("opensearch_topk: " + this.opensearch_topk); // Max context chars (default: 4000) if(this.step.getAttributes().get("opensearch_max_context_chars") != null){ @@ -143,69 +143,69 @@ public class OpenSearchQuerySolver extends StepSolver { logger.info("opensearch_output_variable: " + this.opensearch_output_variable); // Load optional Ks* filter fields - // if(this.step.getAttributes().get("opensearch_ks_application_name") != null){ - // this.opensearch_ks_application_name = (String) this.step.getAttributes().get("opensearch_ks_application_name"); - // logger.info("opensearch_ks_application_name: " + this.opensearch_ks_application_name); - // } - // if(this.step.getAttributes().get("opensearch_ks_doctype") != null){ - // this.opensearch_ks_doctype = (String) this.step.getAttributes().get("opensearch_ks_doctype"); - // logger.info("opensearch_ks_doctype: " + this.opensearch_ks_doctype); - // } - // if(this.step.getAttributes().get("opensearch_ks_doc_source") != null){ - // this.opensearch_ks_doc_source = (String) this.step.getAttributes().get("opensearch_ks_doc_source"); - // logger.info("opensearch_ks_doc_source: " + this.opensearch_ks_doc_source); - // } - // if(this.step.getAttributes().get("opensearch_ks_file_source") != null){ - // this.opensearch_ks_file_source = (String) this.step.getAttributes().get("opensearch_ks_file_source"); - // logger.info("opensearch_ks_file_source: " + this.opensearch_ks_file_source); - // } - // if(this.step.getAttributes().get("opensearch_ks_document_id") != null){ - // this.opensearch_ks_document_id = (String) this.step.getAttributes().get("opensearch_ks_document_id"); - // logger.info("opensearch_ks_document_id: " + this.opensearch_ks_document_id); - // } - // if(this.step.getAttributes().get("opensearch_ks_project_name") != null){ - // this.opensearch_ks_project_name = (String) this.step.getAttributes().get("opensearch_ks_project_name"); - // logger.info("opensearch_ks_project_name: " + this.opensearch_ks_project_name); - // } - // if(this.step.getAttributes().get("opensearch_ks_knowledge_path") != null){ - // this.opensearch_ks_knowledge_path = (String) this.step.getAttributes().get("opensearch_ks_knowledge_path"); - // logger.info("opensearch_ks_knowledge_path: " + this.opensearch_ks_knowledge_path); - // } - // if(this.step.getAttributes().get("opensearch_tags") != null){ - // this.opensearch_tags = (String) this.step.getAttributes().get("opensearch_tags"); - // logger.info("opensearch_tags: " + this.opensearch_tags); - // } + if(this.step.getAttributes().get("opensearch_ks_application_name") != null){ + this.opensearch_ks_application_name = (String) this.step.getAttributes().get("opensearch_ks_application_name"); + logger.info("opensearch_ks_application_name: " + this.opensearch_ks_application_name); + } + if(this.step.getAttributes().get("opensearch_ks_doctype") != null){ + this.opensearch_ks_doctype = (String) this.step.getAttributes().get("opensearch_ks_doctype"); + logger.info("opensearch_ks_doctype: " + this.opensearch_ks_doctype); + } + if(this.step.getAttributes().get("opensearch_ks_doc_source") != null){ + this.opensearch_ks_doc_source = (String) this.step.getAttributes().get("opensearch_ks_doc_source"); + logger.info("opensearch_ks_doc_source: " + this.opensearch_ks_doc_source); + } + if(this.step.getAttributes().get("opensearch_ks_file_source") != null){ + this.opensearch_ks_file_source = (String) this.step.getAttributes().get("opensearch_ks_file_source"); + logger.info("opensearch_ks_file_source: " + this.opensearch_ks_file_source); + } + if(this.step.getAttributes().get("opensearch_ks_document_id") != null){ + this.opensearch_ks_document_id = (String) this.step.getAttributes().get("opensearch_ks_document_id"); + logger.info("opensearch_ks_document_id: " + this.opensearch_ks_document_id); + } + if(this.step.getAttributes().get("opensearch_ks_project_name") != null){ + this.opensearch_ks_project_name = (String) this.step.getAttributes().get("opensearch_ks_project_name"); + logger.info("opensearch_ks_project_name: " + this.opensearch_ks_project_name); + } + if(this.step.getAttributes().get("opensearch_ks_knowledge_path") != null){ + this.opensearch_ks_knowledge_path = (String) this.step.getAttributes().get("opensearch_ks_knowledge_path"); + logger.info("opensearch_ks_knowledge_path: " + this.opensearch_ks_knowledge_path); + } + if(this.step.getAttributes().get("opensearch_tags") != null){ + this.opensearch_tags = (String) this.step.getAttributes().get("opensearch_tags"); + logger.info("opensearch_tags: " + this.opensearch_tags); + } // Parse variables from execution context AttributeParser attributeParser = new AttributeParser(this.scenarioExecution); this.opensearch_query = attributeParser.parse(this.opensearch_query); - // this.opensearch_project = attributeParser.parse(this.opensearch_project); + this.opensearch_project = attributeParser.parse(this.opensearch_project); - // if(this.opensearch_ks_application_name != null){ - // this.opensearch_ks_application_name = attributeParser.parse(this.opensearch_ks_application_name); - // } - // if(this.opensearch_ks_doctype != null){ - // this.opensearch_ks_doctype = attributeParser.parse(this.opensearch_ks_doctype); - // } - // if(this.opensearch_ks_doc_source != null){ - // this.opensearch_ks_doc_source = attributeParser.parse(this.opensearch_ks_doc_source); - // } - // if(this.opensearch_ks_file_source != null){ - // this.opensearch_ks_file_source = attributeParser.parse(this.opensearch_ks_file_source); - // } - // if(this.opensearch_ks_document_id != null){ - // this.opensearch_ks_document_id = attributeParser.parse(this.opensearch_ks_document_id); - // } - // if(this.opensearch_ks_project_name != null){ - // this.opensearch_ks_project_name = attributeParser.parse(this.opensearch_ks_project_name); - // } - // if(this.opensearch_ks_knowledge_path != null){ - // this.opensearch_ks_knowledge_path = attributeParser.parse(this.opensearch_ks_knowledge_path); - // } - // if(this.opensearch_tags != null){ - // this.opensearch_tags = attributeParser.parse(this.opensearch_tags); - // } + if(this.opensearch_ks_application_name != null){ + this.opensearch_ks_application_name = attributeParser.parse(this.opensearch_ks_application_name); + } + if(this.opensearch_ks_doctype != null){ + this.opensearch_ks_doctype = attributeParser.parse(this.opensearch_ks_doctype); + } + if(this.opensearch_ks_doc_source != null){ + this.opensearch_ks_doc_source = attributeParser.parse(this.opensearch_ks_doc_source); + } + if(this.opensearch_ks_file_source != null){ + this.opensearch_ks_file_source = attributeParser.parse(this.opensearch_ks_file_source); + } + if(this.opensearch_ks_document_id != null){ + this.opensearch_ks_document_id = attributeParser.parse(this.opensearch_ks_document_id); + } + if(this.opensearch_ks_project_name != null){ + this.opensearch_ks_project_name = attributeParser.parse(this.opensearch_ks_project_name); + } + if(this.opensearch_ks_knowledge_path != null){ + this.opensearch_ks_knowledge_path = attributeParser.parse(this.opensearch_ks_knowledge_path); + } + if(this.opensearch_tags != null){ + this.opensearch_tags = attributeParser.parse(this.opensearch_tags); + } } @Override @@ -225,46 +225,46 @@ public class OpenSearchQuerySolver extends StepSolver { JSONObject requestBody = new JSONObject(); // Required fields - // requestBody.put("project", this.opensearch_project); + requestBody.put("project", this.opensearch_project); requestBody.put("query", this.opensearch_query); requestBody.put("search_type", this.opensearch_search_type); - requestBody.put("k", this.opensearch_k); + requestBody.put("k", this.opensearch_topk); requestBody.put("max_context_chars", this.opensearch_max_context_chars); requestBody.put("vector_weight", this.opensearch_vector_weight); requestBody.put("entity_weight", this.opensearch_entity_weight); // Add optional Ks* filters - // if(this.opensearch_ks_application_name != null){ - // requestBody.put("KsApplicationName", this.opensearch_ks_application_name); - // } - // if(this.opensearch_ks_doctype != null){ - // requestBody.put("KsDoctype", this.opensearch_ks_doctype); - // } - // if(this.opensearch_ks_doc_source != null){ - // requestBody.put("KsDocSource", this.opensearch_ks_doc_source); - // } - // if(this.opensearch_ks_file_source != null){ - // requestBody.put("KsFileSource", this.opensearch_ks_file_source); - // } - // if(this.opensearch_ks_document_id != null){ - // requestBody.put("KsDocumentId", this.opensearch_ks_document_id); - // } - // if(this.opensearch_ks_project_name != null){ - // requestBody.put("KsProjectName", this.opensearch_ks_project_name); - // } - // if(this.opensearch_ks_knowledge_path != null){ - // requestBody.put("KsKnowledgePath", this.opensearch_ks_knowledge_path); - // } + if(this.opensearch_ks_application_name != null){ + requestBody.put("KsApplicationName", this.opensearch_ks_application_name); + } + if(this.opensearch_ks_doctype != null){ + requestBody.put("KsDoctype", this.opensearch_ks_doctype); + } + if(this.opensearch_ks_doc_source != null){ + requestBody.put("KsDocSource", this.opensearch_ks_doc_source); + } + if(this.opensearch_ks_file_source != null){ + requestBody.put("KsFileSource", this.opensearch_ks_file_source); + } + if(this.opensearch_ks_document_id != null){ + requestBody.put("KsDocumentId", this.opensearch_ks_document_id); + } + if(this.opensearch_ks_project_name != null){ + requestBody.put("KsProjectName", this.opensearch_ks_project_name); + } + if(this.opensearch_ks_knowledge_path != null){ + requestBody.put("KsKnowledgePath", this.opensearch_ks_knowledge_path); + } - // // Add tags filter if provided - // if(this.opensearch_tags != null && !this.opensearch_tags.isEmpty()){ - // try { - // JSONObject tagsObj = new JSONObject(this.opensearch_tags); - // requestBody.put("tags", tagsObj); - // } catch (Exception e) { - // logger.warn("Failed to parse opensearch_tags as JSON, skipping", e); - // } - // } + // Add tags filter if provided + if(this.opensearch_tags != null && !this.opensearch_tags.isEmpty()){ + try { + JSONObject tagsObj = new JSONObject(this.opensearch_tags); + requestBody.put("tags", tagsObj); + } catch (Exception e) { + logger.warn("Failed to parse opensearch_tags as JSON, skipping", e); + } + } logger.info("Calling OpenSearch endpoint: " + endpoint); logger.info("Request body: " + requestBody.toString(2));