toJson method

Map<String, Object?> toJson()

Serialize coarse centroids + PQ codebooks + every populated cell.

Implementation

Map<String, Object?> toJson() {
  return {
    'dim': dim,
    'nlist': nlist,
    'nprobe': nprobe,
    'm': m,
    'trained': _trained,
    'n': _n,
    'coarseCentroids': _encodeF32Slice(
      _coarseQuantizer.centroids,
      0,
      _coarseQuantizer.centroids.length,
    ),
    'pqCentroids': _encodeF32Slice(
      _pq.centroids,
      0,
      _pq.centroids.length,
    ),
    'pqTrained': _pq.trained,
    'cells': [
      for (var c = 0; c < nlist; c++)
        {
          'count': _cellCounts[c],
          'ids': [for (final id in _cellIds[c]) id],
          'codes': base64.encode(
            _cellCodes[c].sublist(0, _cellCounts[c] * m),
          ),
        },
    ],
  };
}