Class GoogleCustomWebSearchEngine

java.lang.Object
dev.langchain4j.web.search.google.customsearch.GoogleCustomWebSearchEngine
All Implemented Interfaces:
WebSearchEngine

public class GoogleCustomWebSearchEngine extends Object implements WebSearchEngine
An implementation of a WebSearchEngine that uses Google Custom Search API for performing web searches.
  • Constructor Details

    • GoogleCustomWebSearchEngine

      public GoogleCustomWebSearchEngine(String apiKey, String csi, Boolean siteRestrict, Boolean includeImages, Duration timeout, Integer maxRetries, Boolean logRequests, Boolean logResponses)
      Constructs a new GoogleCustomWebSearchEngine with the specified parameters.
      Parameters:
      apiKey - the Google Search API key for accessing the Google Custom Search API

      You can just generate an API key here

      csi - the Custom Search ID parameter for search the entire web

      You can create a Custom Search Engine here

      siteRestrict - if your Search Engine is restricted to only searching specific sites, you can set this parameter to true.

      Default value is false. View the documentation for more information here

      includeImages - If it is true then include public images relevant to the query. This can add more latency to the search.

      Default value is false.

      timeout - the timeout duration for API requests

      Default value is 60 seconds.

      maxRetries - the maximum number of retries for API requests

      Default value is 10.

      logRequests - whether to log API requests

      Default value is false.

      logResponses - whether to log API responses

      Default value is false.

  • Method Details

    • withApiKeyAndCsi

      public static GoogleCustomWebSearchEngine withApiKeyAndCsi(String apiKey, String csi)
      Creates a new builder for constructing a GoogleCustomWebSearchEngine with the specified API key and Custom Search ID.
      Parameters:
      apiKey - the API key for accessing the Google Custom Search API
      csi - the Custom Search ID parameter for search the entire web
      Returns:
      a new builder instance
    • 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 - the search request
      Returns:
      the web search results