From 39b2df87276e74dc2ac4439f7ed66ccff7e49374 Mon Sep 17 00:00:00 2001 From: Michail Romaios <84708293+mromaios@users.noreply.github.com> Date: Tue, 21 Oct 2025 11:35:37 +0200 Subject: [PATCH] test(TestInferenceService): prevent negative embedding values (#136806) (cherry picked from commit 9d635175c5f5ac97949d37e0e12d3ac4f91ccafe) --- .../inference/mock/TestSparseInferenceServiceExtension.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x-pack/plugin/inference/qa/test-service-plugin/src/main/java/org/elasticsearch/xpack/inference/mock/TestSparseInferenceServiceExtension.java b/x-pack/plugin/inference/qa/test-service-plugin/src/main/java/org/elasticsearch/xpack/inference/mock/TestSparseInferenceServiceExtension.java index 59a53fae137ee..d8dd8b4e0e35b 100644 --- a/x-pack/plugin/inference/qa/test-service-plugin/src/main/java/org/elasticsearch/xpack/inference/mock/TestSparseInferenceServiceExtension.java +++ b/x-pack/plugin/inference/qa/test-service-plugin/src/main/java/org/elasticsearch/xpack/inference/mock/TestSparseInferenceServiceExtension.java @@ -191,7 +191,9 @@ protected ServiceSettings getServiceSettingsFromMap(Map serviceS private static float generateEmbedding(String input, int position) { // Ensure non-negative and non-zero values for features - return Math.abs(input.hashCode()) + 1 + position; + int hash = input.hashCode(); + int absHash = (hash == Integer.MIN_VALUE) ? Integer.MAX_VALUE : Math.abs(hash); + return absHash + 1.0f + position; } public static class Configuration {