refactor ml utils

This commit is contained in:
Fabian Freund
2025-07-25 22:41:44 +02:00
parent cd51ede15d
commit f803c59050
7 changed files with 24 additions and 4 deletions
@@ -3,13 +3,12 @@ import 'dart:async';
import 'package:collection/collection.dart';
import 'package:fast_equatable/fast_equatable.dart';
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
import 'package:flutter_mozilla_components/ml_utils.dart';
import 'package:nullability/nullability.dart';
import 'package:riverpod/riverpod.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:synchronized/synchronized.dart';
import 'package:weblibre/features/geckoview/features/tabs/domain/providers.dart';
import 'package:weblibre/features/geckoview/features/tabs/utils/embedding_text_processing.dart';
import 'package:weblibre/features/geckoview/features/tabs/utils/nearest_neighbor.dart';
import 'package:weblibre/features/user/domain/repositories/general_settings.dart';
import 'package:weblibre/utils/lru_cache.dart';
@@ -0,0 +1,2 @@
export 'src/utils/ml/embedding_text_processing.dart';
export 'src/utils/ml/nearest_neighbor.dart';
@@ -1,3 +1,9 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
import 'dart:math';
/// Calculates cosine similarity between two lists of floats
@@ -1,3 +1,9 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
/// Removes trailing domain-related text such as '... - Mail' or '... | News'
/// If there's not enough information remaining after, we keep the text as is
/// [text] tab title with potential domain information
@@ -1,5 +1,11 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
import 'package:collection/collection.dart';
import 'package:weblibre/features/geckoview/features/tabs/utils/cosine_similarity.dart';
import 'package:flutter_mozilla_components/src/utils/ml/cosine_similarity.dart';
List<String> findNearestNeighborsRecursive({
required Map<String, List<double>> embeddings,
@@ -8,6 +8,7 @@ environment:
flutter: '>=3.3.0'
dependencies:
collection: ^1.19.1
flutter:
sdk: flutter
rxdart: ^0.28.0
@@ -1,5 +1,5 @@
import 'package:flutter_mozilla_components/src/utils/ml/embedding_text_processing.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:weblibre/features/geckoview/features/tabs/utils/embedding_text_processing.dart';
void main() {
group('Text processing basic cases', () {