Skip to content

Commit

Permalink
feat: add lite search API to allow public website search with API key (
Browse files Browse the repository at this point in the history
…#7765)

* try comparing from origin

* 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
PiperOrigin-RevId: 689588291
Source-Link: googleapis/googleapis@537fd48
Source-Link: googleapis/googleapis-gen@186fcc4
Copy-Tag: eyJwIjoiRGlzY292ZXJ5RW5naW5lLy5Pd2xCb3QueWFtbCIsImgiOiIxODZmY2M0ZTIwYTJjMDZiYjUxNGEyZmY4ZDk0ZWI3ZjdkNjQ3MGMzIn0=

Co-authored-by: Brent Shaffer <[email protected]>
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 31, 2024
1 parent 5271d4e commit 0bd701e
Show file tree
Hide file tree
Showing 14 changed files with 351 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/backwards-compatibility-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
# OwlBot PRs which are not labelled feat should not add new files or methods
run: |
~/.composer/vendor/bin/roave-backward-compatibility-check \
--from=${{ github.head_ref || github.ref_name }} \
--from=origin/${{ github.head_ref || github.ref_name }} \
--to=origin/main --format=github-actions
- name: "Print the action item"
run: |
Expand Down
Binary file modified DiscoveryEngine/metadata/V1/Answer.php
Binary file not shown.
Binary file modified DiscoveryEngine/metadata/V1/Control.php
Binary file not shown.
Binary file modified DiscoveryEngine/metadata/V1/SearchService.php
Binary file not shown.
98 changes: 98 additions & 0 deletions DiscoveryEngine/samples/V1/SearchServiceClient/search_lite.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START discoveryengine_v1_generated_SearchService_SearchLite_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\DiscoveryEngine\V1\Client\SearchServiceClient;
use Google\Cloud\DiscoveryEngine\V1\SearchRequest;
use Google\Cloud\DiscoveryEngine\V1\SearchResponse\SearchResult;

/**
* 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.
*
* @param string $formattedServingConfig The resource name of the Search serving config, such as
* `projects/&#42;/locations/global/collections/default_collection/engines/&#42;/servingConfigs/default_serving_config`,
* or
* `projects/&#42;/locations/global/collections/default_collection/dataStores/default_data_store/servingConfigs/default_serving_config`.
* This field is used to identify the serving configuration name, set
* of models used to make the search. Please see
* {@see SearchServiceClient::servingConfigName()} for help formatting this field.
*/
function search_lite_sample(string $formattedServingConfig): void
{
// Create a client.
$searchServiceClient = new SearchServiceClient();

// Prepare the request message.
$request = (new SearchRequest())
->setServingConfig($formattedServingConfig);

// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $searchServiceClient->searchLite($request);

/** @var SearchResult $element */
foreach ($response as $element) {
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}

/**
* Helper to execute the sample.
*
* This sample 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,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedServingConfig = SearchServiceClient::servingConfigName(
'[PROJECT]',
'[LOCATION]',
'[DATA_STORE]',
'[SERVING_CONFIG]'
);

search_lite_sample($formattedServingConfig);
}
// [END discoveryengine_v1_generated_SearchService_SearchLite_sync]
9 changes: 9 additions & 0 deletions DiscoveryEngine/src/V1/Answer/AnswerSkippedReason.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions DiscoveryEngine/src/V1/Client/SearchServiceClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
* contained within formatted names that are returned by the API.
*
* @method PromiseInterface searchAsync(SearchRequest $request, array $optionalArgs = [])
* @method PromiseInterface searchLiteAsync(SearchRequest $request, array $optionalArgs = [])
*/
final class SearchServiceClient
{
Expand Down Expand Up @@ -573,4 +574,42 @@ public function search(SearchRequest $request, array $callOptions = []): PagedLi
{
return $this->startApiCall('Search', $request, $callOptions);
}

/**
* 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.
*
* The async variant is {@see SearchServiceClient::searchLiteAsync()} .
*
* @example samples/V1/SearchServiceClient/search_lite.php
*
* @param SearchRequest $request A request to house fields associated with the call.
* @param array $callOptions {
* Optional.
*
* @type RetrySettings|array $retrySettings
* Retry settings to use for this call. Can be a {@see RetrySettings} object, or an
* associative array of retry settings parameters. See the documentation on
* {@see RetrySettings} for example usage.
* }
*
* @return PagedListResponse
*
* @throws ApiException Thrown if the API call fails.
*/
public function searchLite(SearchRequest $request, array $callOptions = []): PagedListResponse
{
return $this->startApiCall('SearchLite', $request, $callOptions);
}
}
58 changes: 58 additions & 0 deletions DiscoveryEngine/src/V1/Condition.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions DiscoveryEngine/src/V1/gapic_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
"methods": [
"search"
]
},
"SearchLite": {
"methods": [
"searchLite"
]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
"timeout_millis": 30000,
"retry_codes_name": "retry_policy_2_codes",
"retry_params_name": "retry_policy_2_params"
},
"SearchLite": {
"timeout_millis": 30000,
"retry_codes_name": "retry_policy_2_codes",
"retry_params_name": "retry_policy_2_params"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@
],
],
],
'SearchLite' => [
'pageStreaming' => [
'requestPageTokenGetMethod' => 'getPageToken',
'requestPageTokenSetMethod' => 'setPageToken',
'requestPageSizeGetMethod' => 'getPageSize',
'requestPageSizeSetMethod' => 'setPageSize',
'responsePageTokenGetMethod' => 'getNextPageToken',
'resourcesGetMethod' => 'getResults',
],
'callType' => \Google\ApiCore\Call::PAGINATED_CALL,
'responseType' => 'Google\Cloud\DiscoveryEngine\V1\SearchResponse',
'headerParams' => [
[
'keyName' => 'serving_config',
'fieldAccessors' => [
'getServingConfig',
],
],
],
],
'templateMap' => [
'branch' => 'projects/{project}/locations/{location}/dataStores/{data_store}/branches/{branch}',
'dataStore' => 'projects/{project}/locations/{location}/dataStores/{data_store}',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,30 @@
],
],
],
'SearchLite' => [
'method' => 'post',
'uriTemplate' => '/v1/{serving_config=projects/*/locations/*/dataStores/*/servingConfigs/*}:searchLite',
'body' => '*',
'additionalBindings' => [
[
'method' => 'post',
'uriTemplate' => '/v1/{serving_config=projects/*/locations/*/collections/*/dataStores/*/servingConfigs/*}:searchLite',
'body' => '*',
],
[
'method' => 'post',
'uriTemplate' => '/v1/{serving_config=projects/*/locations/*/collections/*/engines/*/servingConfigs/*}:searchLite',
'body' => '*',
],
],
'placeholders' => [
'serving_config' => [
'getters' => [
'getServingConfig',
],
],
],
],
],
'google.longrunning.Operations' => [
'CancelOperation' => [
Expand Down
Loading

0 comments on commit 0bd701e

Please sign in to comment.