Skip to content

feat(bigquery): add bigquery_vector_search sample to run approximate … - #14741

Open
iennae wants to merge 1 commit into
mainfrom
feat/bq-vector-search
Open

iennae wants to merge 1 commit into
mainfrom
feat/bq-vector-search

Conversation

@iennae

@iennae iennae commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

…nearest-neighbor vector search

Problem:
The BigQuery documentation (https://cloud.google.com/bigquery/docs/vector-search) needs a standalone, tested Python code sample demonstrating how to run approximate nearest-neighbor vector search (region tag bigquery_vector_search).

Solution:

  • Add vector_search(project_id: str, dataset_id: str, table_id: str) -> None in bigquery/vector_search/bigquery_vector_search.py (Find top-K nearest neighbors using VECTOR_SEARCH with an indexed embedding table and fraction_lists_to_search.)
  • Add unit tests (bigquery/vector_search/bigquery_vector_search_test.py) covering both the success path and API error handling (GoogleAPICallError)

Description

Fixes #

Checklist

Testing

  • I have tested this change on a live environment and verified it works as intended.

Compliance & Style


Post-Approval Actions

  • Please merge this PR for me once it is approved

@iennae
iennae requested review from a team and chalmerlowe as code owners November 2, 2026 23:24
@product-auto-label product-auto-label Bot added api: bigquery Issues related to the BigQuery API. samples Issues that are directly related to samples. labels Nov 2, 2026
@snippet-bot

snippet-bot Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 1 region tag.

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

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

Copy link
Copy Markdown
Contributor

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 Python sample for BigQuery Vector Search, including unit tests and configuration files. The feedback suggests removing the redundant Python version environment marker from the test requirements and updating the ignored_versions in the Nox configuration to ensure only the oldest (3.10) and newest (3.13) supported Python versions are tested.

@@ -0,0 +1 @@
pytest==9.0.3; python_version >= "3.10"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

According to the general rules, environment markers for Python versions older than 3.10 should not be specified because Python versions below 3.10 are no longer supported. The environment marker ; python_version >= "3.10" is redundant and can be removed.

pytest==9.0.3
References
  1. Do not specify fallback dependency versions or environment markers for Python versions older than 3.10, as Python versions below 3.10 are no longer supported.


TEST_CONFIG_OVERRIDE = {
# You can opt out from the test for specific Python versions.
"ignored_versions": ["2.7", "3.7", "3.8", "3.9", "3.10", "3.11"],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

According to the general rules, only the oldest and newest supported Python releases should be tested in test configurations, ignoring intermediate versions. Since Python 3.10 is the oldest supported version and Python 3.13 is the newest, we should test 3.10 and 3.13, while ignoring the intermediate versions 3.11 and 3.12.

Suggested change
"ignored_versions": ["2.7", "3.7", "3.8", "3.9", "3.10", "3.11"],
"ignored_versions": ["2.7", "3.7", "3.8", "3.9", "3.11", "3.12"],
References
  1. Only test the oldest and newest supported Python releases in test configurations (such as noxfile_config.py), ignoring intermediate versions.

@iennae
iennae force-pushed the feat/bq-vector-search branch 2 times, most recently from c6b71bc to 27e8348 Compare November 3, 2026 02:44
…nearest-neighbor vector search

Problem:
The BigQuery documentation (https://cloud.google.com/bigquery/docs/vector-search)
needs a standalone, tested Python code sample demonstrating how to
run approximate nearest-neighbor vector search (region tag `bigquery_vector_search`).

Solution:
- Add `vector_search(project_id: str, dataset_id: str, table_id: str) -> None` in `bigquery/vector_search/bigquery_vector_search.py`
  (Find top-K nearest neighbors using VECTOR_SEARCH with an indexed embedding table and fraction_lists_to_search.)
- Add unit tests (`bigquery/vector_search/bigquery_vector_search_test.py`) covering both the success
  path and API error handling (`GoogleAPICallError`)
@iennae
iennae force-pushed the feat/bq-vector-search branch from 27e8348 to 096f6cf Compare November 3, 2026 23:32

@XrossFox XrossFox left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, i have a nitpick, but no changes are neccessary.

def test_vector_search_success(
capsys: pytest.CaptureFixture[str],
) -> None:
with mock.patch("google.cloud.bigquery.Client") as mock_client_cls:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is more of a nitpick, not necessary to actually change the code. This should work, but patching should aim to modify the module's instance rather that the dependency, instead of patching "google.cloud.bigquery.Client", it should target "bigquery_vector_search.bigquery.Client", this could have side effects, but probably not a big deal in the current context.

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

Labels

api: bigquery Issues related to the BigQuery API. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants