JavaScript · Serialization

Serialization

import * as usearch from 'usearch';import { Monolith } from 'usearch'; 3.0.0-rc.1 · 4c3e5023

Persist and restore an index through the filesystem, or through memory when checkpoints live in an object store. Loading creates a new index, its geometry read from the checkpoint, so the verb names where it lands:

index.on(executor).save('index.safegraphs');
const loaded = usearch.DenseIndex.loadRam('index.safegraphs', { executor, memoryDomains: [0, 1] });
const onDevice = usearch.DenseIndex.loadVram('index.safegraphs', { executor: devicePool, devices: [0] });
const viewed = usearch.DenseIndex.viewRam('index.safegraphs'); // Read-only, served from a memory mapping

const monolith = index.on(executor).saveBuffer(arena); // A Monolith viewing the arena
const restored = usearch.DenseIndex.loadRamBuffer(monolith, { executor });

valuesPerKey bounds a live handle rather than the file, so a load takes it among its config.

Read a checkpoint’s geometry before deciding how to open it:

const metadata = usearch.DenseIndex.metadataRead('index.safegraphs', { executor });
const fromMemory = usearch.DenseIndex.metadataReadBuffer(monolith, { executor });

API

Types

DenseLoadRamConfigWhere a checkpoint loaded into host memory lands.
usearch.ts:199 ↗
interface DenseLoadRamConfig

Fields

executor?ExecutorThe workers the read fans out over, one shard per thread; absent reads on the calling thread.
memoryDomains?number[]NUMA node IDs to place the parts on; absent spreads them over every node.
cpuClass?stringThe CPU class to dispatch as by its canonical name; absent dispatches as the machine.
valuesPerKey?numberEntries one key may carry, which no checkpoint records; absent is unbounded.
DenseLoadVramConfigWhere a checkpoint loaded into device memory lands.
usearch.ts:211 ↗
interface DenseLoadVramConfig

Fields

executor?ExecutorThe executor the upload runs on, one stream per device; absent uploads on the default stream.
devices?number[]CUDA ordinals to place the parts on; absent takes one free device.
gpuClass?stringThe GPU class to dispatch as by its canonical name; absent dispatches as the devices.
valuesPerKey?numberEntries one key may carry, which no checkpoint records; absent is unbounded.
DenseLoadRamBufferConfigWhere a monolith held in memory lands in host memory.
usearch.ts:223 ↗
interface DenseLoadRamBufferConfig

Fields

executor?ExecutorThe workers the copy fans out over; absent copies on the calling thread.
memoryDomains?number[]NUMA node IDs to place the shards on; the monolith lands whole on the first.
cpuClass?stringThe CPU class to dispatch as by its canonical name; absent dispatches as the machine.
valuesPerKey?numberEntries one key may carry, which no checkpoint records; absent is unbounded.
DenseLoadVramBufferConfigWhere a monolith held in memory lands in device memory.
usearch.ts:235 ↗
interface DenseLoadVramBufferConfig

Fields

executor?ExecutorThe executor the upload runs on, one stream per device; absent uploads on the default stream.
devices?number[]CUDA ordinals to place the shards on; the monolith lands whole on the first.
gpuClass?stringThe GPU class to dispatch as by its canonical name; absent dispatches as the devices.
valuesPerKey?numberEntries one key may carry, which no checkpoint records; absent is unbounded.
DenseViewNvmeConfigWhere a checkpoint served from NVMe drives is read from.
usearch.ts:247 ↗
interface DenseViewNvmeConfig

Fields

executor?ExecutorThe NVMe executor whose rings read the checkpoint's headers.
paths?string[]Devices or directories to serve the parts from; absent leaves each where its manifest points.
cpuClass?stringThe CPU class to dispatch as by its canonical name; absent dispatches as the machine.
DenseMetadataReadConfigThe workers a checkpoint's metadata is read on.
usearch.ts:257 ↗
interface DenseMetadataReadConfig

Fields

executor?ExecutorThe executor the read runs on; absent reads on the calling thread.
DenseMetadataReadBufferConfigThe workers a monolith's metadata is read on.
usearch.ts:263 ↗
interface DenseMetadataReadBufferConfig

Fields

executor?ExecutorThe executor the read runs on; absent reads on the calling thread.
DenseMetadataThe geometry and metric a checkpoint froze.
usearch.ts:274 ↗
interface DenseMetadata

Where it was written is never recorded, and neither is valuesPerKey, which bounds a live handle rather than the file - both stay the caller's to choose when loading.

Fields

metricDenseMetricThe metric the graph was built for.
quantizationScalarThe scalar type its vectors are stored as.
dimensionsnumberScalars per stored vector.
connectivitynumberConnections per node the graph was built with.
ClassMonolithOne serialized monolith, viewed inside the arena saveBuffer wrote it into.2
types.ts:611 ↗
class Monolith extends ArenaView

The bytes are what a checkpoint holds, so a service that keeps its indexes in an object store never touches the filesystem; loadRamBuffer and metadataReadBuffer read them back.

MonolithMade by saveBuffer, never directly.
types.ts:615 ↗
new Monolith(bytes: Uint8Array | null)
bytesThe monolith, valid until the arena's next call.
types.ts:621 ↗
readonly bytes: Uint8Array