web.searchBatch
Run multiple normalized queries with bounded workers and ordered per-item outcomes.
On this page
Run independent queries
Call searchBatch on the same web client as search. Results preserve input order even when requests finish out of order. Each item has its original index and either a fulfilled value or a rejected SearchError.
import { createSearch } from '@belweave/search-sdk';
import { createMockProvider } from '@belweave/search-sdk/testing';
const client = createSearch({ provider: createMockProvider() });
const outcomes = await client.web.searchBatch(
[
{ query: 'SQLite WAL', limit: 3 },
{ query: 'SQLite transactions', limit: 3 },
],
{ concurrency: 2, timeoutMs: 10_000 },
);
for (const outcome of outcomes) {
if (outcome.status === 'fulfilled') {
console.log(outcome.index, outcome.value.results);
} else {
console.log(outcome.index, outcome.error.code);
}
}Batch options
| Option | Contract |
|---|---|
requests | Array of up to 1,000 SearchRequest items; empty input returns an empty array. |
concurrency | Workers per batch, integer 1–64; default 4. |
timeoutMs | Whole-batch budget including queued items; defaults to the client's total timeoutMs. |
signal | Optional caller AbortSignal for the entire batch. |
The client's maxConcurrency still limits active underlying searches. Each item uses the same provider, fallback, retry, cache, and deduplication policy as a single search; concurrency is not a provider-side batch endpoint or a billing discount.
Handle partial failure
- An invalid individual request becomes a rejected item without discarding successful sibling results.
- An invalid batch envelope or option rejects the batch promise with invalid_request.
- Caller cancellation or the whole-batch deadline stops new dispatch and rejects unfinished items with aborted or timeout. Completed successful items remain in the ordered output.
- Client and per-attempt deadlines still apply to each individual search. A total batch budget does not extend them.
Cancellation cannot promise that upstream work or billing stops after a request has been dispatched. Inspect each outcome and its attempt trace; persist the results you need before retrying failed items.