# Serialization

> USearch for JavaScript

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:

```javascript
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:

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

`import * as usearch from 'usearch';`

`import { Monolith } from 'usearch';`

## DenseLoadRamConfig

Where a checkpoint loaded into host memory lands.

```typescript
interface DenseLoadRamConfig
```

- `executor?` `Executor`: The 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?` `string`: The CPU class to dispatch as by its canonical name; absent dispatches as the machine.
- `valuesPerKey?` `number`: Entries one key may carry, which no checkpoint records; absent is unbounded.

## DenseLoadVramConfig

Where a checkpoint loaded into device memory lands.

```typescript
interface DenseLoadVramConfig
```

- `executor?` `Executor`: The 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?` `string`: The GPU class to dispatch as by its canonical name; absent dispatches as the devices.
- `valuesPerKey?` `number`: Entries one key may carry, which no checkpoint records; absent is unbounded.

## DenseLoadRamBufferConfig

Where a monolith held in memory lands in host memory.

```typescript
interface DenseLoadRamBufferConfig
```

- `executor?` `Executor`: The 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?` `string`: The CPU class to dispatch as by its canonical name; absent dispatches as the machine.
- `valuesPerKey?` `number`: Entries one key may carry, which no checkpoint records; absent is unbounded.

## DenseLoadVramBufferConfig

Where a monolith held in memory lands in device memory.

```typescript
interface DenseLoadVramBufferConfig
```

- `executor?` `Executor`: The 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?` `string`: The GPU class to dispatch as by its canonical name; absent dispatches as the devices.
- `valuesPerKey?` `number`: Entries one key may carry, which no checkpoint records; absent is unbounded.

## DenseViewNvmeConfig

Where a checkpoint served from NVMe drives is read from.

```typescript
interface DenseViewNvmeConfig
```

- `executor?` `Executor`: The 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?` `string`: The CPU class to dispatch as by its canonical name; absent dispatches as the machine.

## DenseMetadataReadConfig

The workers a checkpoint's metadata is read on.

```typescript
interface DenseMetadataReadConfig
```

- `executor?` `Executor`: The executor the read runs on; absent reads on the calling thread.

## DenseMetadataReadBufferConfig

The workers a monolith's metadata is read on.

```typescript
interface DenseMetadataReadBufferConfig
```

- `executor?` `Executor`: The executor the read runs on; absent reads on the calling thread.

## DenseMetadata

The geometry and metric a checkpoint froze.

```typescript
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.

- `metric` `DenseMetric`: The metric the graph was built for.
- `quantization` `Scalar`: The scalar type its vectors are stored as.
- `dimensions` `number`: Scalars per stored vector.
- `connectivity` `number`: Connections per node the graph was built with.

## Monolith

One serialized monolith, viewed inside the arena [`saveBuffer`](https://www.unum.cloud/docs/usearch/javascript/metrics.md#saveBuffer) wrote it into.

```typescript
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`](https://www.unum.cloud/docs/usearch/javascript/metrics.md#loadRamBuffer) and [`metadataReadBuffer`](https://www.unum.cloud/docs/usearch/javascript/metrics.md#metadataReadBuffer) read them back.

## Monolith

Made by [`saveBuffer`](https://www.unum.cloud/docs/usearch/javascript/metrics.md#saveBuffer), never directly.

```typescript
new Monolith(bytes: Uint8Array | null)
```

## bytes

The monolith, valid until the arena's next call.

```typescript
readonly bytes: Uint8Array
```

