Skip to main content
topk-js / schema

Functions

binaryVector()

function binaryVector(options: VectorOptions): FieldSpec;
Creates a FieldSpec type for binary_vector values. Example:
import { binaryVector } from "topk-js/schema";

await client.collections().create("books", {
  title_embedding: binaryVector({ dimension: 128 })
});
Parameters
ParameterType
optionsVectorOptions
Returns FieldSpec

bool()

function bool(): FieldSpec;
Creates a FieldSpec type for bool values. Example:
import { bool } from "topk-js/schema";

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

bytes()

function bytes(): FieldSpec;
Creates a FieldSpec type for bytes values. Example:
import { bytes } from "topk-js/schema";

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

f32SparseVector()

function f32SparseVector(): FieldSpec;
Creates 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:
import { f32SparseVector } from "topk-js/schema";

await client.collections().create("books", {
  sparse_field: f32SparseVector()
});
Returns FieldSpec

f32Vector()

function f32Vector(options: VectorOptions): FieldSpec;
Creates a FieldSpec type for f32_vector values. Example:
import { f32Vector } from "topk-js/schema";

await client.collections().create("books", {
  title_embedding: f32Vector({ dimension: 1536 })
});
Parameters
ParameterType
optionsVectorOptions
Returns FieldSpec

float()

function float(): FieldSpec;
Creates a FieldSpec type for float values. Example:
import { float } from "topk-js/schema";

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

i8Vector()

function i8Vector(options: VectorOptions): FieldSpec;
Creates a FieldSpec type for i8_vector values. Example:
import { i8Vector } from "topk-js/schema";

await client.collections().create("books", {
  title_embedding: i8Vector({ dimension: 1536 })
});
Parameters
ParameterType
optionsVectorOptions
Returns FieldSpec

int()

function int(): FieldSpec;
Creates a FieldSpec type for int values. Example:
import { int } from "topk-js/schema";

await client.collections().create("books", {
  published_year: int()
});
Returns FieldSpec

keywordIndex()

function keywordIndex(): FieldIndex;
Creates a FieldIndex type for keyword_index values. Example:
import { text, keywordIndex } from "topk-js/schema";

await client.collections().create("books", {
  title: text().index(keywordIndex())
});
Adding a keyword index allows you to perform keyword search on this field. Returns FieldIndex

list()

function list(options: ListOptions): FieldSpec;
Creates a FieldSpec type for list values. Example:
import { list } from "topk-js/schema";

await client.collections().create("books", {
  tags: list({ valueType: "text" })
});
Parameters
ParameterType
optionsListOptions
Returns FieldSpec

semanticIndex()

function semanticIndex(options?: SemanticIndexOptions): FieldIndex;
Creates a FieldIndex type for semantic_index values. Example:
import { text, semanticIndex } from "topk-js/schema";

await client.collections().create("books", {
  title: text().index(semanticIndex({ model: "cohere/embed-v4" }))
});
Parameters:
  • model: Embedding model to use for semantic search. Currently supported:
    • cohere/embed-english-v3
    • cohere/embed-multilingual-v3
    • cohere/embed-v4 (default)
  • embeddingType: TopK supports the following embedding types for Cohere models:
    • float32
    • uint8
    • binary
Parameters
ParameterType
options?SemanticIndexOptions
Returns FieldIndex

text()

function text(): FieldSpec;
Creates a FieldSpec type for text values. Example:
import { text } from "topk-js/schema";

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

u8SparseVector()

function u8SparseVector(): FieldSpec;
Creates 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:
import { u8SparseVector } from "topk-js/schema";

await client.collections().create("books", {
  sparse_field: u8SparseVector()
});
Returns FieldSpec

u8Vector()

function u8Vector(options: VectorOptions): FieldSpec;
Creates a FieldSpec type for u8_vector values. Example:
import { u8Vector } from "topk-js/schema";

await client.collections().create("books", {
  title_embedding: u8Vector({ dimension: 1536 })
});
Parameters
ParameterType
optionsVectorOptions
Returns FieldSpec

vectorIndex()

function vectorIndex(options: VectorIndexOptions): FieldIndex;
Creates a FieldIndex type for vector_index values. Supported metrics:
  • euclidean (not supported for sparse vectors)
  • cosine (not supported for sparse vectors)
  • dot_product (supported for dense and sparse vectors)
  • hamming (only supported for binary_vector type)
Example:
import { f32Vector, vectorIndex } from "topk-js/schema";

await client.collections().create("books", {
  title_embedding: f32Vector({ dimension: 1536 }).index(
    vectorIndex({ metric: "cosine" })
  )
});
Parameters
ParameterType
optionsVectorIndexOptions
Returns FieldIndex

Classes

FieldIndex

Internal

FieldSpec

Internal Methods
index()
index(index: FieldIndex): FieldSpec;
Creates an index on a field. Example:
import { text, keywordIndex } from "topk-js/schema";

await client.collections().create("books", {
  title: text().index(keywordIndex())
});
Parameters
ParameterType
indexFieldIndex
Returns FieldSpec
required()
required(): FieldSpec;
Marks the field as required. All fields are optional by default. Example:
import { text } from "topk-js/schema";

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

Interfaces

ListOptions

Options for list field specifications. This struct contains configuration options for list fields, including the type of values the list can contain. Properties
PropertyTypeDescription
valueTypeListValueTypeThe type of values the list can contain

SemanticIndexOptions

Options for semantic index specifications. This struct contains configuration options for semantic indexes, including the model and embedding type to use. Properties
PropertyTypeDescription
embeddingType?EmbeddingDataTypeThe type of embedding data
model?stringThe embedding model to use

VectorIndexOptions

Options for vector index specifications. This struct contains configuration options for vector indexes, including the distance metric to use. Properties
PropertyTypeDescription
metricVectorDistanceMetricThe distance metric to use for vector similarity

VectorOptions

Options for vector field specifications. This struct contains configuration options for vector fields, including the required dimension parameter. Properties
PropertyTypeDescription
dimensionnumberThe dimension of the vector

Type Aliases

EmbeddingDataType

type EmbeddingDataType = "float32" | "uint8" | "binary";

KeywordIndexType

type KeywordIndexType = "text";

ListValueType

type ListValueType = "text" | "integer" | "float";

VectorDistanceMetric

type VectorDistanceMetric = "cosine" | "euclidean" | "dot_product" | "hamming";