> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/algolia/docsearch/llms.txt
> Use this file to discover all available pages before exploring further.

# DocSearchAskAi

> Configuration type for enabling Ask AI features in DocSearch

# DocSearchAskAi Configuration

The `DocSearchAskAi` type defines configuration options for enabling AI-powered conversational search in DocSearch. This feature allows users to ask questions and receive AI-generated answers based on your documentation.

## Required Properties

<ResponseField name="assistantId" type="string" required>
  The assistant ID to use for the Ask AI feature. This identifies your configured AI assistant.

  <CodeGroup>
    ```tsx Example theme={null}
    <DocSearch
      appId="YOUR_APP_ID"
      apiKey="YOUR_SEARCH_API_KEY"
      indexName="docs"
      askAi={{
        assistantId: 'your-assistant-id'
      }}
    />
    ```
  </CodeGroup>
</ResponseField>

## Optional Algolia Configuration

By default, Ask AI uses the same Algolia credentials (`appId`, `apiKey`, `indexName`) as the main search. You can override these for Ask AI if needed.

<ResponseField name="indexName" type="string">
  The index name to use for the Ask AI feature. Your assistant will search this index for relevant documents.

  If not provided, the main `indexName` from DocSearchProps will be used.

  <CodeGroup>
    ```tsx Example theme={null}
    <DocSearch
      appId="YOUR_APP_ID"
      apiKey="YOUR_SEARCH_API_KEY"
      indexName="docs"
      askAi={{
        assistantId: 'your-assistant-id',
        indexName: 'docs-ai' // Use a different index for AI
      }}
    />
    ```
  </CodeGroup>
</ResponseField>

<ResponseField name="apiKey" type="string">
  The API key to use for the Ask AI feature. Your assistant will use this API key to search the index.

  If not provided, the main `apiKey` from DocSearchProps will be used.
</ResponseField>

<ResponseField name="appId" type="string">
  The app ID to use for the Ask AI feature. Your assistant will use this app ID to search the index.

  If not provided, the main `appId` from DocSearchProps will be used.
</ResponseField>

## Features

<ResponseField name="suggestedQuestions" type="boolean">
  Enables displaying suggested questions on Ask AI's new conversation screen.

  **Default:** `false`

  When enabled, users will see suggested questions they can click to start a conversation.

  <CodeGroup>
    ```tsx Example theme={null}
    <DocSearch
      appId="YOUR_APP_ID"
      apiKey="YOUR_SEARCH_API_KEY"
      indexName="docs"
      askAi={{
        assistantId: 'your-assistant-id',
        suggestedQuestions: true
      }}
    />
    ```
  </CodeGroup>
</ResponseField>

## Search Parameters

The `searchParameters` configuration varies based on whether you're using the standard Ask AI backend or the experimental Agent Studio backend.

### Standard Configuration (Default)

<ResponseField name="searchParameters" type="AskAiSearchParameters">
  The search parameters to use for the Ask AI feature when `agentStudio` is not enabled or is `false`.

  <Expandable title="AskAiSearchParameters Type">
    ```typescript theme={null}
    type AskAiSearchParameters = {
      facetFilters?: string[];
      filters?: string;
      attributesToRetrieve?: string[];
      restrictSearchableAttributes?: string[];
      distinct?: boolean | number | string;
    };
    ```

    <ResponseField name="facetFilters" type="string[]">
      Facet filters to apply to the AI search queries.

      Example: `['version:v2', 'language:en']`
    </ResponseField>

    <ResponseField name="filters" type="string">
      Filters to apply to the AI search queries.

      Example: `'category:guides AND version:latest'`
    </ResponseField>

    <ResponseField name="attributesToRetrieve" type="string[]">
      Attributes to retrieve from the search results.

      Example: `['content', 'hierarchy', 'url']`
    </ResponseField>

    <ResponseField name="restrictSearchableAttributes" type="string[]">
      Restrict which attributes can be searched.

      Example: `['content', 'hierarchy.lvl0', 'hierarchy.lvl1']`
    </ResponseField>

    <ResponseField name="distinct" type="boolean | number | string">
      Enable distinct to avoid duplicate results.

      * `true`: Enable distinct with default settings
      * `number`: Number of distinct hits to keep
      * `false`: Disable distinct
    </ResponseField>
  </Expandable>

  <CodeGroup>
    ```tsx Example theme={null}
    <DocSearch
      appId="YOUR_APP_ID"
      apiKey="YOUR_SEARCH_API_KEY"
      indexName="docs"
      askAi={{
        assistantId: 'your-assistant-id',
        searchParameters: {
          filters: 'version:latest',
          facetFilters: ['language:en'],
          distinct: true
        }
      }}
    />
    ```
  </CodeGroup>
</ResponseField>

### Agent Studio Configuration (Experimental)

<ResponseField name="agentStudio" type="boolean">
  **Experimental:** Whether to use Agent Studio as the chat backend.

  This is an experimental feature and its API may change without notice in future releases. Use with caution in production environments.

  **Default:** `false`

  When set to `true`, the `searchParameters` structure changes to be keyed by index name.
</ResponseField>

<ResponseField name="searchParameters" type="AgentStudioSearchParameters">
  When `agentStudio: true`, search parameters must be keyed by index name.

  <Expandable title="AgentStudioSearchParameters Type">
    ```typescript theme={null}
    type AgentStudioSearchParameters = Record<string, Omit<AskAiSearchParameters, 'facetFilters'>>;
    ```

    Each key is an index name, and the value contains search parameters for that index (excluding `facetFilters`).
  </Expandable>

  <CodeGroup>
    ```tsx Agent Studio Example theme={null}
    <DocSearch
      appId="YOUR_APP_ID"
      apiKey="YOUR_SEARCH_API_KEY"
      indexName="docs"
      askAi={{
        assistantId: 'your-assistant-id',
        agentStudio: true,
        searchParameters: {
          'docs': {
            distinct: false,
            filters: 'version:latest'
          },
          'api-reference': {
            distinct: true,
            restrictSearchableAttributes: ['content', 'title']
          }
        }
      }}
    />
    ```
  </CodeGroup>
</ResponseField>

## Internal/Testing Properties

<ResponseField name="useStagingEnv" type="boolean">
  Internal testing property. Do not use in production.

  **Note:** This is a temporary hack for testing staging environments and will be removed before release.
</ResponseField>

## Type Variants

The `DocSearchAskAi` type uses TypeScript discriminated unions to ensure type safety based on the `agentStudio` setting:

<CodeGroup>
  ```typescript Default Variant theme={null}
  type DocSearchAskAi = {
    assistantId: string;
    indexName?: string;
    apiKey?: string;
    appId?: string;
    suggestedQuestions?: boolean;
    useStagingEnv?: boolean;
    agentStudio?: never;
    searchParameters?: AskAiSearchParameters;
  }
  ```

  ```typescript Agent Studio Disabled theme={null}
  type DocSearchAskAi = {
    assistantId: string;
    indexName?: string;
    apiKey?: string;
    appId?: string;
    suggestedQuestions?: boolean;
    useStagingEnv?: boolean;
    agentStudio: false;
    searchParameters?: AskAiSearchParameters;
  }
  ```

  ```typescript Agent Studio Enabled theme={null}
  type DocSearchAskAi = {
    assistantId: string;
    indexName?: string;
    apiKey?: string;
    appId?: string;
    suggestedQuestions?: boolean;
    useStagingEnv?: boolean;
    agentStudio: true;
    searchParameters?: AgentStudioSearchParameters;
  }
  ```
</CodeGroup>

## Simple String Configuration

In addition to the full `DocSearchAskAi` configuration object, you can pass a simple string assistant ID:

<CodeGroup>
  ```tsx Simple String Config theme={null}
  <DocSearch
    appId="YOUR_APP_ID"
    apiKey="YOUR_SEARCH_API_KEY"
    indexName="docs"
    askAi="your-assistant-id"
  />
  ```
</CodeGroup>

This is equivalent to:

<CodeGroup>
  ```tsx Equivalent Object Config theme={null}
  <DocSearch
    appId="YOUR_APP_ID"
    apiKey="YOUR_SEARCH_API_KEY"
    indexName="docs"
    askAi={{
      assistantId: 'your-assistant-id'
    }}
  />
  ```
</CodeGroup>

## Complete Examples

<CodeGroup>
  ```tsx Basic Ask AI theme={null}
  <DocSearch
    appId="YOUR_APP_ID"
    apiKey="YOUR_SEARCH_API_KEY"
    indexName="docs"
    askAi="your-assistant-id"
  />
  ```

  ```tsx With Suggested Questions theme={null}
  <DocSearch
    appId="YOUR_APP_ID"
    apiKey="YOUR_SEARCH_API_KEY"
    indexName="docs"
    askAi={{
      assistantId: 'your-assistant-id',
      suggestedQuestions: true
    }}
  />
  ```

  ```tsx With Search Parameters theme={null}
  <DocSearch
    appId="YOUR_APP_ID"
    apiKey="YOUR_SEARCH_API_KEY"
    indexName="docs"
    askAi={{
      assistantId: 'your-assistant-id',
      suggestedQuestions: true,
      searchParameters: {
        filters: 'version:latest AND category:guides',
        facetFilters: ['language:en'],
        distinct: true,
        attributesToRetrieve: [
          'content',
          'hierarchy',
          'url',
          'type'
        ]
      }
    }}
  />
  ```

  ```tsx Separate AI Index theme={null}
  <DocSearch
    appId="YOUR_APP_ID"
    apiKey="YOUR_SEARCH_API_KEY"
    indexName="docs"
    askAi={{
      assistantId: 'your-assistant-id',
      indexName: 'docs-ai',
      apiKey: 'YOUR_AI_API_KEY',
      searchParameters: {
        filters: 'optimized:true'
      }
    }}
  />
  ```

  ```tsx Agent Studio (Experimental) theme={null}
  <DocSearch
    appId="YOUR_APP_ID"
    apiKey="YOUR_SEARCH_API_KEY"
    indexName="docs"
    askAi={{
      assistantId: 'your-assistant-id',
      agentStudio: true,
      searchParameters: {
        'docs': { distinct: false },
        'api-reference': { distinct: true }
      }
    }}
  />
  ```
</CodeGroup>
