-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[Inference API] Propagate product use case http header to EIS #124025
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 23 commits
ab712dd
b617e0a
2e8231a
ca79955
2c12778
cc52207
a1da2f6
a6e9297
82ce713
e5c5933
634aaef
0302468
ef35491
3abe303
517c943
0bc06df
7a515bc
cf55cb5
8d44488
139f7a5
280f0cf
0a3b0a0
cd1beee
1c0a3c4
d6a7bb9
89a973a
2f881e0
e5153a1
149a094
69687d5
bc1a74f
8ab08f9
e34359c
a7d0f27
e494a39
5b90efb
418241f
9163207
5d4b92f
fa47c8c
0515e1a
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: 124025 | ||
| summary: "[Inference API] Propagate product use case http header to EIS" | ||
| area: Machine Learning | ||
| type: enhancement | ||
| issues: [] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| 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.ToXContent; | ||
| import org.elasticsearch.xcontent.XContentBuilder; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * Record for storing context alongside an inference request, typically used for metadata. | ||
| * This is mainly used to pass along inference context on the transport layer without relying on {@link org.elasticsearch.common.util.concurrent.ThreadContext}, | ||
| * which depending on the internal {@link org.elasticsearch.client.internal.Client} throws away parts of the context, when passed along the transport layer. | ||
| * | ||
| * @param productUseCase - for now mainly interesting to Elastic Inference Service | ||
timgrein marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| public record InferenceContext(String productUseCase) implements Writeable, ToXContent { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should verify non-null so the transport layer doesn't hate us for not using public InferenceContext {
Objects.requireNonNull(productUseCase);
}
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, adjusted with Ensure that productUseCase field in InferenceContext is non-null |
||
|
|
||
| public InferenceContext(StreamInput in) throws IOException { | ||
| this(in.readString()); | ||
| } | ||
|
|
||
| public static InferenceContext empty() { | ||
|
||
| return new InferenceContext(""); | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { | ||
| out.writeString(productUseCase); | ||
| } | ||
|
|
||
| @Override | ||
| public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
| builder.startObject(); | ||
|
|
||
| builder.field("product_use_case", productUseCase); | ||
|
|
||
| builder.endObject(); | ||
|
|
||
| return builder; | ||
| } | ||
| } | ||
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.
Just a reminder, if we do want to backport to 8.19 we'll need a
TransportVersionfor 8.xfor example:
COHERE_BIT_EMBEDDING_TYPE_SUPPORT_ADDED_BACKPORT_8_XWe'll also need to change the
onAfter()check. Here's an example:https://github.com/elastic/elasticsearch/blob/main/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/cohere/embeddings/CohereEmbeddingType.java#L131-L132
The code in 8.x will look different too (since the 9.x transport version won't exist): https://github.com/elastic/elasticsearch/blob/8.x/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/cohere/embeddings/CohereEmbeddingType.java#L131
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.
Thanks for the explanation and the code examples.
Adjusted with Add TransportVersion for 8_X.
In the backport I would then need to replace
TransportVersions.INFERENCE_CONTEXTwithTransportVersions.INFERENCE_CONTEXT_8_X, right?