Update openSearch step
This commit is contained in:
@@ -24,26 +24,26 @@ import ch.qos.logback.classic.Logger;
|
|||||||
public class OpenSearchQuerySolver extends StepSolver {
|
public class OpenSearchQuerySolver extends StepSolver {
|
||||||
|
|
||||||
private String opensearch_base_url;
|
private String opensearch_base_url;
|
||||||
// private String opensearch_project;
|
private String opensearch_project;
|
||||||
private String opensearch_query;
|
private String opensearch_query;
|
||||||
private String opensearch_search_type;
|
private String opensearch_search_type;
|
||||||
private Integer opensearch_k;
|
private Integer opensearch_topk;
|
||||||
private Integer opensearch_max_context_chars;
|
private Integer opensearch_max_context_chars;
|
||||||
private Double opensearch_vector_weight;
|
private Double opensearch_vector_weight;
|
||||||
private Double opensearch_entity_weight;
|
private Double opensearch_entity_weight;
|
||||||
private String opensearch_output_variable;
|
private String opensearch_output_variable;
|
||||||
|
|
||||||
// Optional Ks* filter fields
|
// Optional Ks* filter fields
|
||||||
// private String opensearch_ks_application_name;
|
private String opensearch_ks_application_name;
|
||||||
// private String opensearch_ks_doctype;
|
private String opensearch_ks_doctype;
|
||||||
// private String opensearch_ks_doc_source;
|
private String opensearch_ks_doc_source;
|
||||||
// private String opensearch_ks_file_source;
|
private String opensearch_ks_file_source;
|
||||||
// private String opensearch_ks_document_id;
|
private String opensearch_ks_document_id;
|
||||||
// private String opensearch_ks_project_name;
|
private String opensearch_ks_project_name;
|
||||||
// private String opensearch_ks_knowledge_path;
|
private String opensearch_ks_knowledge_path;
|
||||||
|
|
||||||
// Optional tags filter (as JSON string)
|
// Optional tags filter (as JSON string)
|
||||||
// private String opensearch_tags;
|
private String opensearch_tags;
|
||||||
|
|
||||||
Logger logger = (Logger) LoggerFactory.getLogger(OpenSearchQuerySolver.class);
|
Logger logger = (Logger) LoggerFactory.getLogger(OpenSearchQuerySolver.class);
|
||||||
|
|
||||||
@@ -59,12 +59,12 @@ public class OpenSearchQuerySolver extends StepSolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Project (required)
|
// Project (required)
|
||||||
// if(this.step.getAttributes().get("opensearch_project") != null){
|
if(this.step.getAttributes().get("opensearch_project") != null){
|
||||||
// this.opensearch_project = (String) this.step.getAttributes().get("opensearch_project");
|
this.opensearch_project = (String) this.step.getAttributes().get("opensearch_project");
|
||||||
// logger.info("opensearch_project: " + this.opensearch_project);
|
logger.info("opensearch_project: " + this.opensearch_project);
|
||||||
// } else {
|
} else {
|
||||||
// throw new IllegalArgumentException("opensearch_project is required");
|
throw new IllegalArgumentException("opensearch_project is required");
|
||||||
// }
|
}
|
||||||
|
|
||||||
// Query (required)
|
// Query (required)
|
||||||
if(this.step.getAttributes().get("opensearch_query") != null){
|
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);
|
logger.info("opensearch_search_type: " + this.opensearch_search_type);
|
||||||
|
|
||||||
// K (number of results, default: 5)
|
// 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");
|
Object kValue = this.step.getAttributes().get("opensearch_k");
|
||||||
if(kValue instanceof Integer){
|
if(kValue instanceof Integer){
|
||||||
this.opensearch_k = (Integer) kValue;
|
this.opensearch_topk = (Integer) kValue;
|
||||||
} else {
|
} else {
|
||||||
this.opensearch_k = Integer.parseInt(kValue.toString());
|
this.opensearch_topk = Integer.parseInt(kValue.toString());
|
||||||
}
|
}
|
||||||
} else {
|
} 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)
|
// Max context chars (default: 4000)
|
||||||
if(this.step.getAttributes().get("opensearch_max_context_chars") != null){
|
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);
|
logger.info("opensearch_output_variable: " + this.opensearch_output_variable);
|
||||||
|
|
||||||
// Load optional Ks* filter fields
|
// Load optional Ks* filter fields
|
||||||
// if(this.step.getAttributes().get("opensearch_ks_application_name") != null){
|
if(this.step.getAttributes().get("opensearch_ks_application_name") != null){
|
||||||
// this.opensearch_ks_application_name = (String) this.step.getAttributes().get("opensearch_ks_application_name");
|
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);
|
logger.info("opensearch_ks_application_name: " + this.opensearch_ks_application_name);
|
||||||
// }
|
}
|
||||||
// if(this.step.getAttributes().get("opensearch_ks_doctype") != null){
|
if(this.step.getAttributes().get("opensearch_ks_doctype") != null){
|
||||||
// this.opensearch_ks_doctype = (String) this.step.getAttributes().get("opensearch_ks_doctype");
|
this.opensearch_ks_doctype = (String) this.step.getAttributes().get("opensearch_ks_doctype");
|
||||||
// logger.info("opensearch_ks_doctype: " + this.opensearch_ks_doctype);
|
logger.info("opensearch_ks_doctype: " + this.opensearch_ks_doctype);
|
||||||
// }
|
}
|
||||||
// if(this.step.getAttributes().get("opensearch_ks_doc_source") != null){
|
if(this.step.getAttributes().get("opensearch_ks_doc_source") != null){
|
||||||
// this.opensearch_ks_doc_source = (String) this.step.getAttributes().get("opensearch_ks_doc_source");
|
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);
|
logger.info("opensearch_ks_doc_source: " + this.opensearch_ks_doc_source);
|
||||||
// }
|
}
|
||||||
// if(this.step.getAttributes().get("opensearch_ks_file_source") != null){
|
if(this.step.getAttributes().get("opensearch_ks_file_source") != null){
|
||||||
// this.opensearch_ks_file_source = (String) this.step.getAttributes().get("opensearch_ks_file_source");
|
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);
|
logger.info("opensearch_ks_file_source: " + this.opensearch_ks_file_source);
|
||||||
// }
|
}
|
||||||
// if(this.step.getAttributes().get("opensearch_ks_document_id") != null){
|
if(this.step.getAttributes().get("opensearch_ks_document_id") != null){
|
||||||
// this.opensearch_ks_document_id = (String) this.step.getAttributes().get("opensearch_ks_document_id");
|
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);
|
logger.info("opensearch_ks_document_id: " + this.opensearch_ks_document_id);
|
||||||
// }
|
}
|
||||||
// if(this.step.getAttributes().get("opensearch_ks_project_name") != null){
|
if(this.step.getAttributes().get("opensearch_ks_project_name") != null){
|
||||||
// this.opensearch_ks_project_name = (String) this.step.getAttributes().get("opensearch_ks_project_name");
|
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);
|
logger.info("opensearch_ks_project_name: " + this.opensearch_ks_project_name);
|
||||||
// }
|
}
|
||||||
// if(this.step.getAttributes().get("opensearch_ks_knowledge_path") != null){
|
if(this.step.getAttributes().get("opensearch_ks_knowledge_path") != null){
|
||||||
// this.opensearch_ks_knowledge_path = (String) this.step.getAttributes().get("opensearch_ks_knowledge_path");
|
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);
|
logger.info("opensearch_ks_knowledge_path: " + this.opensearch_ks_knowledge_path);
|
||||||
// }
|
}
|
||||||
// if(this.step.getAttributes().get("opensearch_tags") != null){
|
if(this.step.getAttributes().get("opensearch_tags") != null){
|
||||||
// this.opensearch_tags = (String) this.step.getAttributes().get("opensearch_tags");
|
this.opensearch_tags = (String) this.step.getAttributes().get("opensearch_tags");
|
||||||
// logger.info("opensearch_tags: " + this.opensearch_tags);
|
logger.info("opensearch_tags: " + this.opensearch_tags);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// Parse variables from execution context
|
// Parse variables from execution context
|
||||||
AttributeParser attributeParser = new AttributeParser(this.scenarioExecution);
|
AttributeParser attributeParser = new AttributeParser(this.scenarioExecution);
|
||||||
|
|
||||||
this.opensearch_query = attributeParser.parse(this.opensearch_query);
|
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){
|
if(this.opensearch_ks_application_name != null){
|
||||||
// this.opensearch_ks_application_name = attributeParser.parse(this.opensearch_ks_application_name);
|
this.opensearch_ks_application_name = attributeParser.parse(this.opensearch_ks_application_name);
|
||||||
// }
|
}
|
||||||
// if(this.opensearch_ks_doctype != null){
|
if(this.opensearch_ks_doctype != null){
|
||||||
// this.opensearch_ks_doctype = attributeParser.parse(this.opensearch_ks_doctype);
|
this.opensearch_ks_doctype = attributeParser.parse(this.opensearch_ks_doctype);
|
||||||
// }
|
}
|
||||||
// if(this.opensearch_ks_doc_source != null){
|
if(this.opensearch_ks_doc_source != null){
|
||||||
// this.opensearch_ks_doc_source = attributeParser.parse(this.opensearch_ks_doc_source);
|
this.opensearch_ks_doc_source = attributeParser.parse(this.opensearch_ks_doc_source);
|
||||||
// }
|
}
|
||||||
// if(this.opensearch_ks_file_source != null){
|
if(this.opensearch_ks_file_source != null){
|
||||||
// this.opensearch_ks_file_source = attributeParser.parse(this.opensearch_ks_file_source);
|
this.opensearch_ks_file_source = attributeParser.parse(this.opensearch_ks_file_source);
|
||||||
// }
|
}
|
||||||
// if(this.opensearch_ks_document_id != null){
|
if(this.opensearch_ks_document_id != null){
|
||||||
// this.opensearch_ks_document_id = attributeParser.parse(this.opensearch_ks_document_id);
|
this.opensearch_ks_document_id = attributeParser.parse(this.opensearch_ks_document_id);
|
||||||
// }
|
}
|
||||||
// if(this.opensearch_ks_project_name != null){
|
if(this.opensearch_ks_project_name != null){
|
||||||
// this.opensearch_ks_project_name = attributeParser.parse(this.opensearch_ks_project_name);
|
this.opensearch_ks_project_name = attributeParser.parse(this.opensearch_ks_project_name);
|
||||||
// }
|
}
|
||||||
// if(this.opensearch_ks_knowledge_path != null){
|
if(this.opensearch_ks_knowledge_path != null){
|
||||||
// this.opensearch_ks_knowledge_path = attributeParser.parse(this.opensearch_ks_knowledge_path);
|
this.opensearch_ks_knowledge_path = attributeParser.parse(this.opensearch_ks_knowledge_path);
|
||||||
// }
|
}
|
||||||
// if(this.opensearch_tags != null){
|
if(this.opensearch_tags != null){
|
||||||
// this.opensearch_tags = attributeParser.parse(this.opensearch_tags);
|
this.opensearch_tags = attributeParser.parse(this.opensearch_tags);
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -225,46 +225,46 @@ public class OpenSearchQuerySolver extends StepSolver {
|
|||||||
JSONObject requestBody = new JSONObject();
|
JSONObject requestBody = new JSONObject();
|
||||||
|
|
||||||
// Required fields
|
// Required fields
|
||||||
// requestBody.put("project", this.opensearch_project);
|
requestBody.put("project", this.opensearch_project);
|
||||||
requestBody.put("query", this.opensearch_query);
|
requestBody.put("query", this.opensearch_query);
|
||||||
requestBody.put("search_type", this.opensearch_search_type);
|
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("max_context_chars", this.opensearch_max_context_chars);
|
||||||
requestBody.put("vector_weight", this.opensearch_vector_weight);
|
requestBody.put("vector_weight", this.opensearch_vector_weight);
|
||||||
requestBody.put("entity_weight", this.opensearch_entity_weight);
|
requestBody.put("entity_weight", this.opensearch_entity_weight);
|
||||||
|
|
||||||
// Add optional Ks* filters
|
// Add optional Ks* filters
|
||||||
// if(this.opensearch_ks_application_name != null){
|
if(this.opensearch_ks_application_name != null){
|
||||||
// requestBody.put("KsApplicationName", this.opensearch_ks_application_name);
|
requestBody.put("KsApplicationName", this.opensearch_ks_application_name);
|
||||||
// }
|
}
|
||||||
// if(this.opensearch_ks_doctype != null){
|
if(this.opensearch_ks_doctype != null){
|
||||||
// requestBody.put("KsDoctype", this.opensearch_ks_doctype);
|
requestBody.put("KsDoctype", this.opensearch_ks_doctype);
|
||||||
// }
|
}
|
||||||
// if(this.opensearch_ks_doc_source != null){
|
if(this.opensearch_ks_doc_source != null){
|
||||||
// requestBody.put("KsDocSource", this.opensearch_ks_doc_source);
|
requestBody.put("KsDocSource", this.opensearch_ks_doc_source);
|
||||||
// }
|
}
|
||||||
// if(this.opensearch_ks_file_source != null){
|
if(this.opensearch_ks_file_source != null){
|
||||||
// requestBody.put("KsFileSource", this.opensearch_ks_file_source);
|
requestBody.put("KsFileSource", this.opensearch_ks_file_source);
|
||||||
// }
|
}
|
||||||
// if(this.opensearch_ks_document_id != null){
|
if(this.opensearch_ks_document_id != null){
|
||||||
// requestBody.put("KsDocumentId", this.opensearch_ks_document_id);
|
requestBody.put("KsDocumentId", this.opensearch_ks_document_id);
|
||||||
// }
|
}
|
||||||
// if(this.opensearch_ks_project_name != null){
|
if(this.opensearch_ks_project_name != null){
|
||||||
// requestBody.put("KsProjectName", this.opensearch_ks_project_name);
|
requestBody.put("KsProjectName", this.opensearch_ks_project_name);
|
||||||
// }
|
}
|
||||||
// if(this.opensearch_ks_knowledge_path != null){
|
if(this.opensearch_ks_knowledge_path != null){
|
||||||
// requestBody.put("KsKnowledgePath", this.opensearch_ks_knowledge_path);
|
requestBody.put("KsKnowledgePath", this.opensearch_ks_knowledge_path);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // Add tags filter if provided
|
// Add tags filter if provided
|
||||||
// if(this.opensearch_tags != null && !this.opensearch_tags.isEmpty()){
|
if(this.opensearch_tags != null && !this.opensearch_tags.isEmpty()){
|
||||||
// try {
|
try {
|
||||||
// JSONObject tagsObj = new JSONObject(this.opensearch_tags);
|
JSONObject tagsObj = new JSONObject(this.opensearch_tags);
|
||||||
// requestBody.put("tags", tagsObj);
|
requestBody.put("tags", tagsObj);
|
||||||
// } catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// logger.warn("Failed to parse opensearch_tags as JSON, skipping", e);
|
logger.warn("Failed to parse opensearch_tags as JSON, skipping", e);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
logger.info("Calling OpenSearch endpoint: " + endpoint);
|
logger.info("Calling OpenSearch endpoint: " + endpoint);
|
||||||
logger.info("Request body: " + requestBody.toString(2));
|
logger.info("Request body: " + requestBody.toString(2));
|
||||||
|
|||||||
Reference in New Issue
Block a user