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> embed(String text) async { final response = await _dio.post>( _url, data: { 'input': text, 'model': 'nomic-embed-text-v1.5.Q4_K_M', }, ); final raw = (response.data!['data'] as List)[0]['embedding'] as List; return raw.map((e) => (e as num).toDouble()).toList(); } }