Upsert documents
TopK documents are JSON-like objects containing key-value pairs.
Upsert function
To upsert documents, pass a list of documents to the upsert()
function:
- Every document must have a string
_id
field. - If a document with the specified
_id
doesn’t exist, a new document will be inserted. - If a document with the same
_id
already exists, the existing document will be replaced with the new one.
The upsert()
function does not perform a partial update or merge - the entire document is being replaced.
Supported types
TopK documents are a flat structure of key-value pairs.
The following value types are supported:
Type | Python Type | JavaScript Type | Helper Function |
---|---|---|---|
String | str | string | - |
Integer | int | number | - |
Float | float | number | - |
Boolean | bool | boolean | - |
Float32 vector | List[float] | number[] | f32_vector() |
U8 vector | use helper | use helper | u8_vector() |
Binary vector | use helper | use helper | binary_vector() |
Bytes | use helper | use helper | bytes() |
Here’s an example of a creating a collection with all supported types and inserting a document:
Insert a document with all supported types:
Helper functions
In TopK, a vector is represented as a flat array of numbers. To differentiate between different types of vectors, use provided helper functions.
TopK supports the following types of vectors:
- Float32 vectors
- U8 vectors
- Binary vectors
If no helper function is used, the vector is assumed to be a float32 vector.
f32_vector()
To pass a float32 vector, use the f32_vector()
helper function:
u8_vector()
To pass a u8 vector, use the u8_vector()
helper function:
binary_vector()
To pass a binary vector, use the binary_vector()
helper function:
bytes()
To pass a byte object, use the bytes()
helper function: