Skip to content

Commit 852d157

Browse files
mromaioschrisparrinello
authored andcommitted
test(TestInferenceService): prevent negative embedding values (elastic#136806)
1 parent a45e635 commit 852d157

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
@@ -215,7 +215,9 @@ protected ServiceSettings getServiceSettingsFromMap(Map<String, Object> serviceS
215215

216216
private static float generateEmbedding(String input, int position) {
217217
// Ensure non-negative and non-zero values for features
218-
return Math.abs(input.hashCode()) + 1 + position;
218+
int hash = input.hashCode();
219+
int absHash = (hash == Integer.MIN_VALUE) ? Integer.MAX_VALUE : Math.abs(hash);
220+
return absHash + 1.0f + position;
219221
}
220222

221223
public static class Configuration {

0 commit comments

Comments
 (0)