@@ -18,6 +18,7 @@ struct Spec {
18
18
struct Args {
19
19
client : Box < dyn LlmEmbeddingClient > ,
20
20
text : ResolvedOpArg ,
21
+ expected_output_dimension : usize ,
21
22
}
22
23
23
24
struct Executor {
@@ -28,7 +29,7 @@ struct Executor {
28
29
#[ async_trait]
29
30
impl SimpleFunctionExecutor for Executor {
30
31
fn behavior_version ( & self ) -> Option < u32 > {
31
- Some ( 1 )
32
+ self . args . client . behavior_version ( )
32
33
}
33
34
34
35
fn enable_cache ( & self ) -> bool {
@@ -48,6 +49,23 @@ impl SimpleFunctionExecutor for Executor {
48
49
. map ( |s| Cow :: Borrowed ( s. as_str ( ) ) ) ,
49
50
} ;
50
51
let embedding = self . args . client . embed_text ( req) . await ?;
52
+ if embedding. embedding . len ( ) != self . args . expected_output_dimension {
53
+ if self . spec . output_dimension . is_some ( ) {
54
+ api_bail ! (
55
+ "Expected output dimension {expected} but got {actual} from the embedding API. \
56
+ Consider setting `output_dimension` to {actual} or leave it unset to use the default.",
57
+ expected = self . args. expected_output_dimension,
58
+ actual = embedding. embedding. len( )
59
+ ) ;
60
+ } else {
61
+ bail ! (
62
+ "Expected output dimension {expected} but got {actual} from the embedding API. \
63
+ Consider setting `output_dimension` to {actual} as a workaround.",
64
+ expected = self . args. expected_output_dimension,
65
+ actual = embedding. embedding. len( )
66
+ )
67
+ }
68
+ }
51
69
Ok ( embedding. embedding . into ( ) )
52
70
}
53
71
}
@@ -87,7 +105,14 @@ impl SimpleFunctionFactoryBase for Factory {
87
105
dimension : Some ( output_dimension as usize ) ,
88
106
element_type : Box :: new ( BasicValueType :: Float32 ) ,
89
107
} ) ) ;
90
- Ok ( ( Args { client, text } , output_schema) )
108
+ Ok ( (
109
+ Args {
110
+ client,
111
+ text,
112
+ expected_output_dimension : output_dimension as usize ,
113
+ } ,
114
+ output_schema,
115
+ ) )
91
116
}
92
117
93
118
async fn build_executor (
0 commit comments