Class SearchApiWebSearchEngine

java.lang.Object
dev.langchain4j.web.search.searchapi.SearchApiWebSearchEngine
All Implemented Interfaces:
WebSearchEngine

public class SearchApiWebSearchEngine extends Object implements WebSearchEngine
An implementation of a WebSearchEngine that uses Search API for performing web searches.

Search API supports not only Google Search, but many other engines

  • Constructor Details

    • SearchApiWebSearchEngine

      public SearchApiWebSearchEngine(String apiKey, String baseUrl, Duration timeout, String engine, Map<String,Object> optionalParameters)
      Parameters:
      apiKey - Required - the Search API key for accessing their API
      baseUrl - overrides the default SearchApi base url
      timeout - the timeout duration for API requests

      Default value is 30 seconds.

      engine - the engine used by Search API to execute the search

      Default engine is Google Search.

      optionalParameters - parameters to be passed on every request of this the engine, they can be overridden by the WebSearchRequest additional parameters for matching keys

      Check Search API for more information on available parameters for each engine

  • Method Details

    • search

      public WebSearchResults search(WebSearchRequest webSearchRequest)
      Description copied from interface: WebSearchEngine
      Performs a search request on the web search engine and returns the search results.
      Specified by:
      search in interface WebSearchEngine
      Parameters:
      webSearchRequest - Check Search API for more information on available additional parameters for each engine that can be inside the request
      Returns:
      the web search results
    • withApiKey

      public static WebSearchEngine withApiKey(String apiKey)