Overview
The schema module provides functions to define field types and indexes for TopK collections. Import schema functions fromtopk-js/schema.
FieldSpec
Represents a field specification that can be used to define a field in a collection schema. All schema functions return aFieldSpec object.
Methods
required()
Marks the field as required. All fields are optional by default.index(index)
Creates an index on a field.The index configuration to apply to the field
Scalar Field Types
text()
Creates a FieldSpec for text values.int()
Creates a FieldSpec for integer values.float()
Creates a FieldSpec for floating-point values.bool()
Creates a FieldSpec for boolean values.bytes()
Creates a FieldSpec for binary data.List Field Type
list(options)
Creates a FieldSpec for list values.Configuration options for the list field
The type of values the list can contain. Can be:
'text''integer''float'
Vector Field Types
f32Vector(options)
Creates a FieldSpec for 32-bit float vector values.Configuration options for the vector field
The dimension of the vector
f16Vector(options)
Creates a FieldSpec for 16-bit float vector values.Configuration options for the vector field
The dimension of the vector
f8Vector(options)
Creates a FieldSpec for 8-bit float vector values.Configuration options for the vector field
The dimension of the vector
binaryVector(options)
Creates a FieldSpec for binary vector values.Configuration options for the vector field
The dimension of the vector
u8Vector(options)
Creates a FieldSpec for 8-bit unsigned integer vector values.Configuration options for the vector field
The dimension of the vector
i8Vector(options)
Creates a FieldSpec for 8-bit signed integer vector values.Configuration options for the vector field
The dimension of the vector
Sparse Vector Field Types
f32SparseVector()
Creates a FieldSpec for 32-bit float sparse vector values.Sparse vectors use u32 dimension indices to support dictionaries of up to 2^32 - 1 terms.
u8SparseVector()
Creates a FieldSpec for 8-bit unsigned integer sparse vector values.Sparse vectors use u32 dimension indices to support dictionaries of up to 2^32 - 1 terms.
Matrix Field Type
matrix(options)
Creates a FieldSpec for matrix values.Configuration options for the matrix field
The dimension (number of columns) of the matrix
The value type of the matrix elements. Can be:
'f32'- 32-bit float'f16'- 16-bit float'f8'- 8-bit float'u8'- 8-bit unsigned integer'i8'- 8-bit signed integer
Index Types
semanticIndex(options?)
Creates a FieldIndex for semantic search. This index automatically generates embeddings from text fields and enables semantic similarity search.Optional configuration for the semantic index
Embedding model to use for semantic search. Currently supported:
cohere/embed-english-v3cohere/embed-multilingual-v3cohere/embed-v4(default)
TopK supports the following embedding types for Cohere models:
'float32''uint8''binary'
vectorIndex(options)
Creates a FieldIndex for vector similarity search.Configuration options for the vector index
The distance metric to use for vector similarity. Can be:
'cosine'(not supported for sparse vectors)'euclidean'(not supported for sparse vectors)'dot_product'(supported for dense and sparse vectors)'hamming'(only supported for binary_vector type)
multiVectorIndex(options)
Creates a FieldIndex for multi-vector similarity search.Configuration options for the multi-vector index
The distance metric to use for multi-vector similarity. Currently supported:
'maxsim'
Number of bits to use for multi-vector sketch
The quantization to use for multi-vector values. Can be:
'1bit''2bit''scalar'