@@ -30,32 +30,37 @@ public ExternalEmbeddingGenerator(
3030 _embeddingGeneratorConfig = embeddingGeneratorConfig ;
3131
3232 _log = DefaultLogger < ExternalEmbeddingGenerator > . Instance ;
33+
34+ ScanModel ( ) ;
3335 }
3436
35- private async Task GetDenseVectorSizeAsync ( )
37+ private void ScanModel ( )
3638 {
3739 var client = _httpClientFactory . CreateClient ( ) ;
3840 //do a post request to the model to get the dense vector size
39- var body = new { modelName = _embeddingGeneratorConfig . ModelName } ;
41+ var body = new DimensionInput ( _embeddingGeneratorConfig . ModelName ) ;
4042 var request = new HttpRequestMessage ( HttpMethod . Post , $ "{ _embeddingGeneratorConfig . Address . TrimEnd ( '/' ) } /dimensions")
4143 {
4244 Content = new StringContent ( JsonSerializer . Serialize ( body ) , Encoding . UTF8 , "application/json" )
4345 } ;
44- var response = await client . GetAsync ( $ "{ _embeddingGeneratorConfig . Address . TrimEnd ( '/' ) } /dimensions") ;
46+
47+ var response = client . Send ( request ) ;
48+
4549 //TODO: Proper error handling
4650 if ( ! response . IsSuccessStatusCode )
4751 {
48- throw new Exception ( "Failed to get dense vector size " ) ;
52+ throw new Exception ( "Failed to get dimensions " ) ;
4953 }
50- var responseStream = await response . Content . ReadAsStreamAsync ( ) ;
51- var embeddingInfo = await JsonSerializer . DeserializeAsync < EmbeddingInfo > ( responseStream ) ;
52- VectorSize = embeddingInfo . dimension ;
54+ var responseStream = response . Content . ReadAsStream ( ) ;
55+ var dimensionResult = JsonSerializer . Deserialize < DimensionResult > ( responseStream ) ;
56+ this . VectorSize = dimensionResult . dimension ;
57+ this . MaxTokens = dimensionResult . maxSequenceLength ;
5358 }
5459
5560 /// <inheritdoc />
56- public int MaxTokens { get ; private set ; } = 4096 ;
61+ public int MaxTokens { get ; private set ; } = 384 ;
5762
58- public int VectorSize { get ; private set ; }
63+ public int VectorSize { get ; private set ; } = 768 ;
5964
6065 /// <inheritdoc />
6166 public int CountTokens ( string text )
@@ -118,6 +123,8 @@ public async Task<Embedding> GenerateEmbeddingAsync(
118123 }
119124
120125 public record SentenceInput ( List < string > sentences , string modelName ) ;
126+ public record DimensionInput ( string modelName ) ;
127+ public record DimensionResult ( string model , int maxSequenceLength , int dimension ) ;
121128 public record EmbeddingModel ( List < double [ ] > embeddings , string model ) ;
122129
123130 private record EmbeddingInfo ( string model , int dimension ) ;
0 commit comments