Files
trainhub-flutter/lib/domain/services/embedding_service.dart
Kazimierz Ciołek 0c9eb8878d
Some checks failed
Build Linux App / build (push) Failing after 1m33s
Refactoring
2026-02-23 10:02:23 -05:00

32 lines
910 B
Dart

import 'package:dio/dio.dart';
/// Wraps the Nomic embedding server (llama.cpp, port 8081).
/// Returns a 768-dimensional float vector for any input text.
class EmbeddingService {
final _dio = Dio(
BaseOptions(
connectTimeout: const Duration(seconds: 10),
receiveTimeout: const Duration(seconds: 60),
),
);
static const _url = 'http://localhost:8081/v1/embeddings';
/// Returns the embedding vector for [text].
/// Throws a [DioException] if the Nomic server is unreachable.
Future<List<double>> embed(String text) async {
final response = await _dio.post<Map<String, dynamic>>(
_url,
data: {
'input': text,
'model': 'nomic-embed-text-v1.5.Q4_K_M',
},
);
final raw =
(response.data!['data'] as List<dynamic>)[0]['embedding']
as List<dynamic>;
return raw.map((e) => (e as num).toDouble()).toList();
}
}