13
13
import org .elasticsearch .xcontent .XContentBuilder ;
14
14
import org .elasticsearch .xcontent .XContentFactory ;
15
15
import org .elasticsearch .xcontent .XContentType ;
16
+ import org .elasticsearch .xpack .inference .services .googlevertexai .embeddings .GoogleVertexAiEmbeddingsServiceSettings ;
16
17
import org .elasticsearch .xpack .inference .services .googlevertexai .embeddings .GoogleVertexAiEmbeddingsTaskSettings ;
17
18
18
19
import java .io .IOException ;
@@ -26,7 +27,8 @@ public void testToXContent_SingleEmbeddingRequest_WritesAllFields() throws IOExc
26
27
var entity = new GoogleVertexAiEmbeddingsRequestEntity (
27
28
List .of ("abc" ),
28
29
null ,
29
- new GoogleVertexAiEmbeddingsTaskSettings (true , InputType .CLUSTERING )
30
+ new GoogleVertexAiEmbeddingsTaskSettings (true , InputType .CLUSTERING ),
31
+ new GoogleVertexAiEmbeddingsServiceSettings ("location" , "projectId" , "modelId" , true , null , 10 , null , null )
30
32
);
31
33
32
34
XContentBuilder builder = XContentFactory .contentBuilder (XContentType .JSON );
@@ -42,17 +44,19 @@ public void testToXContent_SingleEmbeddingRequest_WritesAllFields() throws IOExc
42
44
}
43
45
],
44
46
"parameters": {
45
- "autoTruncate": true
47
+ "autoTruncate": true,
48
+ "outputDimensionality": 10
46
49
}
47
50
}
48
51
""" ));
49
52
}
50
53
51
- public void testToXContent_SingleEmbeddingRequest_DoesNotWriteAutoTruncationIfNotDefined () throws IOException {
54
+ public void testToXContent_SingleEmbeddingRequest_DoesNotWriteUndefinedFields () throws IOException {
52
55
var entity = new GoogleVertexAiEmbeddingsRequestEntity (
53
56
List .of ("abc" ),
54
57
InputType .INTERNAL_INGEST ,
55
- new GoogleVertexAiEmbeddingsTaskSettings (null , null )
58
+ new GoogleVertexAiEmbeddingsTaskSettings (null , null ),
59
+ new GoogleVertexAiEmbeddingsServiceSettings ("location" , "projectId" , "modelId" , false , null , null , null , null )
56
60
);
57
61
58
62
XContentBuilder builder = XContentFactory .contentBuilder (XContentType .JSON );
@@ -66,13 +70,45 @@ public void testToXContent_SingleEmbeddingRequest_DoesNotWriteAutoTruncationIfNo
66
70
"content": "abc",
67
71
"task_type": "RETRIEVAL_DOCUMENT"
68
72
}
69
- ]
73
+ ],
74
+ "parameters": {
75
+ }
76
+ }
77
+ """ ));
78
+ }
79
+
80
+ public void testToXContent_SingleEmbeddingRequest_DoesNotWriteUndefinedFields_DimensionsSetByUserFalse () throws IOException {
81
+ var entity = new GoogleVertexAiEmbeddingsRequestEntity (
82
+ List .of ("abc" ),
83
+ InputType .INTERNAL_INGEST ,
84
+ new GoogleVertexAiEmbeddingsTaskSettings (null , null ),
85
+ new GoogleVertexAiEmbeddingsServiceSettings ("location" , "projectId" , "modelId" , false , null , 10 , null , null )
86
+ );
87
+
88
+ XContentBuilder builder = XContentFactory .contentBuilder (XContentType .JSON );
89
+ entity .toXContent (builder , null );
90
+ String xContentResult = Strings .toString (builder );
91
+
92
+ assertThat (xContentResult , equalToIgnoringWhitespaceInJsonString ("""
93
+ {
94
+ "instances": [
95
+ {
96
+ "content": "abc",
97
+ "task_type": "RETRIEVAL_DOCUMENT"
98
+ }
99
+ ],
100
+ "parameters": {}
70
101
}
71
102
""" ));
72
103
}
73
104
74
105
public void testToXContent_SingleEmbeddingRequest_DoesNotWriteInputTypeIfNotDefined () throws IOException {
75
- var entity = new GoogleVertexAiEmbeddingsRequestEntity (List .of ("abc" ), null , new GoogleVertexAiEmbeddingsTaskSettings (false , null ));
106
+ var entity = new GoogleVertexAiEmbeddingsRequestEntity (
107
+ List .of ("abc" ),
108
+ null ,
109
+ new GoogleVertexAiEmbeddingsTaskSettings (false , null ),
110
+ new GoogleVertexAiEmbeddingsServiceSettings ("location" , "projectId" , "modelId" , false , null , null , null , null )
111
+ );
76
112
77
113
XContentBuilder builder = XContentFactory .contentBuilder (XContentType .JSON );
78
114
entity .toXContent (builder , null );
@@ -96,7 +132,8 @@ public void testToXContent_MultipleEmbeddingsRequest_WritesAllFields() throws IO
96
132
var entity = new GoogleVertexAiEmbeddingsRequestEntity (
97
133
List .of ("abc" , "def" ),
98
134
InputType .INTERNAL_SEARCH ,
99
- new GoogleVertexAiEmbeddingsTaskSettings (true , InputType .CLUSTERING )
135
+ new GoogleVertexAiEmbeddingsTaskSettings (true , InputType .CLUSTERING ),
136
+ new GoogleVertexAiEmbeddingsServiceSettings ("location" , "projectId" , "modelId" , true , null , 10 , null , null )
100
137
);
101
138
102
139
XContentBuilder builder = XContentFactory .contentBuilder (XContentType .JSON );
@@ -116,7 +153,8 @@ public void testToXContent_MultipleEmbeddingsRequest_WritesAllFields() throws IO
116
153
}
117
154
],
118
155
"parameters": {
119
- "autoTruncate": true
156
+ "autoTruncate": true,
157
+ "outputDimensionality": 10
120
158
}
121
159
}
122
160
""" ));
@@ -126,7 +164,8 @@ public void testToXContent_MultipleEmbeddingsRequest_DoesNotWriteInputTypeIfNotD
126
164
var entity = new GoogleVertexAiEmbeddingsRequestEntity (
127
165
List .of ("abc" , "def" ),
128
166
null ,
129
- new GoogleVertexAiEmbeddingsTaskSettings (true , null )
167
+ new GoogleVertexAiEmbeddingsTaskSettings (true , null ),
168
+ new GoogleVertexAiEmbeddingsServiceSettings ("location" , "projectId" , "modelId" , false , null , null , null , null )
130
169
);
131
170
132
171
XContentBuilder builder = XContentFactory .contentBuilder (XContentType .JSON );
@@ -154,7 +193,8 @@ public void testToXContent_MultipleEmbeddingsRequest_DoesNotWriteAutoTruncationI
154
193
var entity = new GoogleVertexAiEmbeddingsRequestEntity (
155
194
List .of ("abc" , "def" ),
156
195
null ,
157
- new GoogleVertexAiEmbeddingsTaskSettings (null , InputType .CLASSIFICATION )
196
+ new GoogleVertexAiEmbeddingsTaskSettings (null , InputType .CLASSIFICATION ),
197
+ new GoogleVertexAiEmbeddingsServiceSettings ("location" , "projectId" , "modelId" , false , null , null , null , null )
158
198
);
159
199
160
200
XContentBuilder builder = XContentFactory .contentBuilder (XContentType .JSON );
@@ -172,12 +212,14 @@ public void testToXContent_MultipleEmbeddingsRequest_DoesNotWriteAutoTruncationI
172
212
"content": "def",
173
213
"task_type": "CLASSIFICATION"
174
214
}
175
- ]
215
+ ],
216
+ "parameters": {
217
+ }
176
218
}
177
219
""" ));
178
220
}
179
221
180
222
public void testToXContent_ThrowsIfTaskSettingsIsNull () {
181
- expectThrows (NullPointerException .class , () -> new GoogleVertexAiEmbeddingsRequestEntity (List .of ("abc" , "def" ), null , null ));
223
+ expectThrows (NullPointerException .class , () -> new GoogleVertexAiEmbeddingsRequestEntity (List .of ("abc" , "def" ), null , null , null ));
182
224
}
183
225
}
0 commit comments