Skip to main content
Adds vectors to the index, or replaces existing vectors with the same ID. upsert() takes one of two shapes:

Parameters

Shape 1: list of item dicts

Each dict can contain:
contents accepts a str or bytes. Strings are stored as-is; bytes are base64-encoded first. get() always returns contents as a str, so bytes come back as their base64 text: decode them with base64.b64decode().
datetime and date objects in metadata are converted to integer epoch milliseconds before being sent (naive datetimes are treated as UTC; sub-millisecond precision is truncated). Values read back with get() come back as the same integer, not a datetime. The same conversion runs on filter dicts passed to query() / query_binary() / query_metadata(), so a {"created": {"$gte": datetime(...)}} predicate works directly. See Dates.

Shape 2: parallel arrays

Shape 2 can’t attach metadata or contents. To send them with parallel arrays, call upsert_binary() directly.
Don’t upsert vectors containing NaN or infinite values. The service stores them, and later get or query calls on that index that return vectors or distances fail with a 5xx error. The SDK doesn’t check for them.

Returns

None

Exceptions

  • The arguments don’t match either shape (also a TypeError), an item has no id, or the IDs and vectors differ in length. Raised before any request is sent.
  • The service rejects the items (HTTP 400), for example a vector with the wrong dimension.
The index_key or api_key is invalid (HTTP 401).
The service returns 5xx.
The service can’t be reached.
See Errors for the full hierarchy.

Example Usage

Item dicts

Parallel arrays

Parallel arrays with metadata and contents

Replace an existing item