Skip to content

feat(spanner): Add exact k-nearest neighbors vector search sample - #14836

Merged
iennae merged 3 commits into
mainfrom
feat/spanner-vector-search-knn
Dec 1, 2026
Merged

iennae merged 3 commits into
mainfrom
feat/spanner-vector-search-knn

Conversation

@iennae

@iennae iennae commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Description

Cloud Spanner vector search documentation shows SQL queries for exact k-nearest neighbors (COSINE_DISTANCE), but Python developers lacked a runnable client library reference demonstrating how to bind a FLOAT32 query embedding with param_types.Array(param_types.FLOAT32) inside a read snapshot.

Establishes the spanner/search_and_ai Python 3.13+ sample package and adds spanner_vector_search_knn with offline unit tests and gated live integration tests.

Checklist

Testing

  • I have tested this change on a live environment and verified it works as intended. Unit and live integration tests pass on Python 3.13.

Compliance & Style


Post-Approval Actions

  • Please merge this PR for me once it is approved

Python developers implementing semantic similarity search on Cloud Spanner lacked a client library example showing parameterized FLOAT32 vector bindings with COSINE_DISTANCE.
@iennae
iennae requested review from a team as code owners November 17, 2026 18:48
@snippet-bot

snippet-bot Bot commented Nov 17, 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 Python samples for Cloud Spanner vector search and AI capabilities, including the necessary configuration and test files. The review feedback suggests improving the find_k_nearest_neighbors function by making project_id an optional parameter to better support Application Default Credentials (ADC). It also recommends using client.project for error reporting to ensure the resolved project ID is displayed, removing hardcoded fallback project IDs in the CLI arguments, and updating the corresponding unit and integration tests to reflect the updated function signature.

Prints short resource identifiers instead of full project-prefixed resource paths and omits project_id from diagnostic messages.

@angelcaamal angelcaamal 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 just left a few comments.

Comment thread spanner/search_and_ai/tests/conftest.py Resolved
@XrossFox XrossFox self-assigned this Nov 30, 2026
Problem: review of the k-nearest neighbors sample tests found leftovers from
an earlier revision. The tests still defined DATABASE_NAME and assigned it to
the mocked database's name, although the sample now prints the database ID and
never reads the full resource name. One error test also repeated the same
project ID assertion twice.

Solution: remove the unused DATABASE_NAME constant and the two mock
assignments, and drop the duplicated assertion. Test behavior is unchanged.
@iennae
iennae merged commit e5a86e9 into main Dec 1, 2026
14 of 19 checks passed
@iennae
iennae deleted the feat/spanner-vector-search-knn branch December 1, 2026 00:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the Spanner API. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants