Skip to article

createSearch

Configure one normalized search client with explicit providers and time budgets.

On this page

Signature

TypeScript
import { createSearch } from '@belweave/search-sdk';
import type { SearchConfig } from '@belweave/search-sdk';

// createSearch(config: SearchConfig)
// → { web: { search(request, options?), searchBatch(requests, options?) } }

Configuration

FieldBehavior
providerRequired SearchProvider; first attempted provider.
fallbackOptional ordered array of distinct provider IDs.
timeoutMsTotal deadline in integer milliseconds; default 10,000.
attemptTimeoutMsPer-attempt budget; defaults to the total configured budget.
retryOptional additional attempts per provider with bounded backoff; off by default.
maxConcurrencyOptional active-operation bound; queue time shares the deadline.
cacheOptional { ttlMs, maxEntries? } local successful-response cache.
deduplicateOptional 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

client.ts · server
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.