-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add usage stats for semantic_text fields #135262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 20 commits
2aa5ef7
7f4ca01
abfcf80
00fb4b2
2f05e03
fb71c57
421e77e
79e1d95
1922534
e286108
70fe35b
6e76c14
8d2796d
4d2c2fd
3656419
3d4f273
a9f7d79
d9dc8b8
6f3b519
809631b
632b7cb
c2e6dd3
4408342
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pr: 135262 | ||
| summary: Add usage stats for `semantic_text` fields | ||
| area: "Vector Search" | ||
| type: enhancement | ||
| issues: [] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 9181000 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| elastic_reranker_chunking_configuration,9180000 | ||
| inference_telemetry_added_semantic_text_stats,9181000 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,9 +7,12 @@ | |
|
|
||
| package org.elasticsearch.xpack.core.inference.usage; | ||
|
|
||
| import org.elasticsearch.TransportVersion; | ||
| import org.elasticsearch.common.io.stream.StreamInput; | ||
| import org.elasticsearch.common.io.stream.StreamOutput; | ||
| import org.elasticsearch.common.io.stream.Writeable; | ||
| import org.elasticsearch.core.Nullable; | ||
| import org.elasticsearch.features.NodeFeature; | ||
| import org.elasticsearch.inference.TaskType; | ||
| import org.elasticsearch.xcontent.ToXContentObject; | ||
| import org.elasticsearch.xcontent.XContentBuilder; | ||
|
|
@@ -19,28 +22,42 @@ | |
|
|
||
| public class ModelStats implements ToXContentObject, Writeable { | ||
|
|
||
| public static final NodeFeature SEMANTIC_TEXT_USAGE = new NodeFeature("inference.semantic_text_usage"); | ||
|
|
||
| static final TransportVersion INFERENCE_TELEMETRY_ADDED_SEMANTIC_TEXT_STATS = TransportVersion.fromName( | ||
| "inference_telemetry_added_semantic_text_stats" | ||
| ); | ||
|
|
||
| private final String service; | ||
| private final TaskType taskType; | ||
| private long count; | ||
| @Nullable | ||
| private final SemanticTextStats semanticTextStats; | ||
|
|
||
| public ModelStats(String service, TaskType taskType) { | ||
| this(service, taskType, 0L); | ||
| } | ||
|
|
||
| public ModelStats(String service, TaskType taskType, long count) { | ||
| this(service, taskType, count, taskType.isCompatibleWithSemanticText() ? new SemanticTextStats() : null); | ||
|
||
| } | ||
|
|
||
| public ModelStats(String service, TaskType taskType, long count, @Nullable SemanticTextStats semanticTextStats) { | ||
| this.service = service; | ||
| this.taskType = taskType; | ||
| this.count = count; | ||
| } | ||
|
|
||
| public ModelStats(ModelStats stats) { | ||
| this(stats.service, stats.taskType, stats.count); | ||
| this.semanticTextStats = semanticTextStats; | ||
| } | ||
|
|
||
| public ModelStats(StreamInput in) throws IOException { | ||
| this.service = in.readString(); | ||
| this.taskType = in.readEnum(TaskType.class); | ||
| this.count = in.readLong(); | ||
| if (in.getTransportVersion().supports(INFERENCE_TELEMETRY_ADDED_SEMANTIC_TEXT_STATS)) { | ||
| this.semanticTextStats = in.readOptional(SemanticTextStats::new); | ||
| } else { | ||
| this.semanticTextStats = null; | ||
| } | ||
| } | ||
|
|
||
| public void add() { | ||
|
|
@@ -59,6 +76,11 @@ public long count() { | |
| return count; | ||
| } | ||
|
|
||
| @Nullable | ||
| public SemanticTextStats semanticTextStats() { | ||
| return semanticTextStats; | ||
| } | ||
|
|
||
| @Override | ||
| public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
| builder.startObject(); | ||
|
|
@@ -71,25 +93,34 @@ public void addXContentFragment(XContentBuilder builder, Params params) throws I | |
| builder.field("service", service); | ||
| builder.field("task_type", taskType.name()); | ||
| builder.field("count", count); | ||
| if (semanticTextStats != null) { | ||
| builder.field("semantic_text", semanticTextStats); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { | ||
| out.writeString(service); | ||
| out.writeEnum(taskType); | ||
| out.writeLong(count); | ||
| if (out.getTransportVersion().supports(INFERENCE_TELEMETRY_ADDED_SEMANTIC_TEXT_STATS)) { | ||
| out.writeOptionalWriteable(semanticTextStats); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| ModelStats that = (ModelStats) o; | ||
| return count == that.count && Objects.equals(service, that.service) && taskType == that.taskType; | ||
| return count == that.count | ||
| && Objects.equals(service, that.service) | ||
| && taskType == that.taskType | ||
| && Objects.equals(semanticTextStats, that.semanticTextStats); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(service, taskType, count); | ||
| return Objects.hash(service, taskType, count, semanticTextStats); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.core.inference.usage; | ||
|
|
||
| import org.elasticsearch.common.io.stream.StreamInput; | ||
| import org.elasticsearch.common.io.stream.StreamOutput; | ||
| import org.elasticsearch.common.io.stream.Writeable; | ||
| import org.elasticsearch.xcontent.ToXContentObject; | ||
| import org.elasticsearch.xcontent.XContentBuilder; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Objects; | ||
|
|
||
| public class SemanticTextStats implements ToXContentObject, Writeable { | ||
|
|
||
| private static final String FIELD_COUNT = "field_count"; | ||
| private static final String INDICES_COUNT = "indices_count"; | ||
| private static final String INFERENCE_ID_COUNT = "inference_id_count"; | ||
|
|
||
| private long fieldCount; | ||
| private long indicesCount; | ||
| private long inferenceIdCount; | ||
|
|
||
| public SemanticTextStats() {} | ||
|
|
||
| public SemanticTextStats(long fieldCount, long indicesCount, long inferenceIdCount) { | ||
| this.fieldCount = fieldCount; | ||
| this.indicesCount = indicesCount; | ||
| this.inferenceIdCount = inferenceIdCount; | ||
| } | ||
|
|
||
| public SemanticTextStats(StreamInput in) throws IOException { | ||
| fieldCount = in.readVLong(); | ||
| indicesCount = in.readVLong(); | ||
| inferenceIdCount = in.readVLong(); | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { | ||
| out.writeVLong(fieldCount); | ||
| out.writeVLong(indicesCount); | ||
| out.writeVLong(inferenceIdCount); | ||
| } | ||
|
|
||
| @Override | ||
| public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
| builder.startObject(); | ||
| builder.field(FIELD_COUNT, fieldCount); | ||
| builder.field(INDICES_COUNT, indicesCount); | ||
| builder.field(INFERENCE_ID_COUNT, inferenceIdCount); | ||
| builder.endObject(); | ||
| return builder; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| SemanticTextStats that = (SemanticTextStats) o; | ||
| return fieldCount == that.fieldCount && indicesCount == that.indicesCount && inferenceIdCount == that.inferenceIdCount; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(fieldCount, indicesCount, inferenceIdCount); | ||
| } | ||
|
|
||
| public long getFieldCount() { | ||
| return fieldCount; | ||
| } | ||
|
|
||
| public long getIndicesCount() { | ||
| return indicesCount; | ||
| } | ||
|
|
||
| public long getInferenceIdCount() { | ||
| return inferenceIdCount; | ||
| } | ||
|
|
||
| public void addFieldCount(long fieldCount) { | ||
| this.fieldCount += fieldCount; | ||
| } | ||
|
|
||
| public void incIndicesCount() { | ||
| this.indicesCount++; | ||
| } | ||
|
|
||
| public void setInferenceIdCount(long inferenceIdCount) { | ||
| this.inferenceIdCount = inferenceIdCount; | ||
| } | ||
|
|
||
| public boolean isEmpty() { | ||
| return fieldCount == 0 && indicesCount == 0 && inferenceIdCount == 0; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally wouldn't modify
TaskTypedirectly to add this metadata. We only need it inTransportInferenceUsageAction, I would build a set of task types that need semantic text stats in that class.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 632b7cb