Ui componentsCustomization guides

Search and Chat Filters

Dynamically filter the search and chat results.

Scenario

In this guide, we'll explore how to filter the search and chat results using custom tags and attributes. This allows you to tailor the search experience based on specific criteria, such as product versions or SDKs. By using filters, you can ensure that users only see relevant results based on their current context or preferences.

Filters

Filters can be defined using the filters property of the InkeepBaseSettings interface. These filters will apply to both the search and chat experiences. Alternatively you can also define filters in the InkeepSearchSettings and InkeepChatSettings interfaces to apply them only to the search or chat experience respectively.

export interface SearchAndChatFilters {
  attributes?: {
    [key: string]: any;
  };
}

Supported Operators

Comparison Operators: $eq, $ne, $gt, $gte, $lt, $lte
Array Operators: $in, $nin
Boolean Operators: $exists
Logical Operators: $and, $or

Filter by custom tags and attributes

A common filter scenario is you have docs that covers many products, versions, and SDKs.

The first part to setting up filters is to add <meta> tags prefixed with inkeep: to each page. For example:

<meta name="inkeep:version" content="latest" />
<meta name="inkeep:sdk" content="react" />

Then to filter the search and chat with your custom tags version and sdk:

const baseSettings: InkeepBaseSettings = {
  // ...
  filters: {
    attributes: {
      "$and": [{ version: { $in: ["latest"] } }, { sdk: { $in: ["react", "vue"] } }]
    }
  },
};

Filters can be dynamically generated based on the page the user is on, giving full control over the search and chat experience.

Filter by source id

You can also filter by source id. This is useful if you want to show only specific sources in the search and chat results. You can find the source id in the Inkeep Dashboard by going to the Sources tab, then selecting the particular source you would like to get the id for.

const baseSettings: InkeepBaseSettings = {
  // ...
  filters: {
    attributes: {
      source_id: sourceId,
    }
  },
};

To filter by multiple source ids, you can use the $or operator like so:

const baseSettings: InkeepBaseSettings = {
  // ...
  filters: {
    attributes: {
      "$or": [{
        source_id: sourceId1
      }, {
        source_id: sourceId2
      }]
    }
  },
};

On this page