Skip to main content

Bulk upsert 1000 documents

Send a large batch of documents through the Data Hub bulk endpoint, then read the result rows to find the partial failures.

import sasvi
from sasvi.documents import raise_on_errors

client = sasvi.SVIClient.from_env()

documents = [
{
"objectTypeName": "<your-entity-type>",
"fieldValues": {"name": f"Account {i}", "score": i},
}
for i in range(1000)
]

results = client.documents.bulk_upsert(documents)
# Pass masked=True for restricted or PII payloads (masked-document representations).

failed = [row for row in results if not row.succeeded]
print(f"total={len(results)} succeeded={len(results) - len(failed)} failed={len(failed)}")

if failed:
for row in failed:
print(row.id, row.entity_type, row.error)
raise_on_errors(results) # raises BulkOperationError listing every failure

bulk_upsert returns a list[BulkOperationResult] with one row per input, in input order, so you can also walk the whole list and partition on row.succeeded. The comprehension above keeps only the failed rows, which is what you report on.

Async​

Inside an event loop, call bulk_upsert_async. It takes the same arguments, sends the same chunks one after another, and fails the same way:

results = await client.documents.bulk_upsert_async(documents)

Tuning the batch size​

The Data Hub endpoint accepts payloads up to roughly 10 MB per request. A thousand small documents sits well under that. For richer payloads (long text, embedded URIs, nested children) pass chunk_size, and the SDK splits the input into sequential requests and aggregates the result rows for you.

results = client.documents.bulk_upsert(documents, chunk_size=250)
total_failed = sum(1 for row in results if not row.succeeded)

Go further​