diff --git a/libs/langchain/langchain/retrievers/google_cloud_enterprise_search.py b/libs/langchain/langchain/retrievers/google_cloud_enterprise_search.py index b609317a33..cab8c02d0b 100644 --- a/libs/langchain/langchain/retrievers/google_cloud_enterprise_search.py +++ b/libs/langchain/langchain/retrievers/google_cloud_enterprise_search.py @@ -56,6 +56,16 @@ class GoogleCloudEnterpriseSearchRetriever(BaseRetriever): SearchResponse.total_size is zero. 2 - Automatic query expansion built by the Search API. """ + spell_correction_mode: int = Field(default=2, ge=0, le=2) + """Specification to determine under which conditions query expansion should occur. + 0 - Unspecified spell correction mode. In this case, server behavior defaults + to auto. + 1 - Suggestion only. Search API will try to find a spell suggestion if there is any + and put in the `SearchResponse.corrected_query`. + The spell suggestion will not be used as the search query. + 2 - Automatic spell correction built by the Search API. + Search will be based on the corrected query if found. + """ credentials: Any = None """The default custom credentials (google.auth.credentials.Credentials) to use when making API calls. If not provided, credentials will be ascertained from @@ -134,6 +144,10 @@ class GoogleCloudEnterpriseSearchRetriever(BaseRetriever): condition=self.query_expansion_condition, ) + spell_correction_spec = SearchRequest.SpellCorrectionSpec( + mode=self.spell_correction_mode + ) + if self.get_extractive_answers: extractive_content_spec = ( SearchRequest.ContentSearchSpec.ExtractiveContentSpec( @@ -158,6 +172,7 @@ class GoogleCloudEnterpriseSearchRetriever(BaseRetriever): page_size=self.max_documents, content_search_spec=content_search_spec, query_expansion_spec=query_expansion_spec, + spell_correction_spec=spell_correction_spec, ) def _get_relevant_documents(