Skip to Content
Widgets & Integrations🔎 Search Widget

Search Widget

Introduction

The DocsGPT Search Bar Widget offers a simple yet powerful way to embed AI-powered document search directly into your web applications. This widget allows users to perform searches across your documents or pages, enabling them to quickly find the information they need. This guide will walk you through embedding the Search Bar Widget into your projects, whether you’re using React or plain HTML.

Try out the interactive widget showcase and customize its parameters at the DocsGPT Widget Demo .

Setup

React Setup

Installation

Make sure you have Node.js and npm (or yarn, pnpm) installed in your project. Navigate to your project directory in the terminal and install the docsgpt package:

npm install docsgpt

Usage

In your React component file, import the SearchBar component:

import { SearchBar } from "docsgpt";

Now, you can embed the widget within your React component’s JSX:

<SearchBar apiKey="your-agent-api-key" apiHost="https://gptcloud.arc53.com" theme="light" placeholder="Search or Ask AI..." width="300px" />

Properties Table

The DocsGPT Search Bar Widget offers a range of customizable properties that allow you to tailor its appearance and behavior to perfectly match your web application. These parameters can be modified directly when embedding the widget in your React components or HTML code. Below is a detailed overview of each available prop:

PropTypeDefault ValueDescription
apiKeystringa DocsGPT demo agent’s keyRequired. The API key of your published agent (see Agent API keys). Search runs over that agent’s knowledge. An empty key gets 400 api_key is required, and an omitted key searches a public DocsGPT demo agent.
apiHoststring"https://gptcloud.arc53.com"The URL of your DocsGPT API backend (DocsGPT Cloud by default). Self-hosted: your API URL, e.g. http://localhost:7091.
theme"dark" | "light""dark"Color theme of the search bar and of the chat it opens. Options: "dark" or "light". Defaults to "dark".
placeholderstring"Search or Ask AI..."Placeholder of the input inside the search dialog (modal variant), and the accessible name of the search field.
widthstring"256px"Width of the search bar. Accepts any valid CSS width value (e.g., "300px", "100%", "20rem").
buttonTextstring"Search here"Text in the search field on the page: the label of the button that opens the dialog (modal), or the field’s placeholder (dropdown).
variant"modal" | "dropdown""modal"How the results open. modal opens a search dialog from a button; dropdown is a field you type into, with the results in a panel under it. See Modal or dropdown.
shape"pill" | "rounded""pill"Corners of the search field: fully rounded, or the smaller 8px corners of a form field.
avatarstringa person on the brand-colour circleURL for the image beside “Ask the AI”, also used in the header of the chat it opens.
poweredByboolean | { label: string; href?: string }trueThe credit line at the bottom of the results. true shows “Powered by DocsGPT”, false hides it, and an object replaces it, e.g. { label: 'Powered by Acme', href: 'https://acme.example' }. The chat opened from “Ask the AI” uses the same value.
allowedFileExtensionsstring[]unsetPassed to the chat opened from “Ask the AI”. File extensions its composer accepts, e.g. ['.pdf', '.md']; attachments stay off while unset. See the chat widget page.
showMicButtonbooleanfalseAdds a microphone to the search field for dictating a query, and passes the same option to the chat opened from “Ask the AI”. Uses the browser’s Web Speech API. See the chat widget page.

With the default variant: 'modal', the search field on your page is a button. Selecting it, or pressing ⌘K (Ctrl K on Windows and Linux), opens a search dialog over the page. On a phone the dialog opens as a sheet from the bottom of the screen, above the keyboard.

With variant: 'dropdown', visitors type straight into the field on your page. ⌘K (Ctrl K) focuses it, and the results open in a panel under the field once there is something to search for. The panel stays inside the screen, and closes on Esc, a click elsewhere, or moving focus away.

<SearchBar apiKey="your-agent-api-key" variant="dropdown" shape="rounded" buttonText="Search the docs" width="320px" />

Both work the same way inside:

  • The first row is Ask the AI. Selecting it, or pressing Enter, opens the chat with the query already asked.
  • The arrow keys move between rows, and Enter opens the highlighted one.
  • A result from a web page shows its title and the matching lines, and opens the page in a new tab.
  • A result from an uploaded file shows the same, but is not a link, because a visitor has no way to open a file from your library.

Notes on Widget Properties

  • Full Customization: Every property listed in the table can be customized. Override the defaults to create a Search Bar Widget that perfectly matches your branding and application context.
  • API Key Handling: The search bar needs the API key of a published agent; /api/search rejects requests without one. See Agent API keys. If you leave apiKey out, the search bar falls back to a built-in key for a public DocsGPT demo agent: on DocsGPT Cloud it searches that demo agent’s knowledge instead of yours, and on a self-hosted instance the key is invalid and searches fail. apiHost for DocsGPT Cloud is https://gptcloud.arc53.com.

Explore and Customize Further

The DocsGPT Search Bar Widget is fully open-source, allowing for deep customization and extension beyond the readily available props.

The complete source code for the React-based widget is available in the extensions/react-widget directory within the main DocsGPT GitHub Repository . Feel free to explore the code, fork the repository, and tailor the widget to your exact requirements.

Last updated on