> ## 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_sdk.data

## 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()`](#f32-list), [`i32_list()`](#i32-list), etc.

### 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()`](#f32-sparse-vector) or [`u8_sparse_vector()`](#u8-sparse-vector).

### Matrix

*Internal*

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

### Struct

*Internal*

Instances of the `Struct` class are used to represent nested object values in TopK.
Usually created using the [`struct()`](#struct) helper.

## Functions

### f8\_vector()

```python theme={null}
f8_vector(data: list[float]) -> List
```

Create a [List](/sdk/topk-py/data#List) type containing a 8-bit float vector.

Example:

```python theme={null}
from topk_sdk.data import f8_vector

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

**Parameters**

| Parameter | Type         |
| --------- | ------------ |
| `data`    | list\[float] |

**Returns**

[`List`](#list)

***

### f16\_vector()

```python theme={null}
f16_vector(data: list[float]) -> List
```

Create a [List](/sdk/topk-py/data#List) type containing a 16-bit float vector.

Example:

```python theme={null}
from topk_sdk.data import f16_vector

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

**Parameters**

| Parameter | Type         |
| --------- | ------------ |
| `data`    | list\[float] |

**Returns**

[`List`](#list)

***

### f32\_vector()

```python theme={null}
f32_vector(data: list[float]) -> List
```

Create a [List](/sdk/topk-py/data#List) type containing a 32-bit float vector. This function is an alias for [f32\_list()](/sdk/topk-py/data#f32-list).

Example:

```python theme={null}
from topk_sdk.data import f32_vector

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

**Parameters**

| Parameter | Type         |
| --------- | ------------ |
| `data`    | list\[float] |

**Returns**

[`List`](#list)

***

### u8\_vector()

```python theme={null}
u8_vector(data: list[int]) -> List
```

Create a [List](/sdk/topk-py/data#List) type containing an 8-bit unsigned integer vector. This function is an alias for [u8\_list()](/sdk/topk-py/data#u8-list).

Example:

```python theme={null}
from topk_sdk.data import u8_vector

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

**Parameters**

| Parameter | Type       |
| --------- | ---------- |
| `data`    | list\[int] |

**Returns**

[`List`](#list)

***

### i8\_vector()

```python theme={null}
i8_vector(data: list[int]) -> List
```

Create a [List](/sdk/topk-py/data#List) type containing an 8-bit signed integer vector.

Example:

```python theme={null}
from topk_sdk.data import i8_vector

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

**Parameters**

| Parameter | Type       |
| --------- | ---------- |
| `data`    | list\[int] |

**Returns**

[`List`](#list)

***

### binary\_vector()

```python theme={null}
binary_vector(data: list[int]) -> List
```

Create a [List](/sdk/topk-py/data#List) type containing a binary vector.

Example:

```python theme={null}
from topk_sdk.data import binary_vector

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

**Parameters**

| Parameter | Type       |
| --------- | ---------- |
| `data`    | list\[int] |

**Returns**

[`List`](#list)

***

### f32\_sparse\_vector()

```python theme={null}
f32_sparse_vector(data: dict[int, float]) -> SparseVector
```

Create a [SparseVector](/sdk/topk-py/data#SparseVector) type containing a 32-bit float sparse vector.

Example:

```python theme={null}
from topk_sdk.data import f32_sparse_vector

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

**Parameters**

| Parameter | Type              |
| --------- | ----------------- |
| `data`    | dict\[int, float] |

**Returns**

[`SparseVector`](#sparsevector)

***

### u8\_sparse\_vector()

```python theme={null}
u8_sparse_vector(data: dict[int, int]) -> SparseVector
```

Create a [SparseVector](/sdk/topk-py/data#SparseVector) type containing an 8-bit unsigned integer sparse vector.

Example:

```python theme={null}
from topk_sdk.data import u8_sparse_vector

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

**Parameters**

| Parameter | Type            |
| --------- | --------------- |
| `data`    | dict\[int, int] |

**Returns**

[`SparseVector`](#sparsevector)

***

### bytes()

```python theme={null}
bytes(data: list[int] | bytes) -> List
```

Create a [List](/sdk/topk-py/data#List) type containing bytes data.

Example:

```python theme={null}
from topk_sdk.data import bytes

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

**Parameters**

| Parameter | Type                |
| --------- | ------------------- |
| `data`    | list\[int] \| bytes |

**Returns**

[`List`](#list)

***

### u32\_list()

```python theme={null}
u32_list(data: list[int]) -> List
```

Create a [List](/sdk/topk-py/data#List) type containing a list of 32-bit unsigned integers.

Example:

```python theme={null}
from topk_sdk.data import u32_list

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

**Parameters**

| Parameter | Type       |
| --------- | ---------- |
| `data`    | list\[int] |

**Returns**

[`List`](#list)

***

### i32\_list()

```python theme={null}
i32_list(data: list[int]) -> List
```

Create a [List](/sdk/topk-py/data#List) type containing a list of 32-bit signed integers.

Example:

```python theme={null}
from topk_sdk.data import i32_list

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

**Parameters**

| Parameter | Type       |
| --------- | ---------- |
| `data`    | list\[int] |

**Returns**

[`List`](#list)

***

### i64\_list()

```python theme={null}
i64_list(data: list[int]) -> List
```

Create a [List](/sdk/topk-py/data#List) type containing a list of 64-bit signed integers.

Example:

```python theme={null}
from topk_sdk.data import i64_list

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

**Parameters**

| Parameter | Type       |
| --------- | ---------- |
| `data`    | list\[int] |

**Returns**

[`List`](#list)

***

### f32\_list()

```python theme={null}
f32_list(data: list[float]) -> List
```

Create a [List](/sdk/topk-py/data#List) type containing a list of 32-bit floating point numbers.

Example:

```python theme={null}
from topk_sdk.data import f32_list

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

**Parameters**

| Parameter | Type         |
| --------- | ------------ |
| `data`    | list\[float] |

**Returns**

[`List`](#list)

***

### f64\_list()

```python theme={null}
f64_list(data: list[float]) -> List
```

Create a [List](/sdk/topk-py/data#List) type containing a list of 64-bit floating point numbers.

Example:

```python theme={null}
from topk_sdk.data import f64_list

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

**Parameters**

| Parameter | Type         |
| --------- | ------------ |
| `data`    | list\[float] |

**Returns**

[`List`](#list)

***

### string\_list()

```python theme={null}
string_list(data: list[str]) -> List
```

Create a [List](/sdk/topk-py/data#List) type containing a list of strings.

Example:

```python theme={null}
from topk_sdk.data import string_list

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

**Parameters**

| Parameter | Type       |
| --------- | ---------- |
| `data`    | list\[str] |

**Returns**

[`List`](#list)

***

### struct()

```python theme={null}
struct(fields: dict[str, Any]) -> Struct
```

Create a [Struct](/sdk/topk-py/data#Struct) type containing nested object values.

Example:

```python theme={null}
from topk_sdk.data import struct

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

**Parameters**

| Parameter | Type            |
| --------- | --------------- |
| `fields`  | dict\[str, Any] |

**Returns**

[`Struct`](#struct)

***

### matrix()

```python theme={null}
matrix(values: list[list[float]] | list[list[int]] | numpy.ndarray, value_type: Optional[Literal['f32', 'f16', 'f8', 'u8', 'i8']] = None) -> Matrix
```

Create a [Matrix](/sdk/topk-py/data#Matrix) type containing matrix values.

The `values` parameter can be a list of lists or a [numpy array](https://numpy.org/doc/stable/reference/generated/numpy.array.html). When passing a numpy array,
the matrix type is inferred from the array's dtype (float32, float16, uint8, int8).
When passing a list of lists, the optional `value_type` parameter specifies the matrix type.
If `value_type` is not provided, the matrix defaults to f32.

```python theme={null}
from topk_sdk.data import matrix
import numpy as np

# List of lists with explicit type
matrix([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]], "f32")

# List of lists defaults to f32
matrix([[1.0, 2.0], [3.0, 4.0]])

# Numpy array infers type from dtype
matrix(np.array([[1.0, 2.0], [3.0, 4.0]], dtype=np.float16))
```

**Parameters**

| Parameter    | Type                                                      |
| ------------ | --------------------------------------------------------- |
| `values`     | list\[list\[float]] \| list\[list\[int]] \| numpy.ndarray |
| `value_type` | Optional\[Literal\['f32', 'f16', 'f8', 'u8', 'i8']]       |

**Returns**

[`Matrix`](#matrix)

***
