toJson method

Map<String, Object?> toJson()

Serialize the trained coarse quantizer + every populated cell.

Implementation

Map<String, Object?> toJson() {
  return {
    'dim': dim,
    'metric': defaultMetric.name,
    'nlist': nlist,
    'nprobe': nprobe,
    'trained': _trained,
    'n': _n,
    'centroids': _encodeF32Slice(
      _quantizer.centroids,
      0,
      _quantizer.centroids.length,
    ),
    'cells': [
      for (var c = 0; c < nlist; c++)
        {
          'count': _cellCounts[c],
          'ids': [for (final id in _cellIds[c]) id],
          'vecs': _encodeF32Slice(_cellVecs[c], 0, _cellCounts[c] * dim),
        },
    ],
  };
}