Skip to main content
The SDK automatically caches requests to minimize API calls and improve performance.

Request deduplication

When multiple components request the same data, the SDK automatically deduplicates requests:

Local storage restoration

Cached results are restored from local storage on back navigation:
Disable auto-restore if needed:

Cache invalidation

Invalidate cached queries by pattern:

Search cache

The prepare endpoint caches expensive operations (embeddings, query expansions):
When using search_id, the server maintains the cache for 15 minutes:

Storage adapters

Cache persistence is pluggable via a StorageAdapter. The SDK ships two adapters and accepts any custom implementation, so the cache survives reloads in the browser, page navigations in SSR frameworks, or process restarts in Node.

Browser (localStorage)

localStorage is used automatically when the SDK runs in a browser. Pass an explicit adapter only if you want to customize the storage key:
localStorageAdapter returns null in environments without window.localStorage (e.g. SSR), so the SDK silently falls back to in-memory caching — safe to use in isomorphic code.

Node.js (file system)

Use fileStorage to persist the cache to disk for build scripts, server-rendered pages, or long-running Node processes:
The adapter takes a minimal FileSystem interface (readFileSync, writeFileSync, unlinkSync), so you can substitute a mock in tests or wrap an alternative file system.

Custom adapter

Implement StorageAdapter to back the cache with anything else — sessionStorage, IndexedDB, Redis, Cloudflare KV, an HTTP service, etc.
All three adapter methods are synchronous and operate on a single serialized JSON string. Wrap async backends in a sync queue or memoize the latest snapshot if you need IndexedDB or remote storage. See Cache, storage, and signals for the full interface reference.

Fetch adapter

The SDK calls the global fetch by default. Provide a custom implementation via the fetch option for SSR runtimes, testing, or environments where fetch is unavailable or blocked.

xhrFetch (browser fallback)

xhrFetch is an XMLHttpRequest-based adapter shipped with the SDK. Use it when ad blockers, browser extensions, or restrictive network policies intercept fetch calls:

Custom fetch

Any function matching the CustomFetch signature can be passed. Common uses:
  • SSR / Node: inject a Node-compatible fetch (e.g. undici, node-fetch) on older runtimes.
  • Testing: stub responses without intercepting global fetch.
  • Instrumentation: add tracing, retries, or auth headers around the request.
The SDK handles retries, abort signals, and error classification on top of whatever fetch returns — your adapter only needs to issue the request and return a Response.

Next steps

Performance

Learn performance optimization techniques.

Best Practices

Review SDK best practices and common pitfalls.