Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public MinimalServiceSettings(Model model) {
model.getServiceSettings().dimensions(),
model.getServiceSettings().similarity(),
model.getServiceSettings().elementType(),
model.getConfigurations().getEndpointMetadata()
model.getConfigurations().getEndpointMetadataOrEmpty()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,16 @@ public ChunkingSettings getChunkingSettings() {
return chunkingSettings;
}

public EndpointMetadata getEndpointMetadata() {
public EndpointMetadata getEndpointMetadataOrEmpty() {
// Outside of this class, we'll use the empty instance so callers can avoid the null check
return Objects.requireNonNullElse(endpointMetadata, EndpointMetadata.EMPTY_INSTANCE);
}

@Nullable
public EndpointMetadata getEndpointMetadata() {
return endpointMetadata;
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
return toXContent(builder, params, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,38 +135,41 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
return builder;
}

@Override
public String toString() {
return "EndpointMetadata{" + "heuristics=" + heuristics + ", internal=" + internal + ", display=" + display + '}';
}

@Override
public void writeTo(StreamOutput out) throws IOException {
heuristics.writeTo(out);
internal.writeTo(out);
display.writeTo(out);
}

public record Display(@Nullable String name) implements ToXContentObject, Writeable {
public record Display(@Nullable String name, @Nullable String modelCreator) implements ToXContentObject, Writeable {

public static final Display EMPTY_INSTANCE = new Display(null, null);

public static final Display EMPTY_INSTANCE = new Display((String) null);
public static final String NAME_FIELD = "name";
public static final String MODEL_CREATOR_FIELD = "model_creator";

public static final TransportVersion MODEL_CREATOR_ADDED = TransportVersion.fromName(
"inference_endpoint_metadata_display_model_creator_added"
);

private static final ConstructingObjectParser<Display, Void> PARSER = new ConstructingObjectParser<>(
"endpoint_metadata_display",
true,
args -> new Display((String) args[0])
args -> new Display((String) args[0], (String) args[1])
);

static {
PARSER.declareStringOrNull(ConstructingObjectParser.optionalConstructorArg(), new ParseField(NAME_FIELD));
PARSER.declareStringOrNull(ConstructingObjectParser.optionalConstructorArg(), new ParseField(MODEL_CREATOR_FIELD));
}

public static Display parse(XContentParser parser) throws IOException {
return PARSER.apply(parser, null);
}

public Display(StreamInput in) throws IOException {
this(in.readOptionalString());
this(in.readOptionalString(), in.getTransportVersion().supports(MODEL_CREATOR_ADDED) ? in.readOptionalString() : null);
}

@Override
Expand All @@ -175,18 +178,19 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
if (name != null) {
builder.field(NAME_FIELD, name);
}
if (modelCreator != null) {
builder.field(MODEL_CREATOR_FIELD, modelCreator);
}
builder.endObject();
return builder;
}

@Override
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you 🙏

public String toString() {
return "Display{" + "name=" + name + '}';
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeOptionalString(name);
if (out.getTransportVersion().supports(MODEL_CREATOR_ADDED)) {
out.writeOptionalString(modelCreator);
}
}

public boolean isEmpty() {
Expand Down Expand Up @@ -284,23 +288,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
return builder;
}

@Override
public String toString() {
return "Heuristics{"
+ "properties="
+ properties
+ ", status='"
+ status
+ '\''
+ ", releaseDate='"
+ releaseDate
+ '\''
+ ", endOfLifeDate='"
+ endOfLifeDate
+ '\''
+ '}';
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeStringCollection(properties);
Expand Down Expand Up @@ -368,11 +355,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
return builder;
}

@Override
public String toString() {
return "Internal{" + "fingerprint=" + fingerprint + ", version=" + version + '}';
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeOptionalString(fingerprint);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9314000
2 changes: 1 addition & 1 deletion server/src/main/resources/transport/upper_bounds/9.4.csv
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sql_optional_allow_partial_search_results,9313000
inference_endpoint_metadata_display_model_creator_added,9314000
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class EndpointMetadataTests extends AbstractBWCSerializationTestCase<Endp
private static final EndpointMetadata NON_EMPTY_ENDPOINT_METADATA = new EndpointMetadata(
new EndpointMetadata.Heuristics(List.of("heuristic1", "heuristic2"), StatusHeuristic.BETA, "2025-01-01", "2025-12-31"),
new EndpointMetadata.Internal("fingerprint", 1L),
new EndpointMetadata.Display("name")
new EndpointMetadata.Display("name", "some_creator")
);

private static final String NON_EMPTY_ENDPOINT_METADATA_JSON = """
Expand All @@ -50,7 +50,8 @@ public class EndpointMetadataTests extends AbstractBWCSerializationTestCase<Endp
"version": 1
},
"display": {
"name": "name"
"name": "name",
"model_creator": "some_creator"
}
}
""";
Expand All @@ -64,7 +65,8 @@ public class EndpointMetadataTests extends AbstractBWCSerializationTestCase<Endp
"end_of_life_date": "2025-12-31"
},
"display": {
"name": "name"
"name": "name",
"model_creator": "some_creator"
}
}
""";
Expand Down Expand Up @@ -97,13 +99,15 @@ public static EndpointMetadata randomNonEmptyInstance() {
var version = randomLongBetween(0, Long.MAX_VALUE);
var internal = new EndpointMetadata.Internal(fingerprint, version);

var display = new EndpointMetadata.Display(randomAlphaOfLengthBetween(1, 20));
var display = new EndpointMetadata.Display(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLength(10));

return new EndpointMetadata(heuristics, internal, display);
}

public static EndpointMetadata.Display randomDisplay() {
return randomBoolean() ? EndpointMetadata.Display.EMPTY_INSTANCE : new EndpointMetadata.Display(randomAlphaOfLengthBetween(1, 20));
return randomBoolean()
? EndpointMetadata.Display.EMPTY_INSTANCE
: new EndpointMetadata.Display(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLength(10));
}

public static EndpointMetadata.Heuristics randomHeuristics() {
Expand Down Expand Up @@ -291,6 +295,13 @@ protected EndpointMetadata mutateInstance(EndpointMetadata instance) throws IOEx

@Override
protected EndpointMetadata mutateInstanceForVersion(EndpointMetadata instance, TransportVersion version) {
if (version.supports(EndpointMetadata.Display.MODEL_CREATOR_ADDED) == false) {
return new EndpointMetadata(
instance.heuristics(),
instance.internal(),
new EndpointMetadata.Display(instance.display().name(), null)
);
}
return instance;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class MinimalServiceSettingsTests extends AbstractBWCSerializationTestCas
new EndpointMetadata(
new EndpointMetadata.Heuristics(List.of("heuristic1", "heuristic2"), StatusHeuristic.BETA, "2025-01-01", "2025-12-31"),
new EndpointMetadata.Internal("fingerprint", 1L),
new EndpointMetadata.Display("name")
new EndpointMetadata.Display("name", "creator")
)
);

Expand All @@ -86,7 +86,8 @@ public class MinimalServiceSettingsTests extends AbstractBWCSerializationTestCas
"version": 1
},
"display": {
"name": "name"
"name": "name",
"model_creator": "creator"
}
}
}
Expand Down Expand Up @@ -201,19 +202,26 @@ protected MinimalServiceSettings mutateInstance(MinimalServiceSettings instance)
@Override
protected MinimalServiceSettings mutateInstanceForVersion(MinimalServiceSettings instance, TransportVersion version) {
var metadataVersion = TransportVersion.fromName("inference_endpoint_metadata_fields_added");
var metadataDisplayModelCreatorAddedVersion = TransportVersion.fromName("inference_endpoint_metadata_display_model_creator_added");

if (version.supports(metadataVersion)) {
return instance;
} else {
return new MinimalServiceSettings(
instance.service(),
instance.taskType(),
instance.dimensions(),
instance.similarity(),
instance.elementType(),
EndpointMetadata.EMPTY_INSTANCE
var endpointMetadata = instance.endpointMetadata();
if (version.supports(metadataVersion) == false) {
endpointMetadata = EndpointMetadata.EMPTY_INSTANCE;
} else if (version.supports(metadataDisplayModelCreatorAddedVersion) == false) {
endpointMetadata = new EndpointMetadata(
endpointMetadata.heuristics(),
endpointMetadata.internal(),
new EndpointMetadata.Display(endpointMetadata.display().name(), null)
);
}
return new MinimalServiceSettings(
instance.service(),
instance.taskType(),
instance.dimensions(),
instance.similarity(),
instance.elementType(),
endpointMetadata
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Map;

import static org.elasticsearch.inference.metadata.EndpointMetadata.DISPLAY_FIELD_NAME;
import static org.elasticsearch.inference.metadata.EndpointMetadata.Display.MODEL_CREATOR_FIELD;
import static org.elasticsearch.inference.metadata.EndpointMetadata.Display.NAME_FIELD;
import static org.elasticsearch.inference.metadata.EndpointMetadata.HEURISTICS_FIELD_NAME;
import static org.elasticsearch.inference.metadata.EndpointMetadata.Heuristics.END_OF_LIFE_DATE_FIELD_NAME;
Expand Down Expand Up @@ -120,12 +121,13 @@ static EndpointMetadata.Display displayFromMap(@Nullable Map<String, Object> map
return EndpointMetadata.Display.EMPTY_INSTANCE;
}
var name = ObjectParserUtils.removeAsType(map, NAME_FIELD, root, String.class);
var modelCreator = ObjectParserUtils.removeAsType(map, MODEL_CREATOR_FIELD, root, String.class);

if (name == null) {
if (name == null && modelCreator == null) {
return EndpointMetadata.Display.EMPTY_INSTANCE;
}

return new EndpointMetadata.Display(name);
return new EndpointMetadata.Display(name, modelCreator);
}

private EndpointMetadataParser() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ private static boolean shouldPersistEndpoint(Model newEndpoint, @Nullable Minima
}

EndpointMetadata existingMetadata = existingEndpoint.endpointMetadata();
if (existingMetadata.fingerprintMatches(newEndpoint.getConfigurations().getEndpointMetadata()) == false) {
if (existingMetadata.fingerprintMatches(newEndpoint.getConfigurations().getEndpointMetadataOrEmpty()) == false) {
logger.debug(
() -> Strings.format(
"[%s] selected for persistence, because its fingerprint has changed",
Expand All @@ -373,7 +373,7 @@ private static boolean shouldPersistEndpoint(Model newEndpoint, @Nullable Minima
);
return true;
}
if (newEndpoint.getConfigurations().getEndpointMetadata().hasNewerVersionThan(existingMetadata)) {
if (newEndpoint.getConfigurations().getEndpointMetadataOrEmpty().hasNewerVersionThan(existingMetadata)) {
logger.debug(
() -> Strings.format("[%s] selected for persistence, because its version is higher", newEndpoint.getInferenceEntityId())
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -130,11 +131,10 @@ private static EndpointMetadata getEndpointMetadata(
ElasticInferenceServiceAuthorizationResponseEntity.AuthorizedEndpoint authorizedEndpoint
) {
try {
var kibanaConnectorName = authorizedEndpoint.displayName();
return new EndpointMetadata(
getHeuristics(authorizedEndpoint),
getInternalFields(authorizedEndpoint),
new EndpointMetadata.Display(kibanaConnectorName)
Optional.ofNullable(authorizedEndpoint.display()).orElse(EndpointMetadata.Display.EMPTY_INSTANCE)
);
} catch (IllegalArgumentException e) {
logger.atWarn()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class EndpointSchemaMigration {
* retrieving the latest preconfigured endpoints and updating existing ones to include any new fields included in the authorization
* response.
*/
public static final Long ENDPOINT_SCHEMA_VERSION = 0L;
public static final Long ENDPOINT_SCHEMA_VERSION = 1L;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚀


private EndpointSchemaMigration() {}
}
Loading
Loading