embed method
Generate embeddings for the given input texts
input
- List of strings to generate embeddings for
Returns a list of embedding vectors or throws an LLMError
Implementation
@override
Future<List<List<double>>> embed(List<String> input) async {
if (config.apiKey.isEmpty) {
throw const AuthError('Missing Google API key');
}
try {
// For single input or small batches, use single endpoint
if (input.length == 1) {
final requestBody = _buildSingleEmbeddingRequest(input.first);
final responseData =
await client.postJson(embeddingEndpoint, requestBody);
return [_parseSingleEmbeddingResponse(responseData)];
} else {
// For multiple inputs, use batch endpoint
final requestBody = _buildBatchEmbeddingRequest(input);
final responseData =
await client.postJson(batchEmbeddingEndpoint, requestBody);
return _parseBatchEmbeddingResponse(responseData);
}
} on DioException catch (e) {
throw DioErrorHandler.handleDioError(e, 'Google');
} catch (e) {
throw GenericError('Unexpected error: $e');
}
}