Skip to content

feat(vertexai): Add sample retail_v2_search_request#5521

Open
amcolin wants to merge 4 commits intoGoogleCloudPlatform:mainfrom
amcolin:add-vertex-search-samples
Open

feat(vertexai): Add sample retail_v2_search_request#5521
amcolin wants to merge 4 commits intoGoogleCloudPlatform:mainfrom
amcolin:add-vertex-search-samples

Conversation

@amcolin
Copy link
Copy Markdown
Contributor

@amcolin amcolin commented Apr 15, 2026

Description

This PR adds Go implementation parity for the search samples introduced in python-docs-samples #13996.

Changes

  • New Snippets: Added searchRequest, searchOffset and searchPagination Go samples.
  • Module Setup: Initialized the retail Go module and v2 dependencies.

Fixes Internal b/502581509

For the new test

It needs API enabled for Vertex Search as it is mentioned on the test that are failing:

=== RUN   Test_searchRequest
    search_request_test.go:31: unexpected error: it.Next: rpc error: code = PermissionDenied desc = Vertex AI Search for commerce API has not been used in project 176007320581 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/retail.googleapis.com/overview?project=176007320581 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
        error details: name = ErrorInfo reason = SERVICE_DISABLED domain = googleapis.com metadata = map[activationUrl:https://console.developers.google.com/apis/api/retail.googleapis.com/overview?project=176007320581 consumer:projects/176007320581 containerInfo:176007320581 service:retail.googleapis.com serviceTitle:Vertex AI Search for commerce API]
        error details: name = Help desc = Google developers console API activation url = https://console.developers.google.com/apis/api/retail.googleapis.com/overview?project=176007320581
        error details: name = LocalizedMessage locale = en-US msg = Vertex AI Search for commerce API has not been used in project 176007320581 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/retail.googleapis.com/overview?project=176007320581 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.

Checklist

  • I have followed Contributing Guidelines from CONTRIBUTING.MD
  • Tests pass: go test -v ./.. (see Testing)
  • Code formatted: gofmt (see Formatting)
  • Vetting pass: go vet (see Formatting)
  • These samples need a new API enabled in testing projects to pass (let us know which ones)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved

@product-auto-label product-auto-label Bot added the samples Issues that are directly related to samples. label Apr 15, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new retail package within the vertexai directory, providing a sample implementation for searching products using the Google Cloud Retail API. The feedback focuses on fixing a bug in the search result iteration that could cause an infinite loop, improving the API design by passing a context parameter to the search function, and correcting documentation typos.

Comment thread vertexai/retail/search_request.go
Comment thread vertexai/retail/search_request.go Outdated
Comment thread vertexai/retail/search_request.go
Comment thread vertexai/retail/search_request_test.go
Comment thread vertexai/retail/search_request_test.go
@amcolin amcolin force-pushed the add-vertex-search-samples branch from f8ee201 to be91ae2 Compare April 16, 2026 16:50
@amcolin amcolin force-pushed the add-vertex-search-samples branch from be91ae2 to 4a7f3da Compare April 16, 2026 16:59
@amcolin
Copy link
Copy Markdown
Contributor Author

amcolin commented Apr 16, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new retail package within the vertexai directory, providing sample implementations for product searching using Vertex AI Search for commerce. It includes the searchOffset and searchRequest functions, which support text and browse searches with pagination, along with their respective unit tests. Review feedback identified inconsistencies in the function documentation where parameter descriptions and order did not match the actual code signatures.

Comment thread vertexai/retail/search_offset.go Outdated
Comment thread vertexai/retail/search_request.go Outdated
@amcolin amcolin force-pushed the add-vertex-search-samples branch from b47c529 to b37ea03 Compare April 16, 2026 17:38
@amcolin
Copy link
Copy Markdown
Contributor Author

amcolin commented Apr 17, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new retail package within the vertexai directory, providing sample implementations for product search functionality using the Vertex AI Retail API. The added samples demonstrate how to perform search requests with offsets, handle pagination using page tokens, and execute general text or browse searches. Feedback is provided to correct a typo in a documentation comment and to improve error handling by utilizing the %w verb for error wrapping in Go, as well as fixing a misleading error message in the pagination logic.

Comment thread vertexai/retail/search_offset.go Outdated
Comment thread vertexai/retail/search_pagination.go Outdated
Comment thread vertexai/retail/search_pagination.go Outdated
@amcolin amcolin force-pushed the add-vertex-search-samples branch from 43cbf38 to 59ebbac Compare April 17, 2026 18:52
@amcolin amcolin marked this pull request as ready for review April 17, 2026 19:50
@amcolin amcolin requested review from a team as code owners April 17, 2026 19:50
@snippet-bot
Copy link
Copy Markdown

snippet-bot Bot commented Apr 17, 2026

Here is the summary of changes.

You are about to add 3 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants