Skip to content

feat(spanner): Add full-text search index DDL sample - #14845

Open
iennae wants to merge 6 commits into
mainfrom
feat/spanner-create-search-index
Open

iennae wants to merge 6 commits into
mainfrom
feat/spanner-create-search-index

Conversation

@iennae

@iennae iennae commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Description

Full-text search in Cloud Spanner requires indexing generated TOKENLIST columns with CREATE SEARCH INDEX, and unlike CREATE TABLE or CREATE VECTOR INDEX, CREATE SEARCH INDEX does not accept IF NOT EXISTS and raises FailedPrecondition if the index already exists.

Adds spanner_create_search_index demonstrating asynchronous search index creation and duplicate-DDL error handling from Python.

Note: Stacked on #14836 (feat/spanner-vector-search-knn) so this PR shows only this sample's diff. It will merge into main after #14836.

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.
Full-text search in Cloud Spanner depends on tokenized TOKENLIST columns indexed by CREATE SEARCH INDEX, which previously had only SQL DDL snippets.
@iennae
iennae requested review from a team as code owners November 17, 2026 18:48
@product-auto-label product-auto-label Bot added api: spanner Issues related to the Spanner API. samples Issues that are directly related to samples. labels Nov 17, 2026
@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 a new utility script to create a full-text search index in Google Cloud Spanner, along with comprehensive unit and integration tests to verify the functionality and error handling. As there were no review comments provided for this pull request, I have no feedback to offer.

Prints short resource identifiers instead of full project-prefixed resource paths and omits project_id from diagnostic messages.
Prints only runtime resource and query results instead of hardcoded string literals.
Problem: the sample waits on a long-running operation with a client-side
timeout. When that wait expires the client raises TimeoutError, which is
not an API call error, so the sample ended with an unhandled traceback.

Solution: catch TimeoutError and print a clear message to stderr noting
that only the wait timed out and the operation may still be running (the
timeout does not cancel it). Add a unit test covering the new handler.
Problem: multi-line SQL and DDL statements were written as adjacent string
fragments. That style is easy to get wrong (a missing trailing space joins
two SQL tokens) and is harder to read than the statement itself, and the
samples in this set mixed it with triple-quoted SQL.

Solution: write each multi-line statement as a single triple-quoted string,
matching the layout already used by the other samples. Only whitespace
between SQL tokens changes; the statements are otherwise identical.

Files updated:
  - spanner/search_and_ai/src/spanner_search_and_ai/create_search_index.py
Base automatically changed from feat/spanner-vector-search-knn to main 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.

2 participants