-
Notifications
You must be signed in to change notification settings - Fork 83
[DRAFT] feat: convert vector query to pipeline #1154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: pipeline-preview-public
Are you sure you want to change the base?
[DRAFT] feat: convert vector query to pipeline #1154
Conversation
Summary of ChangesHello @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
🧠 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 AssistThe 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
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 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
|
There was a problem hiding this 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__" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| 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 | ||
| ) | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| 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 | |
| ) | |
| ) |
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