Algolia DocSearch

repository·main·Indexed 11 days ago

https://github.com/algolia/docsearch

A service that crawls documentation, indexes content in Algolia, and provides an accessible search experience. It includes a CLI for indexing and MCP (Model Context Protocol) plugins for AI coding clients like Claude Code, Cursor, and ChatGPT to access public developer documentation via tools such as algolia_docsearch_search_docs, algolia_docsearch_resolve_docset, and algolia_docsearch_query_docs.

Tokens
108.5K
Snippets
268
Records
430
Agent score
47%

What's inside DocSearch

  1. Overview of Algolia DocSearch MCP Plugins

    main

    The Algolia DocSearch MCP Plugins allow AI coding clients to connect to the public DocSearch documentation corpus via the Model Context Protocol (MCP). These plugins enable AI agents to search and retrieve documentation content using natural language queries.

    Key constraints:

    • They connect to the public endpoint: https://mcp.algolia.com/1/docsearch/mcp.
    • They do not expose crawler operations, DocSearch administration, private documentation, or Algolia index credentials.
    • No user authentication is required for the public endpoint.
  2. Supported framework integrations for DocSearch

    main

    DocSearch can be embedded into various documentation frameworks. A framework integration configures the frontend UI; the Algolia Crawler and index are managed separately.

    Important: Framework documentation may target specific DocSearch frontend releases. Always check package compatibility before upgrading to v5.

    Supported Frameworks:

    FrameworkIntegration Guide
    Docusaurus v1How to enable search
    Docusaurus v2 & v3@docsearch/docusaurus-adapter or Using Algolia DocSearch
    VuePressAlgolia Search
    VitePressSearch
    StarlightAlgolia Search
    LaRecipeAlgolia Search
    OrchidAlgolia Search
    Smooth DOCDocSearch
    DocsyConfigure Algolia DocSearch
    Lotus DocsEnabling the DocSearch Plugin
    SphinxAlgolia DocSearch for Sphinx
  3. Choose the right DocSearch v5 package

    main

    DocSearch v5 offers several packages depending on your framework and desired search features:

    • @docsearch/js: For JavaScript sites (non-React). The default export includes both keyword search and Ask AI.
    • @docsearch/react: For React applications. Use DocSearch for keyword search only, or DocSearchAI for keyword search plus Ask AI.
    • @docsearch/css: Provides the complete stylesheet for buttons and modals.
    • @docsearch/core: Provides shared state, keyboard handling, and the provider for the Composable API.
    • @docsearch/modal: Provides search button, keyword modal, and Ask AI modal components for the Composable API.
    • @docsearch/sidepanel: React components for persistent AI conversations.
    • @docsearch/sidepanel-js: JavaScript wrapper for the AI Sidepanel.
    • @docsearch/docusaurus-adapter: Specifically for Docusaurus sites using the official adapter.
  4. What is Hybrid mode in DocSearch?

    main

    Hybrid mode connects the DocSearch keyword search modal with the Ask AI Sidepanel experience. It allows users to start an AI interaction within the search modal (scanning keyword results) and then seamlessly transition that conversation into a Sidepanel for a continuous, side-by-side experience.

    During the handoff, the prompt and its identifiers are carried over so the conversation context is preserved. The handoff uses an InitialAskAiMessage object containing:

    • query: The text of the prompt.
    • messageId: An optional ID used to restore a locally stored conversation.
    • suggestedQuestionId: An optional ID used to identify which suggested question was selected in Agent Studio.
  5. Mobile behavior in Hybrid mode

    main

    To ensure a good user experience, Hybrid mode behaves differently on mobile devices (viewports matching (max-width: 768px)):

    • React: The DocSearch provider automatically detects mobile viewports. On mobile, Ask AI actions stay within the modal instead of moving to the Sidepanel. This prevents the conversation from being forced into a desktop-oriented layout. The decision is updated on window resize.
    • JavaScript: The JavaScript packages do not share a provider, so they do not apply this mobile logic automatically. If you want consistent behavior, you must manually implement a matchMedia check within your interceptAskAiEvent callback, as shown in the JavaScript integration guide.
    • Sidepanel Focus: On mobile, the Sidepanel avoids automatically focusing the prompt to prevent the virtual keyboard from disrupting the layout.
  6. Understand Agent Studio response feedback ratings

    main

    DocSearch v5 automatically includes feedback controls for completed Agent Studio answers.

    • Positive Feedback (Thumbs up): Submits immediately with a value of { thumbs: 1 }.
    • Negative Feedback (Thumbs down): Opens a form where users can select zero or more reason tags and an optional note. The payload structure is:
      {
        thumbs: 0;
        tags?: AskAiFeedbackReason[];
        notes?: string;
      }

    Constraints and Behavior:

    • Reason tags and notes are only collected for negative feedback.
    • Notes are trimmed, omitted if empty, and limited to 1,000 characters.
    • Submitting without a reason or note is valid.
    • Closing or canceling the form does not submit feedback.
    • To enable feedback, use an API key with the search ACL. You do not need to explicitly add an askAi option to enable the controls themselves.
  7. Structure content hierarchy for DocSearch

    main

    DocSearch uses heading hierarchy to build hierarchy.lvl0 through hierarchy.lvl6. This structure is used to improve result relevance and, in v5, to render result breadcrumbs.

    Best Practices:

    • Use an ordered heading hierarchy (e.g., <h1> through <h6>).
    • Avoid skipping levels to ensure each result retains its page context.
    • For large pages, aim for at least three levels of depth (e.g., lvl0 to lvl3).
    • If you don't use standard <hX> elements, you can use classes like <span class="title-X"> to represent hierarchy.
  8. Manage API keys for DocSearch

    main

    Security and Sharing

    The apiKey provided by the DocSearch team is a search-only API key. It is safe to include this key in your public repository and version control.

    Warning: If you decide to run the scraper yourself, ensure you create a search-only key and never share your Admin API key.

    Key Differences

    Every Algolia application has a default "Search API Key" in the dashboard that can list indices and retrieve settings. However, for DocSearch applications, the acceptance email contains a specific search-only API key scoped strictly to your DocSearch index. If you lose this key, you must contact Algolia support.

    Key Rotation

    To rotate your API keys, you must contact Algolia support.