Skip to main content
Version: Stable (v5.x)

Starlight adapter

Use @docsearch/starlight-adapter to replace the built-in Pagefind search in an Astro Starlight site with DocSearch keyword search and Ask AI.

Before you start​

Collect these values:

  • An Algolia application ID.
  • A Search API key with access to your DocSearch indices.
  • At least one DocSearch index name.
  • An Agent Studio agent ID if you want Ask AI or the Sidepanel. Follow Get started with Agent Studio to create one.

Use Astro 7.2.10 or later in the Astro 7 release line and Starlight 0.42.7 or later.

Install the adapter​

Install @docsearch/starlight-adapter@^5:

npm install @docsearch/starlight-adapter@^5

If your site already overrides Starlight's Search component, the adapter keeps your component and logs a warning. Remove the override to use DocSearch.

Add the adapter to Starlight's plugins:

astro.config.mjs
import starlight from '@astrojs/starlight';
import docsearch from '@docsearch/starlight-adapter';
import { defineConfig } from 'astro/config';

export default defineConfig({
integrations: [
starlight({
title: 'My Docs',
plugins: [
docsearch({
appId: 'YOUR_APPLICATION_ID',
apiKey: 'YOUR_SEARCH_API_KEY',
indices: ['YOUR_INDEX_NAME'],
}),
],
}),
],
});

indices is required and must contain at least one index. Use an object to set search parameters for one index:

astro.config.mjs
indices: [
{
name: 'docs',
searchParameters: {
facetFilters: ['language:en'],
hitsPerPage: 5,
},
},
],

The adapter includes these options in your site's browser code. Use a search-only API key, never an admin key.

Start Astro and open the search modal with the header button, Ctrl/Cmd+K, or /.

Add Ask AI​

Set askAi to your Agent Studio agent ID:

astro.config.mjs
docsearch({
appId: 'YOUR_APPLICATION_ID',
apiKey: 'YOUR_SEARCH_API_KEY',
indices: ['YOUR_INDEX_NAME'],
askAi: 'YOUR_AGENT_ID',
}),

The agent reuses the root appId and apiKey. Pass an object to set other credentials, indices, or suggested questions. See Ask AI.

Add the Sidepanel​

Set sidePanel beside askAi. You must also configure askAi:

astro.config.mjs
docsearch({
appId: 'YOUR_APPLICATION_ID',
apiKey: 'YOUR_SEARCH_API_KEY',
indices: ['YOUR_INDEX_NAME'],
askAi: 'YOUR_AGENT_ID',
sidePanel: true,
}),

By default, a floating button in the bottom corner opens the Sidepanel. You can also press Ctrl/Cmd+I. Choosing Ask AI in the search modal opens the Sidepanel with your question. Pass an object instead of true to configure its placement, width, or text. See Sidepanel options.

Next steps​