Repository navigation
feat(spanner): Add exact k-nearest neighbors vector search sample - #14836
Conversation
Python developers implementing semantic similarity search on Cloud Spanner lacked a client library example showing parameterized FLOAT32 vector bindings with COSINE_DISTANCE.
|
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
LGTM, I just left a few comments.
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.
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 aFLOAT32query embedding withparam_types.Array(param_types.FLOAT32)inside a read snapshot.Establishes the
spanner/search_and_aiPython 3.13+ sample package and addsspanner_vector_search_knnwith offline unit tests and gated live integration tests.Checklist
Testing
Compliance & Style
spanner/, which the default repository owners cover.Post-Approval Actions