@@ -18,6 +18,7 @@ struct Spec {
1818struct Args {
1919 client : Box < dyn LlmEmbeddingClient > ,
2020 text : ResolvedOpArg ,
21+ expected_output_dimension : usize ,
2122}
2223
2324struct Executor {
@@ -28,7 +29,7 @@ struct Executor {
2829#[ async_trait]
2930impl SimpleFunctionExecutor for Executor {
3031 fn behavior_version ( & self ) -> Option < u32 > {
31- Some ( 1 )
32+ self . args . client . behavior_version ( )
3233 }
3334
3435 fn enable_cache ( & self ) -> bool {
@@ -48,6 +49,23 @@ impl SimpleFunctionExecutor for Executor {
4849 . map ( |s| Cow :: Borrowed ( s. as_str ( ) ) ) ,
4950 } ;
5051 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+ }
5169 Ok ( embedding. embedding . into ( ) )
5270 }
5371}
@@ -87,7 +105,14 @@ impl SimpleFunctionFactoryBase for Factory {
87105 dimension : Some ( output_dimension as usize ) ,
88106 element_type : Box :: new ( BasicValueType :: Float32 ) ,
89107 } ) ) ;
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+ ) )
91116 }
92117
93118 async fn build_executor (
0 commit comments