fabriziofortino commented on code in PR #1804:
URL: https://github.com/apache/jackrabbit-oak/pull/1804#discussion_r1822905066
##########
oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexDefinition.java:
##########
@@ -381,4 +408,238 @@ protected IndexDefinition createInstance(NodeState
indexDefnStateToUse) {
return new ElasticIndexDefinition(root, indexDefnStateToUse,
indexPath, indexPrefix);
}
}
+
+ /**
+ * Represents the inference configuration for an Elasticsearch index
definition.
+ * This class holds the properties and queries used for inference.
+ */
+ public static class InferenceDefinition {
+
+ /**
+ * List of properties used for inference.
+ */
+ public List<Property> properties;
+
+ /**
+ * List of queries used for inference.
+ */
+ public List<Query> queries;
+
+ public InferenceDefinition() { }
+
+ /**
+ * Constructs an InferenceDefinition from a given NodeState.
+ *
+ * @param inferenceNode the NodeState containing the inference
configuration
+ */
+ public InferenceDefinition(NodeState inferenceNode) {
+ if (inferenceNode.hasChildNode("properties")) {
+ this.properties =
StreamSupport.stream(inferenceNode.getChildNode("properties").getChildNodeEntries().spliterator(),
false)
+ .map(cne -> new Property(cne.getName(),
cne.getNodeState()))
+ .collect(Collectors.toList());
+ }
+ if (inferenceNode.hasChildNode("queries")) {
+ this.queries =
StreamSupport.stream(inferenceNode.getChildNode("queries").getChildNodeEntries().spliterator(),
false)
+ .map(cne -> new Query(cne.getName(),
cne.getNodeState()))
+ .collect(Collectors.toList());
+ }
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ InferenceDefinition that = (InferenceDefinition) o;
+ return Objects.equals(properties, that.properties) &&
Objects.equals(queries, that.queries);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(properties, queries);
+ }
+
+ /**
+ * Represents a property used for inference.
+ */
+ public static class Property {
+ /**
+ * The name of the property. It will be prefixed with {@link
ElasticIndexDefinition#INFERENCE}. when stored in the index.
+ */
+ public String name;
+ /**
+ * The model used for inference. Default is "semantic". This will
be used by the inference service to determine the model to use.
+ */
+ public String model;
+ /**
+ * The fields used for inference. These fields will be used to
generate the vector for the inference.
+ */
+ public List<String> fields;
+ /**
+ * The number of dimensions for the vector generated for the
inference.
+ */
+ public int dims;
+ /**
+ * The similarity function used for the inference. Default is
"cosine".
+ */
+ public String similarity;
+
+ public Property() {}
Review Comment:
the default contructor is need by jackson to deserialize the object (used in
the tests). Modifier has been changed to `protected`, added SuppressWarning
annotation, and added comment to document this.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]