Skip to content

Commit

Permalink
feat: [google-cloud-discoveryengine] add lite search API to allow pub…
Browse files Browse the repository at this point in the history
…lic website search with API key (#13216)

- [ ] Regenerate this pull request now.

BEGIN_COMMIT_OVERRIDE
feat: add lite search API to allow public website search with API key
feat: add LOW_GROUNDED_ANSWER in answer skip reasons
feat: support query regex in control match rules
docs: keep the API doc up-to-date with recent changes
END_COMMIT_OVERRIDE


PiperOrigin-RevId: 689588291

Source-Link:
googleapis/googleapis@537fd48

Source-Link:
googleapis/googleapis-gen@186fcc4
Copy-Tag:
eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLWRpc2NvdmVyeWVuZ2luZS8uT3dsQm90LnlhbWwiLCJoIjoiMTg2ZmNjNGUyMGEyYzA2YmI1MTRhMmZmOGQ5NGViN2Y3ZDY0NzBjMyJ9

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
gcf-owl-bot[bot] and gcf-owl-bot[bot] authored Oct 25, 2024
1 parent 7d0c200 commit 365d55d
Show file tree
Hide file tree
Showing 24 changed files with 1,872 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
__version__ = "0.13.1" # {x-release-please-version}
__version__ = "0.0.0" # {x-release-please-version}
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,11 @@
"methods": [
"search"
]
},
"SearchLite": {
"methods": [
"search_lite"
]
}
}
},
Expand All @@ -1013,6 +1018,11 @@
"methods": [
"search"
]
},
"SearchLite": {
"methods": [
"search_lite"
]
}
}
},
Expand All @@ -1023,6 +1033,11 @@
"methods": [
"search"
]
},
"SearchLite": {
"methods": [
"search_lite"
]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
__version__ = "0.13.1" # {x-release-please-version}
__version__ = "0.0.0" # {x-release-please-version}
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,123 @@ async def sample_search():
# Done; return the response.
return response

async def search_lite(
self,
request: Optional[Union[search_service.SearchRequest, dict]] = None,
*,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> pagers.SearchLiteAsyncPager:
r"""Performs a search. Similar to the
[SearchService.Search][google.cloud.discoveryengine.v1.SearchService.Search]
method, but a lite version that allows API key for
authentication, where OAuth and IAM checks are not required.
Only public website search is supported by this method. If data
stores and engines not associated with public website search are
specified, a ``FAILED_PRECONDITION`` error is returned.
This method can be used for easy onboarding without having to
implement an authentication backend. However, it is strongly
recommended to use
[SearchService.Search][google.cloud.discoveryengine.v1.SearchService.Search]
instead with required OAuth and IAM checks to provide better
data security.
.. code-block:: python
# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in:
# https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import discoveryengine_v1
async def sample_search_lite():
# Create a client
client = discoveryengine_v1.SearchServiceAsyncClient()
# Initialize request argument(s)
request = discoveryengine_v1.SearchRequest(
serving_config="serving_config_value",
)
# Make the request
page_result = client.search_lite(request=request)
# Handle the response
async for response in page_result:
print(response)
Args:
request (Optional[Union[google.cloud.discoveryengine_v1.types.SearchRequest, dict]]):
The request object. Request message for
[SearchService.Search][google.cloud.discoveryengine.v1.SearchService.Search]
method.
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
should be retried.
timeout (float): The timeout for this request.
metadata (Sequence[Tuple[str, str]]): Strings which should be
sent along with the request as metadata.
Returns:
google.cloud.discoveryengine_v1.services.search_service.pagers.SearchLiteAsyncPager:
Response message for
[SearchService.Search][google.cloud.discoveryengine.v1.SearchService.Search]
method.
Iterating over this object will yield results and
resolve additional pages automatically.
"""
# Create or coerce a protobuf request object.
# - Use the request object if provided (there's no risk of modifying the input as
# there are no flattened fields), or create one.
if not isinstance(request, search_service.SearchRequest):
request = search_service.SearchRequest(request)

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = self._client._transport._wrapped_methods[
self._client._transport.search_lite
]

# Certain fields should be provided within the metadata header;
# add these here.
metadata = tuple(metadata) + (
gapic_v1.routing_header.to_grpc_metadata(
(("serving_config", request.serving_config),)
),
)

# Validate the universe domain.
self._client._validate_universe_domain()

# Send the request.
response = await rpc(
request,
retry=retry,
timeout=timeout,
metadata=metadata,
)

# This method is paged; wrap the response in a pager, which provides
# an `__aiter__` convenience method.
response = pagers.SearchLiteAsyncPager(
method=rpc,
request=request,
response=response,
retry=retry,
timeout=timeout,
metadata=metadata,
)

# Done; return the response.
return response

async def list_operations(
self,
request: Optional[operations_pb2.ListOperationsRequest] = None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,121 @@ def sample_search():
# Done; return the response.
return response

def search_lite(
self,
request: Optional[Union[search_service.SearchRequest, dict]] = None,
*,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> pagers.SearchLitePager:
r"""Performs a search. Similar to the
[SearchService.Search][google.cloud.discoveryengine.v1.SearchService.Search]
method, but a lite version that allows API key for
authentication, where OAuth and IAM checks are not required.
Only public website search is supported by this method. If data
stores and engines not associated with public website search are
specified, a ``FAILED_PRECONDITION`` error is returned.
This method can be used for easy onboarding without having to
implement an authentication backend. However, it is strongly
recommended to use
[SearchService.Search][google.cloud.discoveryengine.v1.SearchService.Search]
instead with required OAuth and IAM checks to provide better
data security.
.. code-block:: python
# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in:
# https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import discoveryengine_v1
def sample_search_lite():
# Create a client
client = discoveryengine_v1.SearchServiceClient()
# Initialize request argument(s)
request = discoveryengine_v1.SearchRequest(
serving_config="serving_config_value",
)
# Make the request
page_result = client.search_lite(request=request)
# Handle the response
for response in page_result:
print(response)
Args:
request (Union[google.cloud.discoveryengine_v1.types.SearchRequest, dict]):
The request object. Request message for
[SearchService.Search][google.cloud.discoveryengine.v1.SearchService.Search]
method.
retry (google.api_core.retry.Retry): Designation of what errors, if any,
should be retried.
timeout (float): The timeout for this request.
metadata (Sequence[Tuple[str, str]]): Strings which should be
sent along with the request as metadata.
Returns:
google.cloud.discoveryengine_v1.services.search_service.pagers.SearchLitePager:
Response message for
[SearchService.Search][google.cloud.discoveryengine.v1.SearchService.Search]
method.
Iterating over this object will yield results and
resolve additional pages automatically.
"""
# Create or coerce a protobuf request object.
# - Use the request object if provided (there's no risk of modifying the input as
# there are no flattened fields), or create one.
if not isinstance(request, search_service.SearchRequest):
request = search_service.SearchRequest(request)

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = self._transport._wrapped_methods[self._transport.search_lite]

# Certain fields should be provided within the metadata header;
# add these here.
metadata = tuple(metadata) + (
gapic_v1.routing_header.to_grpc_metadata(
(("serving_config", request.serving_config),)
),
)

# Validate the universe domain.
self._validate_universe_domain()

# Send the request.
response = rpc(
request,
retry=retry,
timeout=timeout,
metadata=metadata,
)

# This method is paged; wrap the response in a pager, which provides
# an `__iter__` convenience method.
response = pagers.SearchLitePager(
method=rpc,
request=request,
response=response,
retry=retry,
timeout=timeout,
metadata=metadata,
)

# Done; return the response.
return response

def __enter__(self) -> "SearchServiceClient":
return self

Expand Down
Loading

0 comments on commit 365d55d

Please sign in to comment.