> ## Documentation Index
> Fetch the complete documentation index at: https://docs.topk.io/llms.txt
> Use this file to discover all available pages before exploring further.

# topk-js/data

[topk-js](/sdk/topk-js/index) / data

## Functions

### binaryVector()

```ts theme={null}
function binaryVector(values: number[]): List;
```

Creates a [List](https://docs.topk.io/sdk/topk-js/data#List) type containing a binary vector. This function is an alias for [binaryList()](https://docs.topk.io/sdk/topk-js/data#binarylist).

Example:

```javascript theme={null}
import { binaryVector } from "topk-js/data";

binaryVector([0, 1, 1, 0])
```

**Parameters**

| Parameter | Type        |
| --------- | ----------- |
| `values`  | `number`\[] |

**Returns**

[`List`](/sdk/topk-js/Namespace.data#list)

***

### bytes()

```ts theme={null}
function bytes(buffer: number[] | Buffer<ArrayBufferLike>): Buffer;
```

Creates a [List](https://docs.topk.io/sdk/topk-js/data#List) type containing bytes data.

Example:

```javascript theme={null}
import { bytes } from "topk-js/data";

bytes([0, 1, 1, 0])
```

**Parameters**

| Parameter | Type                                        |
| --------- | ------------------------------------------- |
| `buffer`  | `number`\[] \| `Buffer`\<`ArrayBufferLike`> |

**Returns**

`Buffer`

***

### f16Vector()

```ts theme={null}
function f16Vector(values: number[]): List;
```

Creates a [List](https://docs.topk.io/sdk/topk-js/data#List) type containing a 16-bit float vector.

Example:

```javascript theme={null}
import { f16Vector } from "topk-js/data";

f16Vector([0.12, 0.67, 0.82, 0.53])
```

**Parameters**

| Parameter | Type        |
| --------- | ----------- |
| `values`  | `number`\[] |

**Returns**

[`List`](/sdk/topk-js/Namespace.data#list)

***

### f32List()

```ts theme={null}
function f32List(values: number[]): List;
```

Creates a [List](https://docs.topk.io/sdk/topk-js/data#List) type containing a list of 32-bit floating point numbers.

Example:

```javascript theme={null}
import { f32List } from "topk-js/data";

f32List([0.12, 0.67, 0.82, 0.53])
```

**Parameters**

| Parameter | Type        |
| --------- | ----------- |
| `values`  | `number`\[] |

**Returns**

[`List`](/sdk/topk-js/Namespace.data#list)

***

### f32SparseVector()

```ts theme={null}
function f32SparseVector(vector: Record<number, number>): SparseVector;
```

Creates a [SparseVector](https://docs.topk.io/sdk/topk-js/data#SparseVector) type containing a sparse vector of 32-bit floats. This function is an alias for [f32SparseList()](https://docs.topk.io/sdk/topk-js/data#f32sparselist).

Example:

```javascript theme={null}
import { f32SparseVector } from "topk-js/data";

f32SparseVector({0: 0.12, 6: 0.67, 17: 0.82, 97: 0.53})
```

**Parameters**

| Parameter | Type                          |
| --------- | ----------------------------- |
| `vector`  | `Record`\<`number`, `number`> |

**Returns**

[`SparseVector`](/sdk/topk-js/Namespace.data#sparsevector)

***

### f32Vector()

```ts theme={null}
function f32Vector(values: number[]): List;
```

Creates a [List](https://docs.topk.io/sdk/topk-js/data#List) type containing a 32-bit float vector. This function is an alias for [f32List()](https://docs.topk.io/sdk/topk-js/data#f32list).

Example:

```javascript theme={null}
import { f32Vector } from "topk-js/data";

f32Vector([0.12, 0.67, 0.82, 0.53])
```

**Parameters**

| Parameter | Type        |
| --------- | ----------- |
| `values`  | `number`\[] |

**Returns**

[`List`](/sdk/topk-js/Namespace.data#list)

***

### f64List()

```ts theme={null}
function f64List(values: number[]): List;
```

Creates a [List](https://docs.topk.io/sdk/topk-js/data#List) type containing a list of 64-bit floating point numbers.

Example:

```javascript theme={null}
import { f64List } from "topk-js/data";

f64List([0.12, 0.67, 0.82, 0.53])
```

**Parameters**

| Parameter | Type        |
| --------- | ----------- |
| `values`  | `number`\[] |

**Returns**

[`List`](/sdk/topk-js/Namespace.data#list)

***

### f8Vector()

```ts theme={null}
function f8Vector(values: number[]): List;
```

Creates a [List](https://docs.topk.io/sdk/topk-js/data#List) type containing an 8-bit float vector.

Example:

```javascript theme={null}
import { f8Vector } from "topk-js/data";

f8Vector([0.12, 0.67, 0.82, 0.53])
```

**Parameters**

| Parameter | Type        |
| --------- | ----------- |
| `values`  | `number`\[] |

**Returns**

[`List`](/sdk/topk-js/Namespace.data#list)

***

### i32List()

```ts theme={null}
function i32List(values: number[]): List;
```

Creates a [List](https://docs.topk.io/sdk/topk-js/data#List) type containing a list of 32-bit signed integers.

Example:

```javascript theme={null}
import { i32List } from "topk-js/data";

i32List([0, 1, 2, 3])
```

**Parameters**

| Parameter | Type        |
| --------- | ----------- |
| `values`  | `number`\[] |

**Returns**

[`List`](/sdk/topk-js/Namespace.data#list)

***

### i64List()

```ts theme={null}
function i64List(values: number[]): List;
```

Creates a [List](https://docs.topk.io/sdk/topk-js/data#List) type containing a list of 64-bit signed integers.

Example:

```javascript theme={null}
import { i64List } from "topk-js/data";

i64List([0, 1, 2, 3])
```

**Parameters**

| Parameter | Type        |
| --------- | ----------- |
| `values`  | `number`\[] |

**Returns**

[`List`](/sdk/topk-js/Namespace.data#list)

***

### i8Vector()

```ts theme={null}
function i8Vector(values: number[]): List;
```

Creates a [List](https://docs.topk.io/sdk/topk-js/data#List) type containing an 8-bit signed integer vector. This function is an alias for [i8List()](https://docs.topk.io/sdk/topk-js/data#i8list).

Example:

```javascript theme={null}
import { i8Vector } from "topk-js/data";

i8Vector([-128, 127, -1, 0, 1])
```

**Parameters**

| Parameter | Type        |
| --------- | ----------- |
| `values`  | `number`\[] |

**Returns**

[`List`](/sdk/topk-js/Namespace.data#list)

***

### matrix()

```ts theme={null}
function matrix(values: number[][], valueType?: MatrixValueType): Matrix;
```

Create a [Matrix](https://docs.topk.io/sdk/topk-js/data#Matrix) type containing matrix values.

The `values` parameter must be an array of number arrays. When passing an array of number arrays,
the optional `valueType` parameter specifies the matrix type.
If `valueType` is not provided, the matrix defaults to f32.

```javascript theme={null}
import { matrix } from "topk-js/data";

// Array of number arrays with explicit type
matrix([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]], "f32")

// Array of number arrays defaults to f32
matrix([[1.0, 2.0], [3.0, 4.0]])
```

**Parameters**

| Parameter    | Type                                                             |
| ------------ | ---------------------------------------------------------------- |
| `values`     | `number`\[]\[]                                                   |
| `valueType?` | [`MatrixValueType`](/sdk/topk-js/Namespace.data#matrixvaluetype) |

**Returns**

[`Matrix`](/sdk/topk-js/Namespace.data#matrix)

***

### stringList()

```ts theme={null}
function stringList(values: string[]): List;
```

Creates a [List](https://docs.topk.io/sdk/topk-js/data#List) type containing a list of strings.

Example:

```javascript theme={null}
import { stringList } from "topk-js/data";

stringList(["foo", "bar", "baz"])
```

**Parameters**

| Parameter | Type        |
| --------- | ----------- |
| `values`  | `string`\[] |

**Returns**

[`List`](/sdk/topk-js/Namespace.data#list)

***

### struct()

```ts theme={null}
function struct(fields: Record<string, any>): Struct;
```

Creates a [Struct](https://docs.topk.io/sdk/topk-js/data#Struct) type containing nested object values.

Example:

```javascript theme={null}
import { struct } from "topk-js/data";

struct({ author: "alice", year: 2024 })
```

**Parameters**

| Parameter | Type                       |
| --------- | -------------------------- |
| `fields`  | `Record`\<`string`, `any`> |

**Returns**

[`Struct`](/sdk/topk-js/Namespace.data#struct)

***

### u32List()

```ts theme={null}
function u32List(values: number[]): List;
```

Creates a [List](https://docs.topk.io/sdk/topk-js/data#List) type containing a list of 32-bit unsigned integers.

Example:

```javascript theme={null}
import { u32List } from "topk-js/data";

u32List([0, 1, 2, 3])
```

**Parameters**

| Parameter | Type        |
| --------- | ----------- |
| `values`  | `number`\[] |

**Returns**

[`List`](/sdk/topk-js/Namespace.data#list)

***

### u8SparseVector()

```ts theme={null}
function u8SparseVector(vector: Record<number, number>): SparseVector;
```

Creates a [SparseVector](https://docs.topk.io/sdk/topk-js/data#SparseVector) type containing a sparse vector of 8-bit unsigned integers. This function is an alias for [u8SparseList()](https://docs.topk.io/sdk/topk-js/data#u8sparselist).

Example:

```javascript theme={null}
import { u8SparseVector } from "topk-js/data";

u8SparseVector({0: 12, 6: 67, 17: 82, 97: 53})
```

**Parameters**

| Parameter | Type                          |
| --------- | ----------------------------- |
| `vector`  | `Record`\<`number`, `number`> |

**Returns**

[`SparseVector`](/sdk/topk-js/Namespace.data#sparsevector)

***

### u8Vector()

```ts theme={null}
function u8Vector(values: number[]): List;
```

Creates a [List](https://docs.topk.io/sdk/topk-js/data#List) type containing an 8-bit unsigned integer vector. This function is an alias for [u8List()](https://docs.topk.io/sdk/topk-js/data#u8list).

Example:

```javascript theme={null}
import { u8Vector } from "topk-js/data";

u8Vector([0, 255, 1, 2, 3])
```

**Parameters**

| Parameter | Type        |
| --------- | ----------- |
| `values`  | `number`\[] |

**Returns**

[`List`](/sdk/topk-js/Namespace.data#list)

## Classes

### List

**`Internal`**

Instances of the `List` class are used to represent lists of values in TopK.
Usually created using data constructors such as [`f32_list()`](#f32list), [`i32_list()`](#i32list), etc.

***

### Matrix

**`Internal`**

Instances of the `Matrix` class are used to represent matrices in TopK.
Usually created using data constructors such as [`matrix()`](#matrix).

***

### SparseVector

**`Internal`**

Instances of the `SparseVector` class are used to represent sparse vectors in TopK.
Usually created using data constructors such as [`f32_sparse_vector()`](#f32sparsevector) or [`u8_sparse_vector()`](#u8sparsevector).

***

### Struct

**`Internal`**

Instances of the `Struct` class are used to represent nested object values in TopK.
Usually created using the [`struct()`](https://docs.topk.io/sdk/topk-js/data#struct-2) helper.

## Type Aliases

### MatrixValueType

```ts theme={null}
type MatrixValueType = "f32" | "f16" | "f8" | "u8" | "i8";
```

Matrix element value type.
