Skip to content

fix: avoid constructing DatasetProcessRule in indexing preview#33911

Open
wangji0923 wants to merge 3 commits intolanggenius:mainfrom
wangji0923:fix/31094-indexing-estimate-preview-rule
Open

fix: avoid constructing DatasetProcessRule in indexing preview#33911
wangji0923 wants to merge 3 commits intolanggenius:mainfrom
wangji0923:fix/31094-indexing-estimate-preview-rule

Conversation

@wangji0923
Copy link
Copy Markdown
Contributor

Summary

  • replace the preview-only DatasetProcessRule ORM construction in IndexingRunner.indexing_estimate with a lightweight process rule dict
  • allow ProcessRuleDict to omit persisted-only fields in preview scenarios
  • add a focused unit test to ensure preview estimation does not instantiate DatasetProcessRule

Testing

  • DEBUG=false uv run --project api --no-default-groups --group dev --group tools pytest api/tests/unit_tests/core/rag/indexing/test_indexing_runner.py

Closes #31094

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 optimizes the indexing preview functionality by preventing the instantiation of full DatasetProcessRule ORM objects. Instead, it utilizes a more lightweight dictionary representation for processing rules during estimation, which streamlines the process and reduces overhead by avoiding unnecessary database interactions for preview-only operations.

Highlights

  • Performance Optimization for Indexing Preview: Replaced the construction of DatasetProcessRule ORM objects with a lightweight dictionary (ProcessRuleDict) in the IndexingRunner.indexing_estimate method, specifically for preview scenarios. This change avoids unnecessary database-related operations when only an estimation is required.
  • Flexible ProcessRuleDict Definition: Modified the ProcessRuleDict definition to mark id and dataset_id fields as NotRequired. This allows the dictionary to be used in contexts like preview estimation where these persisted-only fields are not necessary.
  • New Unit Test for Preview Logic: Added a focused unit test (test_indexing_estimate_uses_lightweight_preview_process_rule) to explicitly ensure that the DatasetProcessRule ORM object is not instantiated during the indexing preview estimation process, thereby validating the intended optimization.

🧠 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.

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
Copy Markdown
Contributor

@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 successfully refactors the indexing_estimate method to avoid constructing a DatasetProcessRule ORM object during previews, which is a good performance optimization. This is achieved by creating a lightweight dictionary and updating ProcessRuleDict to allow optional id and dataset_id fields. The new unit test is well-written and effectively validates that the ORM object is not instantiated. The changes are solid, and I have just one minor suggestion to improve the robustness of the new test's assertion.

assert transform_kwargs["preview"] is True
assert transform_kwargs["process_rule"] == {
"mode": tmp_processing_rule["mode"],
"rules": tmp_processing_rule["rules"],
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.

medium

The assertion uses dictionary-style access (tmp_processing_rule["rules"]), while the implementation being tested uses the safer .get("rules"). While this works for the current test setup, it makes the test less robust. To better align with the implementation's logic and improve robustness, consider using .get("rules") here as well.

Suggested change
"rules": tmp_processing_rule["rules"],
"rules": tmp_processing_rule.get("rules"),

@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

No changes detected.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DatasetProcessRule missing fields

1 participant