Skip to content

Commit f19f2ff

Browse files
committed
Add upper limit to Multilingual E5 Small as well
1 parent 224aabb commit f19f2ff

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elasticsearch/MultilingualE5SmallModel.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
public class MultilingualE5SmallModel extends ElasticsearchInternalModel {
1414

15+
// Ensure that inference endpoints based on E5 small don't go past its window size
16+
public static final int E5_SMALL_MAX_WINDOW_SIZE = 300;
17+
1518
public MultilingualE5SmallModel(
1619
String inferenceEntityId,
1720
TaskType taskType,
@@ -20,6 +23,15 @@ public MultilingualE5SmallModel(
2023
ChunkingSettings chunkingSettings
2124
) {
2225
super(inferenceEntityId, taskType, service, serviceSettings, chunkingSettings);
26+
if (chunkingSettings != null && chunkingSettings.maxChunkSize() != null) {
27+
if (chunkingSettings.maxChunkSize() > E5_SMALL_MAX_WINDOW_SIZE) throw new IllegalArgumentException(
28+
serviceSettings.modelId()
29+
+ " does not support chunk sizes larger than "
30+
+ E5_SMALL_MAX_WINDOW_SIZE
31+
+ ". Requested chunk size: "
32+
+ chunkingSettings.maxChunkSize()
33+
);
34+
}
2335
}
2436

2537
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.inference.services.elasticsearch;
9+
10+
import org.elasticsearch.inference.TaskType;
11+
import org.elasticsearch.test.ESTestCase;
12+
import org.elasticsearch.xpack.inference.chunking.SentenceBoundaryChunkingSettings;
13+
14+
import static org.hamcrest.Matchers.equalTo;
15+
16+
public class MultilingualE5SmallModelTests extends ESTestCase {
17+
18+
public void testHugeChunkingSettings() {
19+
Exception expectedException = expectThrows(
20+
IllegalArgumentException.class,
21+
() -> new MultilingualE5SmallModel(
22+
"foo",
23+
TaskType.TEXT_EMBEDDING,
24+
ElasticsearchInternalService.NAME,
25+
MultilingualE5SmallInternalServiceSettings.defaultEndpointSettings(randomBoolean()),
26+
new SentenceBoundaryChunkingSettings(10000, 0)
27+
)
28+
);
29+
30+
assertThat(
31+
expectedException.getMessage(),
32+
equalTo(".multilingual-e5-small does not support chunk sizes larger than 300. Requested chunk size: 10000")
33+
);
34+
}
35+
}

0 commit comments

Comments
 (0)