createSearch
Configure one normalized search client with explicit providers and time budgets.
On this page
Signature
import { createSearch } from '@belweave/search-sdk';
import type { SearchConfig } from '@belweave/search-sdk';
// createSearch(config: SearchConfig)
// → { web: { search(request, options?), searchBatch(requests, options?) } }Configuration
| Field | Behavior |
|---|---|
provider | Required SearchProvider; first attempted provider. |
fallback | Optional ordered array of distinct provider IDs. |
timeoutMs | Total deadline in integer milliseconds; default 10,000. |
attemptTimeoutMs | Per-attempt budget; defaults to the total configured budget. |
retry | Optional additional attempts per provider with bounded backoff; off by default. |
maxConcurrency | Optional active-operation bound; queue time shares the deadline. |
cache | Optional { ttlMs, maxEntries? } local successful-response cache. |
deduplicate | Optional sharing of identical in-flight requests; false by default. |
Both durations must be between 1 and 2,147,483,647. Unknown configuration fields, duplicate provider IDs, invalid capability descriptors, and invalid budgets are configuration errors. Factory configuration errors can throw synchronously.
Example
import { createSearch } from '@belweave/search-sdk';
import { context } from '@belweave/search-sdk/context';
import { tinyfish } from '@belweave/search-sdk/tinyfish';
const contextKey = process.env.CONTEXT_API_KEY;
const tinyfishKey = process.env.TINYFISH_API_KEY;
if (!contextKey || !tinyfishKey) throw new Error('Missing server credentials');
const client = createSearch({
provider: context({ apiKey: contextKey }),
fallback: [tinyfish({ apiKey: tinyfishKey })],
timeoutMs: 10_000,
attemptTimeoutMs: 4_000,
});
const response = await client.web.search({ query: 'SQLite write concurrency' });
console.log(response.provider, response.attempts, response.warnings);Set a smaller per-attempt budget when you need to reserve time for fallback. A total deadline never extends to accommodate another provider.