Skip to main content

Classes

FieldIndex

Internal Instances of the FieldIndex class represents a field index created by vector_index, keyword_index, or semantic_index functions.

FieldSpec

Internal Instances of the FieldSpec class represents a field specification created by text, int, float, bool, f32_vector, u8_vector, i8_vector, binary_vector, f32_sparse_vector, u8_sparse_vector, bytes, or list functions. Methods

required()

required(self) -> FieldSpec
Mark a field as required. All fields are optional by default. Example:
from topk_sdk.schema import text

client.collections().create("books", schema={
    "title": text().required()
})
Returns FieldSpec

optional()

optional(self) -> FieldSpec
Returns FieldSpec

index()

index(self, index: FieldIndex) -> FieldSpec
Create an index on a field. Example:
from topk_sdk.schema import text, keyword_index

client.collections().create("books", schema={
    "title": text().index(keyword_index())
})
Parameters
ParameterType
indexFieldIndex
Returns FieldSpec

Functions

text()

text() -> FieldSpec
Create a FieldSpec type for text values. Example:
from topk_sdk.schema import text

client.collections().create("books", schema={
    "title": text()
})
Returns FieldSpec

int()

int() -> FieldSpec
Create an integer field specification. Returns FieldSpec

float()

float() -> FieldSpec
Create a FieldSpec type for float values. Example:
from topk_sdk.schema import float

client.collections().create("books", schema={
    "price": float()
})
Returns FieldSpec

bool()

bool() -> FieldSpec
Create a FieldSpec type for bool values. Example:
from topk_sdk.schema import bool

client.collections().create("books", schema={
    "is_published": bool()
})
Returns FieldSpec

f32_vector()

f32_vector(dimension: int) -> FieldSpec
Create a FieldSpec type for f32_vector values. Example:
from topk_sdk.schema import f32_vector

client.collections().create("books", schema={
    "title_embedding": f32_vector(dimension=1536)
})
Parameters
ParameterType
dimensionint
Returns FieldSpec

u8_vector()

u8_vector(dimension: int) -> FieldSpec
Create a FieldSpec type for u8_vector values. Example:
from topk_sdk.schema import u8_vector

client.collections().create("books", schema={
    "title_embedding": u8_vector(dimension=1536)
})
Parameters
ParameterType
dimensionint
Returns FieldSpec

i8_vector()

i8_vector(dimension: int) -> FieldSpec
Create a FieldSpec type for i8_vector values. Example:
from topk_sdk.schema import i8_vector

client.collections().create("books", schema={
    "title_embedding": i8_vector(dimension=1536)
})
Parameters
ParameterType
dimensionint
Returns FieldSpec

binary_vector()

binary_vector(dimension: int) -> FieldSpec
Create a FieldSpec type for binary_vector values. Example:
from topk_sdk.schema import binary_vector

client.collections().create("books", schema={
    "title_embedding": binary_vector(dimension=128)
})
Parameters
ParameterType
dimensionint
Returns FieldSpec

f32_sparse_vector()

f32_sparse_vector() -> FieldSpec
Create a FieldSpec type for f32_sparse_vector values. Note: Sparse vectors use u32 dimension indices to support dictionaries of up to 2^32 - 1 terms. Example:
from topk_sdk.schema import f32_sparse_vector

client.collections().create("books", schema={
    "sparse_field": f32_sparse_vector()
})
Returns FieldSpec

u8_sparse_vector()

u8_sparse_vector() -> FieldSpec
Create a FieldSpec type for u8_sparse_vector values. Note: Sparse vectors use u32 dimension indices to support dictionaries of up to 2^32 - 1 terms. Example:
from topk_sdk.schema import u8_sparse_vector

client.collections().create("books", schema={
    "sparse_field": u8_sparse_vector()
})
Returns FieldSpec

bytes()

bytes() -> FieldSpec
Create a FieldSpec type for bytes values. Example:
from topk_sdk.schema import bytes

client.collections().create("books", schema={
    "image": bytes()
})
Returns FieldSpec

list()

list(value_type: Literal['text', 'integer', 'float']) -> FieldSpec
Create a FieldSpec type for list values. Example:
from topk_sdk.schema import list

client.collections().create("books", schema={
    "tags": list(value_type="text")
})
Parameters
ParameterType
value_typeLiteral[‘text’, ‘integer’, ‘float’]
Returns FieldSpec

vector_index()

vector_index(metric: Literal['cosine', 'euclidean', 'dot_product', 'hamming']) -> FieldIndex
Create a FieldIndex type for vector_index values. Supported metrics:
  • euclidean (only dense vectors)
  • cosine (only dense vectors)
  • dot_product (dense and sparse vectors)
  • hamming (only binary vectors)
Example:
from topk_sdk.schema import f32_vector, vector_index

client.collections().create("books", schema={
    "title_embedding": f32_vector(dimension=1536).index(vector_index(metric="cosine"))
})
Parameters
ParameterType
metricLiteral[‘cosine’, ‘euclidean’, ‘dot_product’, ‘hamming’]
Returns FieldIndex

keyword_index()

keyword_index() -> FieldIndex
Create a FieldIndex type for keyword_index values. Example:
from topk_sdk.schema import text, keyword_index

client.collections().create("books", schema={
    "title": text().index(keyword_index())
})
Returns FieldIndex

semantic_index()

semantic_index(model: str) -> FieldIndex
Create a FieldIndex type for semantic_index values. Supported models:
  • cohere/embed-english-v3
  • cohere/embed-multilingual-v3
  • cohere/embed-v4 (default)
TopK supports the following embedding types for Cohere models:
  • float32
  • uint8
  • binary
Example:
from topk_sdk.schema import text, semantic_index

client.collections().create("books", schema={
    "title": text().index(semantic_index(model="cohere/embed-v4"))
})
Parameters
ParameterType
modelstr
Returns FieldIndex