6565
6666public class TransportInferenceUsageActionTests extends ESTestCase {
6767
68+ private static final SemanticTextStats EMPTY_SEMANTIC_TEXT_STATS = new SemanticTextStats ();
69+
6870 private Client client ;
6971 private ModelRegistry modelRegistry ;
7072 private ClusterState clusterState ;
@@ -110,14 +112,14 @@ public void testGivenServices_NoInferenceFields() throws Exception {
110112 XContentSource response = executeAction ();
111113
112114 assertThat (response .getValue ("models" ), hasSize (8 ));
113- assertStats (response , 0 , new ModelStats ("_all" , TaskType .CHAT_COMPLETION , 0 , new SemanticTextStats () ));
114- assertStats (response , 1 , new ModelStats ("_all" , TaskType .COMPLETION , 0 , new SemanticTextStats () ));
115- assertStats (response , 2 , new ModelStats ("_all" , TaskType .RERANK , 0 , new SemanticTextStats () ));
116- assertStats (response , 3 , new ModelStats ("_all" , TaskType .SPARSE_EMBEDDING , 3 , new SemanticTextStats () ));
117- assertStats (response , 4 , new ModelStats ("_all" , TaskType .TEXT_EMBEDDING , 3 , new SemanticTextStats () ));
118- assertStats (response , 5 , new ModelStats ("hugging_face_elser" , TaskType .SPARSE_EMBEDDING , 2 , new SemanticTextStats () ));
119- assertStats (response , 6 , new ModelStats ("openai" , TaskType .SPARSE_EMBEDDING , 1 , new SemanticTextStats () ));
120- assertStats (response , 7 , new ModelStats ("openai" , TaskType .TEXT_EMBEDDING , 3 , new SemanticTextStats () ));
115+ assertStats (response , 0 , new ModelStats ("_all" , TaskType .CHAT_COMPLETION , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
116+ assertStats (response , 1 , new ModelStats ("_all" , TaskType .COMPLETION , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
117+ assertStats (response , 2 , new ModelStats ("_all" , TaskType .RERANK , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
118+ assertStats (response , 3 , new ModelStats ("_all" , TaskType .SPARSE_EMBEDDING , 3 , EMPTY_SEMANTIC_TEXT_STATS ));
119+ assertStats (response , 4 , new ModelStats ("_all" , TaskType .TEXT_EMBEDDING , 3 , EMPTY_SEMANTIC_TEXT_STATS ));
120+ assertStats (response , 5 , new ModelStats ("hugging_face_elser" , TaskType .SPARSE_EMBEDDING , 2 , EMPTY_SEMANTIC_TEXT_STATS ));
121+ assertStats (response , 6 , new ModelStats ("openai" , TaskType .SPARSE_EMBEDDING , 1 , EMPTY_SEMANTIC_TEXT_STATS ));
122+ assertStats (response , 7 , new ModelStats ("openai" , TaskType .TEXT_EMBEDDING , 3 , EMPTY_SEMANTIC_TEXT_STATS ));
121123 }
122124
123125 public void testGivenFieldRefersToMissingInferenceEndpoint () throws Exception {
@@ -127,11 +129,11 @@ public void testGivenFieldRefersToMissingInferenceEndpoint() throws Exception {
127129 XContentSource response = executeAction ();
128130
129131 assertThat (response .getValue ("models" ), hasSize (5 ));
130- assertStats (response , 0 , new ModelStats ("_all" , TaskType .CHAT_COMPLETION , 0 , new SemanticTextStats () ));
131- assertStats (response , 1 , new ModelStats ("_all" , TaskType .COMPLETION , 0 , new SemanticTextStats () ));
132- assertStats (response , 2 , new ModelStats ("_all" , TaskType .RERANK , 0 , new SemanticTextStats () ));
133- assertStats (response , 3 , new ModelStats ("_all" , TaskType .SPARSE_EMBEDDING , 0 , new SemanticTextStats () ));
134- assertStats (response , 4 , new ModelStats ("_all" , TaskType .TEXT_EMBEDDING , 0 , new SemanticTextStats () ));
132+ assertStats (response , 0 , new ModelStats ("_all" , TaskType .CHAT_COMPLETION , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
133+ assertStats (response , 1 , new ModelStats ("_all" , TaskType .COMPLETION , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
134+ assertStats (response , 2 , new ModelStats ("_all" , TaskType .RERANK , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
135+ assertStats (response , 3 , new ModelStats ("_all" , TaskType .SPARSE_EMBEDDING , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
136+ assertStats (response , 4 , new ModelStats ("_all" , TaskType .TEXT_EMBEDDING , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
135137 }
136138
137139 public void testGivenVariousServicesAndInferenceFields () throws Exception {
@@ -175,9 +177,9 @@ public void testGivenVariousServicesAndInferenceFields() throws Exception {
175177 XContentSource response = executeAction ();
176178
177179 assertThat (response .getValue ("models" ), hasSize (8 ));
178- assertStats (response , 0 , new ModelStats ("_all" , TaskType .CHAT_COMPLETION , 0 , new SemanticTextStats () ));
179- assertStats (response , 1 , new ModelStats ("_all" , TaskType .COMPLETION , 0 , new SemanticTextStats () ));
180- assertStats (response , 2 , new ModelStats ("_all" , TaskType .RERANK , 0 , new SemanticTextStats () ));
180+ assertStats (response , 0 , new ModelStats ("_all" , TaskType .CHAT_COMPLETION , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
181+ assertStats (response , 1 , new ModelStats ("_all" , TaskType .COMPLETION , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
182+ assertStats (response , 2 , new ModelStats ("_all" , TaskType .RERANK , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
181183 assertStats (response , 3 , new ModelStats ("_all" , TaskType .SPARSE_EMBEDDING , 2 , new SemanticTextStats (6 , 2 , 2 )));
182184 assertStats (response , 4 , new ModelStats ("_all" , TaskType .TEXT_EMBEDDING , 5 , new SemanticTextStats (9 , 3 , 4 )));
183185 assertStats (response , 5 , new ModelStats ("eis" , TaskType .TEXT_EMBEDDING , 3 , new SemanticTextStats (3 , 3 , 2 )));
@@ -220,9 +222,9 @@ public void testGivenServices_InferenceFieldsReferencingDefaultModels() throws E
220222 XContentSource response = executeAction ();
221223
222224 assertThat (response .getValue ("models" ), hasSize (12 ));
223- assertStats (response , 0 , new ModelStats ("_all" , TaskType .CHAT_COMPLETION , 0 , new SemanticTextStats () ));
224- assertStats (response , 1 , new ModelStats ("_all" , TaskType .COMPLETION , 0 , new SemanticTextStats () ));
225- assertStats (response , 2 , new ModelStats ("_all" , TaskType .RERANK , 0 , new SemanticTextStats () ));
225+ assertStats (response , 0 , new ModelStats ("_all" , TaskType .CHAT_COMPLETION , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
226+ assertStats (response , 1 , new ModelStats ("_all" , TaskType .COMPLETION , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
227+ assertStats (response , 2 , new ModelStats ("_all" , TaskType .RERANK , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
226228 assertStats (response , 3 , new ModelStats ("_all" , TaskType .SPARSE_EMBEDDING , 2 , new SemanticTextStats (4 , 2 , 2 )));
227229 assertStats (response , 4 , new ModelStats ("_all" , TaskType .TEXT_EMBEDDING , 3 , new SemanticTextStats (6 , 2 , 2 )));
228230 assertStats (response , 5 , new ModelStats ("_eis__model-id-001" , TaskType .TEXT_EMBEDDING , 2 , new SemanticTextStats (6 , 2 , 2 )));
@@ -231,7 +233,7 @@ public void testGivenServices_InferenceFieldsReferencingDefaultModels() throws E
231233 assertStats (response , 8 , new ModelStats ("eis" , TaskType .SPARSE_EMBEDDING , 1 , new SemanticTextStats (1 , 1 , 1 )));
232234 assertStats (response , 9 , new ModelStats ("eis" , TaskType .TEXT_EMBEDDING , 2 , new SemanticTextStats (6 , 2 , 2 )));
233235 assertStats (response , 10 , new ModelStats ("openai" , TaskType .SPARSE_EMBEDDING , 1 , new SemanticTextStats (3 , 2 , 1 )));
234- assertStats (response , 11 , new ModelStats ("openai" , TaskType .TEXT_EMBEDDING , 1 , new SemanticTextStats () ));
236+ assertStats (response , 11 , new ModelStats ("openai" , TaskType .TEXT_EMBEDDING , 1 , EMPTY_SEMANTIC_TEXT_STATS ));
235237 }
236238
237239 public void testGivenDefaultModelWithLinuxSuffix () throws Exception {
@@ -262,10 +264,10 @@ public void testGivenDefaultModelWithLinuxSuffix() throws Exception {
262264 XContentSource response = executeAction ();
263265
264266 assertThat (response .getValue ("models" ), hasSize (7 ));
265- assertStats (response , 0 , new ModelStats ("_all" , TaskType .CHAT_COMPLETION , 0 , new SemanticTextStats () ));
266- assertStats (response , 1 , new ModelStats ("_all" , TaskType .COMPLETION , 0 , new SemanticTextStats () ));
267- assertStats (response , 2 , new ModelStats ("_all" , TaskType .RERANK , 0 , new SemanticTextStats () ));
268- assertStats (response , 3 , new ModelStats ("_all" , TaskType .SPARSE_EMBEDDING , 0 , new SemanticTextStats () ));
267+ assertStats (response , 0 , new ModelStats ("_all" , TaskType .CHAT_COMPLETION , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
268+ assertStats (response , 1 , new ModelStats ("_all" , TaskType .COMPLETION , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
269+ assertStats (response , 2 , new ModelStats ("_all" , TaskType .RERANK , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
270+ assertStats (response , 3 , new ModelStats ("_all" , TaskType .SPARSE_EMBEDDING , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
269271 assertStats (response , 4 , new ModelStats ("_all" , TaskType .TEXT_EMBEDDING , 2 , new SemanticTextStats (6 , 2 , 2 )));
270272 assertStats (response , 5 , new ModelStats ("_eis__model-id-001" , TaskType .TEXT_EMBEDDING , 2 , new SemanticTextStats (6 , 2 , 2 )));
271273 assertStats (response , 6 , new ModelStats ("eis" , TaskType .TEXT_EMBEDDING , 2 , new SemanticTextStats (6 , 2 , 2 )));
@@ -299,10 +301,10 @@ public void testGivenSameDefaultModelWithAndWithoutLinuxSuffix() throws Exceptio
299301 XContentSource response = executeAction ();
300302
301303 assertThat (response .getValue ("models" ), hasSize (7 ));
302- assertStats (response , 0 , new ModelStats ("_all" , TaskType .CHAT_COMPLETION , 0 , new SemanticTextStats () ));
303- assertStats (response , 1 , new ModelStats ("_all" , TaskType .COMPLETION , 0 , new SemanticTextStats () ));
304- assertStats (response , 2 , new ModelStats ("_all" , TaskType .RERANK , 0 , new SemanticTextStats () ));
305- assertStats (response , 3 , new ModelStats ("_all" , TaskType .SPARSE_EMBEDDING , 0 , new SemanticTextStats () ));
304+ assertStats (response , 0 , new ModelStats ("_all" , TaskType .CHAT_COMPLETION , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
305+ assertStats (response , 1 , new ModelStats ("_all" , TaskType .COMPLETION , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
306+ assertStats (response , 2 , new ModelStats ("_all" , TaskType .RERANK , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
307+ assertStats (response , 3 , new ModelStats ("_all" , TaskType .SPARSE_EMBEDDING , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
306308 assertStats (response , 4 , new ModelStats ("_all" , TaskType .TEXT_EMBEDDING , 2 , new SemanticTextStats (6 , 2 , 2 )));
307309 assertStats (response , 5 , new ModelStats ("_eis__model-id-001" , TaskType .TEXT_EMBEDDING , 2 , new SemanticTextStats (6 , 2 , 2 )));
308310 assertStats (response , 6 , new ModelStats ("eis" , TaskType .TEXT_EMBEDDING , 2 , new SemanticTextStats (6 , 2 , 2 )));
@@ -315,10 +317,10 @@ public void testGivenExternalServiceModelIsNull() throws Exception {
315317 XContentSource response = executeAction ();
316318
317319 assertThat (response .getValue ("models" ), hasSize (6 ));
318- assertStats (response , 0 , new ModelStats ("_all" , TaskType .CHAT_COMPLETION , 0 , new SemanticTextStats () ));
319- assertStats (response , 1 , new ModelStats ("_all" , TaskType .COMPLETION , 0 , new SemanticTextStats () ));
320- assertStats (response , 2 , new ModelStats ("_all" , TaskType .RERANK , 0 , new SemanticTextStats () ));
321- assertStats (response , 3 , new ModelStats ("_all" , TaskType .SPARSE_EMBEDDING , 0 , new SemanticTextStats () ));
320+ assertStats (response , 0 , new ModelStats ("_all" , TaskType .CHAT_COMPLETION , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
321+ assertStats (response , 1 , new ModelStats ("_all" , TaskType .COMPLETION , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
322+ assertStats (response , 2 , new ModelStats ("_all" , TaskType .RERANK , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
323+ assertStats (response , 3 , new ModelStats ("_all" , TaskType .SPARSE_EMBEDDING , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
322324 assertStats (response , 4 , new ModelStats ("_all" , TaskType .TEXT_EMBEDDING , 1 , new SemanticTextStats (1 , 1 , 1 )));
323325 assertStats (response , 5 , new ModelStats ("openai" , TaskType .TEXT_EMBEDDING , 1 , new SemanticTextStats (1 , 1 , 1 )));
324326 }
@@ -347,10 +349,10 @@ public void testGivenDuplicateServices() throws Exception {
347349 XContentSource response = executeAction ();
348350
349351 assertThat (response .getValue ("models" ), hasSize (6 ));
350- assertStats (response , 0 , new ModelStats ("_all" , TaskType .CHAT_COMPLETION , 0 , new SemanticTextStats () ));
351- assertStats (response , 1 , new ModelStats ("_all" , TaskType .COMPLETION , 0 , new SemanticTextStats () ));
352- assertStats (response , 2 , new ModelStats ("_all" , TaskType .RERANK , 0 , new SemanticTextStats () ));
353- assertStats (response , 3 , new ModelStats ("_all" , TaskType .SPARSE_EMBEDDING , 0 , new SemanticTextStats () ));
352+ assertStats (response , 0 , new ModelStats ("_all" , TaskType .CHAT_COMPLETION , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
353+ assertStats (response , 1 , new ModelStats ("_all" , TaskType .COMPLETION , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
354+ assertStats (response , 2 , new ModelStats ("_all" , TaskType .RERANK , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
355+ assertStats (response , 3 , new ModelStats ("_all" , TaskType .SPARSE_EMBEDDING , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
354356 assertStats (response , 4 , new ModelStats ("_all" , TaskType .TEXT_EMBEDDING , 2 , new SemanticTextStats (5 , 2 , 2 )));
355357 assertStats (response , 5 , new ModelStats ("openai" , TaskType .TEXT_EMBEDDING , 2 , new SemanticTextStats (5 , 2 , 2 )));
356358 }
@@ -381,10 +383,10 @@ public void testShouldExcludeSystemIndexFields() throws Exception {
381383 XContentSource response = executeAction ();
382384
383385 assertThat (response .getValue ("models" ), hasSize (7 ));
384- assertStats (response , 0 , new ModelStats ("_all" , TaskType .CHAT_COMPLETION , 0 , new SemanticTextStats () ));
385- assertStats (response , 1 , new ModelStats ("_all" , TaskType .COMPLETION , 0 , new SemanticTextStats () ));
386- assertStats (response , 2 , new ModelStats ("_all" , TaskType .RERANK , 0 , new SemanticTextStats () ));
387- assertStats (response , 3 , new ModelStats ("_all" , TaskType .SPARSE_EMBEDDING , 0 , new SemanticTextStats () ));
386+ assertStats (response , 0 , new ModelStats ("_all" , TaskType .CHAT_COMPLETION , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
387+ assertStats (response , 1 , new ModelStats ("_all" , TaskType .COMPLETION , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
388+ assertStats (response , 2 , new ModelStats ("_all" , TaskType .RERANK , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
389+ assertStats (response , 3 , new ModelStats ("_all" , TaskType .SPARSE_EMBEDDING , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
388390 assertStats (response , 4 , new ModelStats ("_all" , TaskType .TEXT_EMBEDDING , 2 , new SemanticTextStats (2 , 1 , 2 )));
389391 assertStats (response , 5 , new ModelStats ("eis" , TaskType .TEXT_EMBEDDING , 1 , new SemanticTextStats (1 , 1 , 1 )));
390392 assertStats (response , 6 , new ModelStats ("openai" , TaskType .TEXT_EMBEDDING , 1 , new SemanticTextStats (1 , 1 , 1 )));
@@ -416,10 +418,10 @@ public void testShouldExcludeHiddenIndexFields() throws Exception {
416418 XContentSource response = executeAction ();
417419
418420 assertThat (response .getValue ("models" ), hasSize (7 ));
419- assertStats (response , 0 , new ModelStats ("_all" , TaskType .CHAT_COMPLETION , 0 , new SemanticTextStats () ));
420- assertStats (response , 1 , new ModelStats ("_all" , TaskType .COMPLETION , 0 , new SemanticTextStats () ));
421- assertStats (response , 2 , new ModelStats ("_all" , TaskType .RERANK , 0 , new SemanticTextStats () ));
422- assertStats (response , 3 , new ModelStats ("_all" , TaskType .SPARSE_EMBEDDING , 0 , new SemanticTextStats () ));
421+ assertStats (response , 0 , new ModelStats ("_all" , TaskType .CHAT_COMPLETION , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
422+ assertStats (response , 1 , new ModelStats ("_all" , TaskType .COMPLETION , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
423+ assertStats (response , 2 , new ModelStats ("_all" , TaskType .RERANK , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
424+ assertStats (response , 3 , new ModelStats ("_all" , TaskType .SPARSE_EMBEDDING , 0 , EMPTY_SEMANTIC_TEXT_STATS ));
423425 assertStats (response , 4 , new ModelStats ("_all" , TaskType .TEXT_EMBEDDING , 2 , new SemanticTextStats (2 , 1 , 2 )));
424426 assertStats (response , 5 , new ModelStats ("eis" , TaskType .TEXT_EMBEDDING , 1 , new SemanticTextStats (1 , 1 , 1 )));
425427 assertStats (response , 6 , new ModelStats ("openai" , TaskType .TEXT_EMBEDDING , 1 , new SemanticTextStats (1 , 1 , 1 )));
0 commit comments