fromJson static method
Reconstruct a FlatIndex from toJson output. Throws on any structural mismatch so callers can fall back to a fresh build.
Implementation
static FlatIndex fromJson(Map<String, Object?> j) {
final dim = (j['dim'] as num).toInt();
final metric = VectorMetric.values.firstWhere(
(m) => m.name == j['metric'],
orElse: () => VectorMetric.l2sq,
);
final idx = FlatIndex(dim, defaultMetric: metric);
final ids = (j['ids'] as List).cast<Object?>();
final data = _decodeF32Slice(j['data'] as String);
if (data.length != ids.length * dim) {
throw FormatException(
'FlatIndex.fromJson: data length ${data.length} '
'!= ids ${ids.length} * dim $dim',
);
}
idx._data = data;
idx._ids.addAll(ids);
return idx;
}