Skip to content

Conversation

@daniel-sanche
Copy link
Contributor

WIP code that converts vector queries to pipelines, and triggers relevant system tests

Other languages don't seem to do this, so we can hold off for now. But I wanted to put this branch together for later

@product-auto-label product-auto-label bot added size: l Pull request size is large. api: firestore Issues related to the googleapis/python-firestore API. labels Jan 13, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello @daniel-sanche, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request integrates vector queries with the existing pipeline execution framework, allowing vector search operations to be represented and executed as Firestore pipelines. This change streamlines the internal handling of vector queries, simplifies the pipeline API by removing an unused parameter, and enhances test coverage for this functionality.

Highlights

  • Vector Query to Pipeline Conversion: Introduced a new _build_pipeline method within BaseVectorQuery to convert vector search parameters into a series of pipeline stages, including FindNearest, Where (for distance thresholds), and RemoveFields (for temporary distance fields).
  • Pipeline API Updates: Modified the PipelineSource.create_from method to accept BaseVectorQuery objects, allowing direct creation of pipelines from vector queries. The index_mode parameter was removed from Pipeline and AsyncPipeline execution methods, simplifying the API.
  • System Test Enhancements: Updated system tests to include verify_pipeline calls for vector search tests, ensuring that vector queries are correctly processed through the pipeline verification mechanism. Removed IS_KOKORO_TEST related skips, indicating broader support for pipeline tests.
  • Unit Test Coverage: Added comprehensive unit tests for the _build_pipeline method in BaseVectorQuery, covering scenarios with explicit and implicit distance result fields, and correct application of distance thresholds.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@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 the capability to convert vector queries into pipelines by adding a _build_pipeline method to BaseVectorQuery. It also updates system tests to verify this new functionality, removes the index_mode parameter from pipeline execution methods, and cleans up test configurations by removing Kokoro-specific skips. The implementation of _build_pipeline is sound, correctly handling distance thresholds and generating the appropriate pipeline stages. The tests are comprehensive, covering both unit and system-level verification. I have a couple of suggestions to improve code maintainability and robustness.

cleanup_distance_field = False

if self._distance_threshold is not None and not distance_field_name:
distance_field_name = "__vector_distance__"

Choose a reason for hiding this comment

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

medium

The magic string __vector_distance__ is used here and also hardcoded in the new unit tests in tests/unit/v1/test_vector_query.py. To improve maintainability and prevent potential typos, it would be better to define this as a module-level constant (e.g., _DEFAULT_DISTANCE_FIELD = "__vector_distance__"). This constant could then be used here and imported into the test file.

Comment on lines +211 to +222
if self._distance_measure == DistanceMeasure.DOT_PRODUCT:
pipeline = pipeline.where(
Field(distance_field_name).greater_than_or_equal(
self._distance_threshold
)
)
else:
pipeline = pipeline.where(
Field(distance_field_name).less_than_or_equal(
self._distance_threshold
)
)

Choose a reason for hiding this comment

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

medium

The logic for applying the distance threshold assumes that any distance measure other than DOT_PRODUCT will use less_than_or_equal. While this is correct for EUCLIDEAN and COSINE, it might not hold for future distance measures. It would be more robust to explicitly check for the supported distance measures to make the code safer for future extensions.

Suggested change
if self._distance_measure == DistanceMeasure.DOT_PRODUCT:
pipeline = pipeline.where(
Field(distance_field_name).greater_than_or_equal(
self._distance_threshold
)
)
else:
pipeline = pipeline.where(
Field(distance_field_name).less_than_or_equal(
self._distance_threshold
)
)
if self._distance_measure == DistanceMeasure.DOT_PRODUCT:
pipeline = pipeline.where(
Field(distance_field_name).greater_than_or_equal(
self._distance_threshold
)
)
elif self._distance_measure in (
DistanceMeasure.EUCLIDEAN,
DistanceMeasure.COSINE,
):
pipeline = pipeline.where(
Field(distance_field_name).less_than_or_equal(
self._distance_threshold
)
)

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

Labels

api: firestore Issues related to the googleapis/python-firestore API. size: l Pull request size is large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant