embed method
Embeds a passage that will be stored and searched.
Implementation
@override
Future<List<double>> embed(String text) async {
embedded.add(text);
final v = List<double>.filled(dimensions, 0);
for (final w in text.toLowerCase().split(RegExp(r'[^a-z0-9]+'))) {
if (w.isEmpty) continue;
v[w.hashCode.abs() % dimensions] += 1;
}
final norm = math.sqrt(v.fold<double>(0, (a, b) => a + b * b));
return norm == 0 ? v : [for (final x in v) x / norm];
}