IWebSearchService

Overview

The IWebSearchService offers web search capabilities. Currently, the only implemented consumer of this service is the WebSearchTools. However, you can also incorporate this service into your own tools as needed.

Implementing this service is straightforward, as it requires only a single property and one method. The property, MaxSites, is used to limit the number of search results returned. The SearchAsync(query) method is responsible for returning the search results.

The result is a single string that is included in the RAG (Retrieve-and-Generate) context. You can format this string as you wish, but it's essential that the AI can discern both the URL and a snippet or abstract text from it. The built-in services typically format the result as follows:

URL: url
Abstract: text
===

Default Implementation

The IWebSearchService interface offers several built-in implementations: BingWebSearchService, BraveWebSearchService, and GoogleWebSearchService.

You can download the BingWebSearchService implementation below, which serves as a basic guideline for setting up your own web search service.

internal static class Program
{
  static Program()
  {
    Application.Services
      .AddOrReplaceService<IWebSearchService, MySerpAPIService>();
  }
}

Last updated