Skip to content

Commit 7f20d32

Browse files
committed
voyage ai
1 parent a143af1 commit 7f20d32

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/external/request/voyageai/VoyageAIEmbeddingsRequestEntity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
7272
static String convertToString(InputType inputType) {
7373
return switch (inputType) {
7474
case null -> null;
75-
case INGEST -> DOCUMENT;
76-
case SEARCH -> QUERY;
75+
case INGEST, INTERNAL_INGEST -> DOCUMENT;
76+
case SEARCH, INTERNAL_SEARCH -> QUERY;
7777
default -> {
7878
assert false : invalidInputTypeMessage(inputType);
7979
yield null;

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/voyageai/embeddings/VoyageAIEmbeddingsTaskSettings.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ public class VoyageAIEmbeddingsTaskSettings implements TaskSettings {
4141
public static final String NAME = "voyageai_embeddings_task_settings";
4242
public static final VoyageAIEmbeddingsTaskSettings EMPTY_SETTINGS = new VoyageAIEmbeddingsTaskSettings(null, null);
4343
static final String INPUT_TYPE = "input_type";
44-
static final EnumSet<InputType> VALID_REQUEST_VALUES = EnumSet.of(InputType.INGEST, InputType.SEARCH);
44+
static final EnumSet<InputType> VALID_REQUEST_VALUES = EnumSet.of(
45+
InputType.INGEST,
46+
InputType.SEARCH,
47+
InputType.INTERNAL_INGEST,
48+
InputType.INTERNAL_SEARCH
49+
);
4550

4651
public static VoyageAIEmbeddingsTaskSettings fromMap(Map<String, Object> map) {
4752
if (map == null || map.isEmpty()) {

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/external/request/voyageai/VoyageAIEmbeddingsRequestEntityTests.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,38 @@ public void testXContent_WritesNoOptionalFields_WhenTheyAreNotDefined() throws I
163163
{"input":["abc"],"model":"model"}"""));
164164
}
165165

166+
public void testXContent_InputTypeInternalSearch() throws IOException {
167+
var entity = new VoyageAIEmbeddingsRequestEntity(
168+
List.of("abc"),
169+
VoyageAIEmbeddingsServiceSettings.EMPTY_SETTINGS,
170+
new VoyageAIEmbeddingsTaskSettings(InputType.INTERNAL_SEARCH, Boolean.FALSE),
171+
"model"
172+
);
173+
174+
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
175+
entity.toXContent(builder, null);
176+
String xContentResult = Strings.toString(builder);
177+
178+
MatcherAssert.assertThat(xContentResult, is("""
179+
{"input":["abc"],"model":"model","input_type":"query"}"""));
180+
}
181+
182+
public void testXContent_InputTypeInternalIngest() throws IOException {
183+
var entity = new VoyageAIEmbeddingsRequestEntity(
184+
List.of("abc"),
185+
VoyageAIEmbeddingsServiceSettings.EMPTY_SETTINGS,
186+
new VoyageAIEmbeddingsTaskSettings(InputType.INTERNAL_INGEST, Boolean.FALSE),
187+
"model"
188+
);
189+
190+
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
191+
entity.toXContent(builder, null);
192+
String xContentResult = Strings.toString(builder);
193+
194+
MatcherAssert.assertThat(xContentResult, is("""
195+
{"input":["abc"],"model":"model","input_type":"document"}"""));
196+
}
197+
166198
public void testConvertToString_ThrowsAssertionFailure_WhenInputTypeIsUnspecified() {
167199
var thrownException = expectThrows(
168200
AssertionError.class,

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/voyageai/embeddings/VoyageAIEmbeddingsTaskSettingsTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@ public void testOf_UsesRequestTaskSettings_AndRequestInputType() {
181181
var overriddenTaskSettings = VoyageAIEmbeddingsTaskSettings.of(
182182
taskSettings,
183183
new VoyageAIEmbeddingsTaskSettings((InputType) null, null),
184-
InputType.INGEST
184+
InputType.INTERNAL_INGEST
185185
);
186186

187-
MatcherAssert.assertThat(overriddenTaskSettings, is(new VoyageAIEmbeddingsTaskSettings(InputType.INGEST, true)));
187+
MatcherAssert.assertThat(overriddenTaskSettings, is(new VoyageAIEmbeddingsTaskSettings(InputType.INTERNAL_INGEST, true)));
188188
}
189189

190190
@Override

0 commit comments

Comments
 (0)