-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[EIS] Dense Text Embedding task type integration #129847
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
Merged
timgrein
merged 31 commits into
elastic:main
from
timgrein:eis-text-embedding-task-type
Jun 24, 2025
Merged
Changes from 9 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
f054dca
Add working dense text embeddings integration with default endpoint. …
timgrein 9ca7369
Merge branch 'main' into eis-text-embedding-task-type
timgrein 6584dab
Fix merge conflicts, compilation errors and test failures
timgrein 9d47176
Spotless apply
timgrein 3e8c70a
Add ElasticInferenceServiceDenseTextEmbeddingsRequestTests
timgrein 23e7595
Add ElasticInferenceServiceDenseTextEmbeddingsRequestEntityTests
timgrein 5af7516
Add "-v1" to multilingual-embed
timgrein fddfd9d
Add ElasticInferenceServiceDenseTextEmbeddingsServiceSettingsTests.java
timgrein 9b48dfb
Add dense text embedding test cases to ElasticInferenceServiceActionC…
timgrein dbdadbe
[CI] Auto commit changes from spotless
e2f872e
Add ElasticInferenceServiceDenseTextEmbeddingsResponseEntityTests
timgrein 485dd89
Merge remote-tracking branch 'origin/eis-text-embedding-task-type' in…
timgrein 172070a
Merge branch 'main' into eis-text-embedding-task-type
timgrein 6a35870
Fix compilation error after resolving merge conflict and spotlessAppl
timgrein a8b604b
Merge branch 'main' into eis-text-embedding-task-type
brendan-jugan-elastic 3b486b7
remove dimensions_set_by_user
brendan-jugan-elastic 6ffcc22
Merge branch 'main' into eis-text-embedding-task-type
brendan-jugan-elastic 3489a09
[CI] Auto commit changes from spotless
fb5dbc0
fix checkstyle
brendan-jugan-elastic 1dcbcab
fix checkstyle
brendan-jugan-elastic dc6f320
[CI] Auto commit changes from spotless
087d4e5
use ConstructingObjectParser for response parsing
brendan-jugan-elastic cd3e116
[CI] Auto commit changes from spotless
aa24341
Merge branch 'main' into eis-text-embedding-task-type
timgrein 7269c51
Some cleanup (removing unused vars etc.)
timgrein 220e208
Fix integration test
timgrein 27ca440
Do not set usage context, if it's null
timgrein b7d10b8
Pass through chunking settings and provide default for default endpoint
timgrein 3164c6c
Merge branch 'main' into eis-text-embedding-task-type
timgrein fc11815
After merge conflict resolution clean-up
timgrein 59f84a9
Merge branch 'main' into eis-text-embedding-task-type
timgrein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
...e/external/response/elastic/ElasticInferenceServiceDenseTextEmbeddingsResponseEntity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| /* | ||
| * 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.inference.external.response.elastic; | ||
|
|
||
| import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; | ||
| import org.elasticsearch.common.xcontent.XContentParserUtils; | ||
| import org.elasticsearch.xcontent.XContentFactory; | ||
| import org.elasticsearch.xcontent.XContentParser; | ||
| import org.elasticsearch.xcontent.XContentParserConfiguration; | ||
| import org.elasticsearch.xcontent.XContentType; | ||
| import org.elasticsearch.xpack.core.inference.results.TextEmbeddingFloatResults; | ||
| import org.elasticsearch.xpack.inference.external.http.HttpResult; | ||
| import org.elasticsearch.xpack.inference.external.request.Request; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken; | ||
| import static org.elasticsearch.common.xcontent.XContentParserUtils.parseList; | ||
| import static org.elasticsearch.xpack.inference.external.response.XContentUtils.moveToFirstToken; | ||
| import static org.elasticsearch.xpack.inference.external.response.XContentUtils.positionParserAtTokenAfterField; | ||
|
|
||
| public class ElasticInferenceServiceDenseTextEmbeddingsResponseEntity { | ||
|
|
||
| private static final String FAILED_TO_FIND_FIELD_TEMPLATE = | ||
| "Failed to find required field [%s] in Elastic Inference Service dense text embeddings response"; | ||
|
|
||
| /** | ||
| * Parses the Elastic Inference Service Dense Text Embeddings response. | ||
| * | ||
| * For a request like: | ||
| * | ||
| * <pre> | ||
| * <code> | ||
| * { | ||
| * "inputs": ["Embed this text", "Embed this text, too"] | ||
| * } | ||
| * </code> | ||
| * </pre> | ||
| * | ||
| * The response would look like: | ||
| * | ||
| * <pre> | ||
| * <code> | ||
| * { | ||
| * "data": [ | ||
| * [ | ||
| * 2.1259406, | ||
| * 1.7073475, | ||
| * 0.9020516 | ||
| * ], | ||
| * (...) | ||
| * ], | ||
| * "meta": { | ||
| * "usage": {...} | ||
| * } | ||
| * } | ||
| * </code> | ||
| * </pre> | ||
| */ | ||
|
|
||
| public static TextEmbeddingFloatResults fromResponse(Request request, HttpResult response) throws IOException { | ||
| var parserConfig = XContentParserConfiguration.EMPTY.withDeprecationHandler(LoggingDeprecationHandler.INSTANCE); | ||
|
|
||
| try (XContentParser jsonParser = XContentFactory.xContent(XContentType.JSON).createParser(parserConfig, response.body())) { | ||
|
||
| moveToFirstToken(jsonParser); | ||
|
|
||
| XContentParser.Token token = jsonParser.currentToken(); | ||
| ensureExpectedToken(XContentParser.Token.START_OBJECT, token, jsonParser); | ||
|
|
||
| positionParserAtTokenAfterField(jsonParser, "data", FAILED_TO_FIND_FIELD_TEMPLATE); | ||
|
|
||
| List<TextEmbeddingFloatResults.Embedding> parsedEmbeddings = parseList( | ||
| jsonParser, | ||
| (parser, index) -> ElasticInferenceServiceDenseTextEmbeddingsResponseEntity.parseTextEmbeddingObject(parser) | ||
| ); | ||
|
|
||
| if (parsedEmbeddings.isEmpty()) { | ||
| return new TextEmbeddingFloatResults(Collections.emptyList()); | ||
| } | ||
|
|
||
| return new TextEmbeddingFloatResults(parsedEmbeddings); | ||
| } | ||
| } | ||
|
|
||
| private static TextEmbeddingFloatResults.Embedding parseTextEmbeddingObject(XContentParser parser) throws IOException { | ||
| List<Float> embeddingValueList = parseList( | ||
| parser, | ||
| ElasticInferenceServiceDenseTextEmbeddingsResponseEntity::parseEmbeddingFloatValueList | ||
| ); | ||
| return TextEmbeddingFloatResults.Embedding.of(embeddingValueList); | ||
| } | ||
|
|
||
| private static float parseEmbeddingFloatValueList(XContentParser parser) throws IOException { | ||
| XContentParser.Token token = parser.currentToken(); | ||
| XContentParserUtils.ensureExpectedToken(XContentParser.Token.VALUE_NUMBER, token, parser); | ||
| return parser.floatValue(); | ||
| } | ||
|
|
||
| private ElasticInferenceServiceDenseTextEmbeddingsResponseEntity() {} | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 vaguely remembered Tim's thread on this a couple weeks ago, but should we revisit the response format? Looking at OpenAI, Alibaba, and Mixedbread as quick references, it looks like they return a list of objects. I don't have a strong preference, but just wanted to bring this up since we might be differing from others here and wanted to confirm that this is what we want.
Thanks!
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.
Answered in the thread