Skip to content

Commit ceaabc8

Browse files
feat: [AiPlatform] add AskContexts and AsyncRetrieveContexts APIs to VertexRagService (#8960)
* feat: add AskContexts and AsyncRetrieveContexts APIs to VertexRagService PiperOrigin-RevId: 877654221 Source-Link: googleapis/googleapis@e50da27 Source-Link: googleapis/googleapis-gen@c95cf17 Copy-Tag: eyJwIjoiQWlQbGF0Zm9ybS8uT3dsQm90LnlhbWwiLCJoIjoiYzk1Y2YxNzNiNjgzZTc1MzdjY2VjZjM0MjUzM2VmN2JjYmZlMjBmNiJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 9bfe824 commit ceaabc8

14 files changed

Lines changed: 1191 additions & 5 deletions
1.36 KB
Binary file not shown.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/*
3+
* Copyright 2026 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/*
19+
* GENERATED CODE WARNING
20+
* This file was automatically generated - do not edit!
21+
*/
22+
23+
require_once __DIR__ . '/../../../vendor/autoload.php';
24+
25+
// [START aiplatform_v1_generated_VertexRagService_AskContexts_sync]
26+
use Google\ApiCore\ApiException;
27+
use Google\Cloud\AIPlatform\V1\AskContextsRequest;
28+
use Google\Cloud\AIPlatform\V1\AskContextsResponse;
29+
use Google\Cloud\AIPlatform\V1\Client\VertexRagServiceClient;
30+
use Google\Cloud\AIPlatform\V1\RagQuery;
31+
32+
/**
33+
* Agentic Retrieval Ask API for RAG.
34+
*
35+
* @param string $formattedParent The resource name of the Location from which to retrieve
36+
* RagContexts. The users must have permission to make a call in the project.
37+
* Format:
38+
* `projects/{project}/locations/{location}`. Please see
39+
* {@see VertexRagServiceClient::locationName()} for help formatting this field.
40+
*/
41+
function ask_contexts_sample(string $formattedParent): void
42+
{
43+
// Create a client.
44+
$vertexRagServiceClient = new VertexRagServiceClient();
45+
46+
// Prepare the request message.
47+
$query = new RagQuery();
48+
$request = (new AskContextsRequest())
49+
->setParent($formattedParent)
50+
->setQuery($query);
51+
52+
// Call the API and handle any network failures.
53+
try {
54+
/** @var AskContextsResponse $response */
55+
$response = $vertexRagServiceClient->askContexts($request);
56+
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
57+
} catch (ApiException $ex) {
58+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
59+
}
60+
}
61+
62+
/**
63+
* Helper to execute the sample.
64+
*
65+
* This sample has been automatically generated and should be regarded as a code
66+
* template only. It will require modifications to work:
67+
* - It may require correct/in-range values for request initialization.
68+
* - It may require specifying regional endpoints when creating the service client,
69+
* please see the apiEndpoint client configuration option for more details.
70+
*/
71+
function callSample(): void
72+
{
73+
$formattedParent = VertexRagServiceClient::locationName('[PROJECT]', '[LOCATION]');
74+
75+
ask_contexts_sample($formattedParent);
76+
}
77+
// [END aiplatform_v1_generated_VertexRagService_AskContexts_sync]
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
/*
3+
* Copyright 2026 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/*
19+
* GENERATED CODE WARNING
20+
* This file was automatically generated - do not edit!
21+
*/
22+
23+
require_once __DIR__ . '/../../../vendor/autoload.php';
24+
25+
// [START aiplatform_v1_generated_VertexRagService_AsyncRetrieveContexts_sync]
26+
use Google\ApiCore\ApiException;
27+
use Google\ApiCore\OperationResponse;
28+
use Google\Cloud\AIPlatform\V1\AsyncRetrieveContextsRequest;
29+
use Google\Cloud\AIPlatform\V1\AsyncRetrieveContextsResponse;
30+
use Google\Cloud\AIPlatform\V1\Client\VertexRagServiceClient;
31+
use Google\Cloud\AIPlatform\V1\RagQuery;
32+
use Google\Rpc\Status;
33+
34+
/**
35+
* Asynchronous API to retrieves relevant contexts for a query.
36+
*
37+
* @param string $formattedParent The resource name of the Location from which to retrieve
38+
* RagContexts. The users must have permission to make a call in the project.
39+
* Format:
40+
* `projects/{project}/locations/{location}`. Please see
41+
* {@see VertexRagServiceClient::locationName()} for help formatting this field.
42+
*/
43+
function async_retrieve_contexts_sample(string $formattedParent): void
44+
{
45+
// Create a client.
46+
$vertexRagServiceClient = new VertexRagServiceClient();
47+
48+
// Prepare the request message.
49+
$query = new RagQuery();
50+
$request = (new AsyncRetrieveContextsRequest())
51+
->setParent($formattedParent)
52+
->setQuery($query);
53+
54+
// Call the API and handle any network failures.
55+
try {
56+
/** @var OperationResponse $response */
57+
$response = $vertexRagServiceClient->asyncRetrieveContexts($request);
58+
$response->pollUntilComplete();
59+
60+
if ($response->operationSucceeded()) {
61+
/** @var AsyncRetrieveContextsResponse $result */
62+
$result = $response->getResult();
63+
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
64+
} else {
65+
/** @var Status $error */
66+
$error = $response->getError();
67+
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
68+
}
69+
} catch (ApiException $ex) {
70+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
71+
}
72+
}
73+
74+
/**
75+
* Helper to execute the sample.
76+
*
77+
* This sample has been automatically generated and should be regarded as a code
78+
* template only. It will require modifications to work:
79+
* - It may require correct/in-range values for request initialization.
80+
* - It may require specifying regional endpoints when creating the service client,
81+
* please see the apiEndpoint client configuration option for more details.
82+
*/
83+
function callSample(): void
84+
{
85+
$formattedParent = VertexRagServiceClient::locationName('[PROJECT]', '[LOCATION]');
86+
87+
async_retrieve_contexts_sample($formattedParent);
88+
}
89+
// [END aiplatform_v1_generated_VertexRagService_AsyncRetrieveContexts_sync]

AiPlatform/src/V1/AskContextsRequest.php

Lines changed: 178 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)