Python · Serialization

Serialization

from usearch import Monolith, DenseMetadata 3.0.0-rc.1 · 4c3e5023

index.on(pool).save("index.safegraphs")
copy = DenseIndex.load_ram("index.safegraphs", executor=pool)  # A new, mutable index in host memory
view = DenseIndex.view_ram("index.safegraphs")  # Served in place, read-only

Loading creates a handle rather than filling one, its geometry read from the checkpoint’s own headers, and a cancelled or failed load creates none. The executor a load fans out over is its executor= keyword, and without one it reads on the calling thread. A view maps the file instead of copying it, so opening costs the headers alone, and every mutating verb on it raises ReadOnlyError. To learn a checkpoint’s shape without opening a shard, ask for its metadata, a DenseMetadata struct sequence whose fields are the geometry every empty constructor takes:

metadata = DenseIndex.metadata_read("index.safegraphs")
empty = DenseIndex.init_ram(
    metadata.dimensions, metadata.metric, metadata.quantization, connectivity=metadata.connectivity
)

Residency is never among those fields, because where the payload lives stays the caller’s choice.

save_buffer returns one monolith of every shard as a Monolith over the arena it is handed, and load_ram_buffer and metadata_read_buffer read one back from any buffer.

API

ClassMonolithThe bytes save_buffer wrote into an Arena, one (length,) run of 'B'.3
lib.pyi:535 ↗
class Monolith
__buffer__Host memory only; device memory raises DeviceError, a rewound arena UninitializedError.
lib.pyi:481 ↗

Inherited from _ArenaBuffer

def __buffer__(flags: int, /) -> memoryview

Python-only.

__len__Rows, or bytes of a Monolith.
lib.pyi:485 ↗

Inherited from _ArenaBuffer

def __len__() -> int

Python-only.

__cuda_array_interface__Version 3 of the CUDA Array Interface, present only over device memory.
lib.pyi:490 ↗

Inherited from _ArenaBuffer

__cuda_array_interface__: dict[str, Any]

Python-only.

ClassDenseMetadataThe geometry and metric a checkpoint froze.4
lib.pyi:1666 ↗
class DenseMetadata(structseq[Any], tuple[int, DenseMetric, Scalar, int])
dimensionsScalars per stored vector.
lib.pyi:1673 ↗
dimensions: int
metricThe DenseMetric the checkpoint scores with.
lib.pyi:1678 ↗
metric: DenseMetric
quantizationThe Scalar its vectors are stored and quantized into.
lib.pyi:1683 ↗
quantization: Scalar
connectivityConnections per node the graph was built with.
lib.pyi:1688 ↗
connectivity: int