Skip to content

Typesense

Keep collection search and ordered multi-search with nested hits[].document. The native X-TYPESENSE-API-KEY header works with a DocSlurp key.

On this page

1Install

Terminal
# Needs @docslurp/sdk 0.2.0 or newer (0.1.x lacks these exports).
npm install @docslurp/sdk@^0.3.0

# Then import:
# import { createDocSlurpTypesenseClient } from '@docslurp/sdk/search-adapters';
Terminal
# Same client as @docslurp/sdk/search-adapters, one subpath per search client.
npm install @docslurp/contrib-search-compat

# Then import:
# import { createDocSlurpTypesenseClient } from '@docslurp/contrib-search-compat/typesense';

2Swap the client

Collection names become workspace references: a slug, a UUID, or default. query_by must be text, the passage text DocSlurp searches.

search.tsDiff
- import Typesense from 'typesense';
- const client = new Typesense.Client({ nodes: [TYPESENSE_NODE], apiKey: TYPESENSE_SEARCH_KEY });
+ import { createDocSlurpTypesenseClient } from '@docslurp/sdk/search-adapters';
+ const client = createDocSlurpTypesenseClient({
+   apiUrl: 'https://docslurp.io',
+   clientKey: PUBLIC_DOCSLURP_CLIENT_KEY,
+ });

  // Unchanged: collections(name).documents().search() and multiSearch.perform()
  const result = await client.collections('product-docs').documents()
    .search({ q: 'installation', query_by: 'text', per_page: 10 });

3Usage

search.ts
import { createDocSlurpTypesenseClient } from '@docslurp/sdk/search-adapters';

const client = createDocSlurpTypesenseClient({ apiUrl: 'https://docslurp.io', clientKey });

const result = await client.collections('product-docs').documents().search({
  q: 'installation', query_by: 'text', page: 1, per_page: 10,
});
result.hits.map(hit => hit.document.title);
search.ts
// Up to 10 searches per batch; results keep request order.
const batch = await client.multiSearch.perform({
  searches: [
    { collection: 'product-docs', q: 'installation' },
    { collection: 'release-notes', q: 'installation' },
  ],
}, { query_by: 'text' });

batch.results[0].hits; // product-docs
batch.results[1].hits; // release-notes
Terminal
curl https://docslurp.io/compat/typesense/multi_search \
  -H "X-TYPESENSE-API-KEY: $DOCSLURP_SEARCH_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "searches": [
        { "collection": "product-docs", "q": "installation", "query_by": "text" },
        { "collection": "default", "q": "installation", "query_by": "text" }
      ] }'

Every collection in a batch is authorized before any search runs, so a batch never incurs usage for a request that would be rejected. The default page size is 20.

Compatibility

Supported

  • collections(name).documents().search() via GET or POST
  • multiSearch.perform() with 1–10 searches, results in request order
  • q, query_by: "text", page, per_page

Watch for

  • found counts the 100-passage window; there's no workspace-wide out_of.
  • facet_counts is always empty.
  • Union search, grouping, filters, facets, sort and other query_by fields return HTTP 400.

Hand off to an agent

Working in a real codebase? Copy a prompt that tells a coding agent exactly what to change for Typesense: which entry point to use, the supported contract, and what to validate before shipping. It contains no keys or secrets.

Review agent instructions

Before switching traffic, run through the go-live checklist. Stuck? See troubleshooting.

Jump to