1010package org .elasticsearch .xpack .inference .external .response .voyageai ;
1111
1212import org .elasticsearch .common .xcontent .LoggingDeprecationHandler ;
13- import org .elasticsearch .core .Nullable ;
1413import org .elasticsearch .inference .InferenceServiceResults ;
1514import org .elasticsearch .xcontent .ConstructingObjectParser ;
1615import org .elasticsearch .xcontent .ParseField ;
3231import java .util .List ;
3332
3433import static org .elasticsearch .xcontent .ConstructingObjectParser .constructorArg ;
35- import static org .elasticsearch .xcontent .ConstructingObjectParser .optionalConstructorArg ;
3634import static org .elasticsearch .xpack .inference .services .voyageai .embeddings .VoyageAIEmbeddingType .toLowerCase ;
3735
3836public class VoyageAIEmbeddingsResponseEntity {
@@ -47,31 +45,29 @@ private static String supportedEmbeddingTypes() {
4745 return String .join (", " , validTypes );
4846 }
4947
50- record EmbeddingInt8Result (List <EmbeddingInt8ResultEntry > entries , String model , String object , @ Nullable Usage usage ) {
48+ record EmbeddingInt8Result (List <EmbeddingInt8ResultEntry > entries ) {
5149 @ SuppressWarnings ("unchecked" )
5250 public static final ConstructingObjectParser <EmbeddingInt8Result , Void > PARSER = new ConstructingObjectParser <>(
5351 EmbeddingInt8Result .class .getSimpleName (),
54- args -> new EmbeddingInt8Result ((List <EmbeddingInt8ResultEntry >) args [0 ], (String ) args [1 ], (String ) args [2 ], (Usage ) args [3 ])
52+ true ,
53+ args -> new EmbeddingInt8Result ((List <EmbeddingInt8ResultEntry >) args [0 ])
5554 );
5655
5756 static {
5857 PARSER .declareObjectArray (constructorArg (), EmbeddingInt8ResultEntry .PARSER ::apply , new ParseField ("data" ));
59- PARSER .declareString (constructorArg (), new ParseField ("model" ));
60- PARSER .declareString (constructorArg (), new ParseField ("object" ));
61- PARSER .declareObject (optionalConstructorArg (), Usage .PARSER ::apply , new ParseField ("usage" ));
6258 }
6359 }
6460
65- record EmbeddingInt8ResultEntry (String object , Integer index , List <Integer > embedding ) {
61+ record EmbeddingInt8ResultEntry (Integer index , List <Integer > embedding ) {
6662
6763 @ SuppressWarnings ("unchecked" )
6864 public static final ConstructingObjectParser <EmbeddingInt8ResultEntry , Void > PARSER = new ConstructingObjectParser <>(
6965 EmbeddingInt8ResultEntry .class .getSimpleName (),
70- args -> new EmbeddingInt8ResultEntry ((String ) args [0 ], (Integer ) args [1 ], (List <Integer >) args [2 ])
66+ true ,
67+ args -> new EmbeddingInt8ResultEntry ((Integer ) args [0 ], (List <Integer >) args [1 ])
7168 );
7269
7370 static {
74- PARSER .declareString (constructorArg (), new ParseField ("object" ));
7571 PARSER .declareInt (constructorArg (), new ParseField ("index" ));
7672 PARSER .declareIntArray (constructorArg (), new ParseField ("embedding" ));
7773 }
@@ -88,31 +84,29 @@ public InferenceByteEmbedding toInferenceByteEmbedding() {
8884 }
8985 }
9086
91- record EmbeddingFloatResult (List <EmbeddingFloatResultEntry > entries , String model , String object , @ Nullable Usage usage ) {
87+ record EmbeddingFloatResult (List <EmbeddingFloatResultEntry > entries ) {
9288 @ SuppressWarnings ("unchecked" )
9389 public static final ConstructingObjectParser <EmbeddingFloatResult , Void > PARSER = new ConstructingObjectParser <>(
9490 EmbeddingFloatResult .class .getSimpleName (),
95- args -> new EmbeddingFloatResult ((List <EmbeddingFloatResultEntry >) args [0 ], (String ) args [1 ], (String ) args [2 ], (Usage ) args [3 ])
91+ true ,
92+ args -> new EmbeddingFloatResult ((List <EmbeddingFloatResultEntry >) args [0 ])
9693 );
9794
9895 static {
9996 PARSER .declareObjectArray (constructorArg (), EmbeddingFloatResultEntry .PARSER ::apply , new ParseField ("data" ));
100- PARSER .declareString (constructorArg (), new ParseField ("model" ));
101- PARSER .declareString (constructorArg (), new ParseField ("object" ));
102- PARSER .declareObject (optionalConstructorArg (), Usage .PARSER ::apply , new ParseField ("usage" ));
10397 }
10498 }
10599
106- record EmbeddingFloatResultEntry (String object , Integer index , List <Float > embedding ) {
100+ record EmbeddingFloatResultEntry (Integer index , List <Float > embedding ) {
107101
108102 @ SuppressWarnings ("unchecked" )
109103 public static final ConstructingObjectParser <EmbeddingFloatResultEntry , Void > PARSER = new ConstructingObjectParser <>(
110104 EmbeddingFloatResultEntry .class .getSimpleName (),
111- args -> new EmbeddingFloatResultEntry ((String ) args [0 ], (Integer ) args [1 ], (List <Float >) args [2 ])
105+ true ,
106+ args -> new EmbeddingFloatResultEntry ((Integer ) args [0 ], (List <Float >) args [1 ])
112107 );
113108
114109 static {
115- PARSER .declareString (constructorArg (), new ParseField ("object" ));
116110 PARSER .declareInt (constructorArg (), new ParseField ("index" ));
117111 PARSER .declareFloatArray (constructorArg (), new ParseField ("embedding" ));
118112 }
@@ -122,18 +116,6 @@ public InferenceTextEmbeddingFloatResults.InferenceFloatEmbedding toInferenceFlo
122116 }
123117 }
124118
125- record Usage (Integer totalTokens ) {
126-
127- public static final ConstructingObjectParser <Usage , Void > PARSER = new ConstructingObjectParser <>(
128- Usage .class .getSimpleName (),
129- args -> new Usage ((Integer ) args [0 ])
130- );
131-
132- static {
133- PARSER .declareInt (constructorArg (), new ParseField ("total_tokens" ));
134- }
135- }
136-
137119 /**
138120 * Parses the VoyageAI json response.
139121 * For a request like:
0 commit comments