embed method

  1. @override
Future<List<List<double>>> embed(
  1. List<String> input, {
  2. CancelToken? cancelToken,
})
override

Generate embeddings for the given input texts

input - List of strings to generate embeddings for cancelToken - Optional token to cancel the request

Returns a list of embedding vectors or throws an LLMError

Implementation

@override
Future<List<List<double>>> embed(
  List<String> input, {
  CancelToken? cancelToken,
}) async {
  if (config.baseUrl.isEmpty) {
    throw const InvalidRequestError('Missing Ollama base URL');
  }

  try {
    final requestBody = _buildRequestBody(input);
    final responseData = await client.postJson(
      embeddingEndpoint,
      requestBody,
      cancelToken: cancelToken,
    );
    return _parseResponse(responseData);
  } on DioException catch (e) {
    throw DioErrorHandler.handleDioError(e, 'Ollama');
  } catch (e) {
    throw GenericError('Unexpected error: $e');
  }
}