Skip to main content
Documents in TopK are JSON-like objects composed of key-value pairs. Each document within a collection:
  • Must include a unique _id field
  • Must conform to the schema defined for the collection
Fields defined in the schema can be indexed for vector, keyword, or other retrieval strategies.

Upsert documents

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.
Each document you send is serialized as a Protocol Buffers (protobuf) message. The encoded size of that message must be 128KB or smaller.

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
Fields that are not defined in the schema are not indexed. If you want to use a field for vector search, semantic search, keyword search or multi-vector search, it must be declared in the schema and have a corresponding index defined.

Supported types

TopK documents are a flat structure of key-value pairs. The following value types are supported:

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 the delete() function.
Passing a filter expression to delete() is useful for deleting documents that match a specific condition, such as all documents for a specific tenant e.g. field("_id").starts_with("tenant-123/").