Skip to content

Commit e1d9a15

Browse files
authored
test(TestInferenceService): prevent negative embedding values (#136806) (#136855)
(cherry picked from commit 9d63517)
1 parent 244507f commit e1d9a15

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

x-pack/plugin/inference/qa/test-service-plugin/src/main/java/org/elasticsearch/xpack/inference/mock/TestSparseInferenceServiceExtension.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ protected ServiceSettings getServiceSettingsFromMap(Map<String, Object> serviceS
191191

192192
private static float generateEmbedding(String input, int position) {
193193
// Ensure non-negative and non-zero values for features
194-
return Math.abs(input.hashCode()) + 1 + position;
194+
int hash = input.hashCode();
195+
int absHash = (hash == Integer.MIN_VALUE) ? Integer.MAX_VALUE : Math.abs(hash);
196+
return absHash + 1.0f + position;
195197
}
196198

197199
public static class Configuration {

0 commit comments

Comments
 (0)