Documents in TopK are JSON-like objects composed of key-value pairs. Each document within a collection: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.
- Must include a unique
_idfield - Must conform to the schema defined for the collection
Upsert documents
To upsert documents, pass a list of documents to theupsert() function:
- Every document must have a string
_idfield. - If a document with the specified
_iddoesn’t exist, a new document will be inserted. - If a document with the same
_idalready 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.Additional (non-schema) fields
You may include fields that are not defined in the collection schema. These fields:- Are stored with the document
- Can be returned to the client in query results
- Can be used for filtering in queries
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 | - |
| String list | list[str] | string[] | string_list() |
| F32 list | list[float] | number[] | f32_list() |
| F64 list | use helper | use helper | f64_list() |
| I32 list | use helper | use helper | i32_list() |
| I64 list | use helper | use helper | i64_list() |
| U32 list | use helper | use helper | u32_list() |
| F8 vector | use helper | use helper | f8_vector() |
| F16 vector | use helper | use helper | f16_vector() |
| F32 vector | list[float] | number[] | f32_vector() |
| U8 vector | use helper | use helper | u8_vector() |
| I8 vector | use helper | use helper | i8_vector() |
| Binary vector | use helper | use helper | binary_vector() |
| F32 sparse vector | use helper | use helper | f32_sparse_vector() |
| U8 sparse vector | use helper | use helper | u8_sparse_vector() |
| Matrix | use helper | use helper | matrix() |
| Bytes | use helper | use helper | bytes() |
| Struct | dict[str, Any] | Record<string, any> | struct() |
Delete documents
You can delete documents by their_id or using a filter expression. Both methods provide
the same consistency guarantees and will be reflected in query/get results according to your consistency level.
Delete documents by _id
To delete documents by their _id, pass a list of _ids to the delete() method:
The
delete() method returns an LSN (Log Sequence Number) that you can pass to subsequent queries for read-after-write consistency.Delete documents by filter expression
To delete documents that match a predicate, you can pass a filter expression to thedelete() function.