Skip to content
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

fix(wren-ai-service): column pruning step in retrieval pipeline and correct code for sql generation in evaluation #1225

Merged
merged 3 commits into from
Jan 24, 2025

Conversation

paopa
Copy link
Member

@paopa paopa commented Jan 24, 2025

This PR introduces several improvements to the retrieval and generation pipelines:

Changes

  1. Pre-indexing Pipeline Enhancement

    • Added Table Description indexing alongside DB Schema indexing
    • Refactored indexing deployment to handle multiple indexing components
    • Renamed _indexing to _db_schema_indexing for better clarity
  2. SQL Generation Updates

    • Added sql_generation_reasoning field to both Generation and Ask pipelines for Evaluation
    • This allows for better tracking and understanding of SQL query generation logic
  3. DB Schema Processing Optimization

    • Simplified the DB schemas pruning logic in retrieval prompt generation
    • Modified the encoding selection logic to respect allow_using_db_schemas_without_pruning flag

Summary by CodeRabbit

  • New Features

    • Enhanced pipeline classes to handle additional SQL generation reasoning information.
    • Improved retrieval result formatting and database schema handling.
    • Enabled the use of database schemas without pruning in OpenAI model configurations.
  • Refactor

    • Simplified DDL generation process.
    • Modified conditions for pruning database schemas.
    • Updated method signatures with explicit return types.
  • Bug Fixes

    • Adjusted output structure to match new schema requirements.

@paopa paopa added module/ai-service ai-service related ci/ai-service ai-service related labels Jan 24, 2025
Copy link
Contributor

coderabbitai bot commented Jan 24, 2025

Walkthrough

The pull request introduces modifications to the AI service's pipeline classes, focusing on enhancing SQL generation and retrieval processes. The changes primarily involve updating the RetrievalPipeline, GenerationPipeline, and AskPipeline classes in the evaluation and retrieval modules. Key modifications include renaming variables, introducing new indexing components, and updating method signatures to incorporate SQL generation reasoning information.

Changes

File Change Summary
wren-ai-service/eval/pipelines.py - Renamed _indexing to _db_schema_indexing in RetrievalPipeline
- Added _table_description_indexing
- Updated GenerationPipeline._process() to include sql_generation_reasoning
- Updated AskPipeline._process() to include sql_generation_reasoning
wren-ai-service/src/pipelines/retrieval/retrieval.py - Modified prompt() function DDL generation logic
- Updated Retrieval.__init__() condition for allow_using_db_schemas_without_pruning
- Reformatted construct_retrieval_results() output structure
wren-launcher/utils/docker.go - Added line to enable allow_using_db_schemas_without_pruning in OpenAI configuration

Sequence Diagram

sequenceDiagram
    participant Retrieval
    participant GenerationPipeline
    participant AskPipeline
    
    Retrieval->>GenerationPipeline: Pass SQL generation reasoning
    Retrieval->>AskPipeline: Pass SQL generation reasoning
    
    GenerationPipeline->>GenerationPipeline: Process with reasoning
    AskPipeline->>AskPipeline: Process with reasoning
Loading

Possibly related PRs

  • chore(wren-ai-service): improve ai service #1068: The changes in the wren-ai-service/src/pipelines/retrieval/retrieval.py file involve modifications to the Retrieval class, which may relate to the overall functionality of the pipelines, particularly in how data is handled and processed, although it does not directly modify the same classes or methods as the main PR.
  • chore(wren-ai-service): add separate reasoning pipeline #1212: This PR introduces a new pipeline step for SQL generation reasoning, which is directly related to the enhancements made in the main PR regarding the handling of reasoning information during SQL generation in the GenerationPipeline and AskPipeline classes.
  • chore(wren-ai-service): minor updates #1219: The addition of the generation_reasoning field to the AskResultResponse class enhances the response structure to include reasoning related to SQL generation, which aligns with the changes made in the main PR to incorporate reasoning into the pipeline processes.

Suggested reviewers

  • andreashimin
  • onlyjackfrost
  • wwwy3y3

Poem

🐰 In pipelines of code, a rabbit's delight,
SQL reasoning now shines so bright!
Indexing tweaked with magical care,
Retrieval and generation beyond compare,
A dance of logic, precise and light! 🔍✨

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
wren-ai-service/eval/pipelines.py (2)

184-186: Add a clarifying comment.
The newly introduced _table_description_indexing variable is self-explanatory, but consider adding a brief docstring or inline comment explaining its role in this pipeline for future maintainers.


253-253: Validate default for missing reasoning.
Using prediction.get("reasoning", "") silently defaults to an empty string. If this information is critical, consider alerting or logging a warning when it's missing, rather than defaulting to an empty value.

wren-ai-service/src/pipelines/retrieval/retrieval.py (1)

419-421: Safeguard against fragile model name checks.
Relying on substring matching ("gpt-4o" or "gpt-4o-mini") may break if model names evolve. Consider mapping known model names to the chosen encoding in a config or dictionary for better maintainability.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 63f26bc and 118daa0.

📒 Files selected for processing (2)
  • wren-ai-service/eval/pipelines.py (3 hunks)
  • wren-ai-service/src/pipelines/retrieval/retrieval.py (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: pytest
  • GitHub Check: pytest
  • GitHub Check: Analyze (go)
🔇 Additional comments (3)
wren-ai-service/eval/pipelines.py (2)

344-344: Same missing reasoning concern as above.
This echoes the comment on line 253. Make sure the default empty string is intentional and won't mask missing data.


180-180: Ensure renamed variable is used uniformly.
Since _indexing was replaced by _db_schema_indexing, please confirm that all upstream and downstream references now point to _db_schema_indexing to avoid runtime errors.

✅ Verification successful

Variable rename verification successful
The variable _db_schema_indexing is used consistently throughout the codebase with no remaining references to the old variable name _indexing.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify references to _db_schema_indexing throughout the codebase
rg -A 5 '_db_schema_indexing'

Length of output: 2108


Script:

#!/bin/bash
# Search for any remaining instances of _indexing
rg -A 5 '_indexing' wren-ai-service/eval/pipelines.py

Length of output: 1330

wren-ai-service/src/pipelines/retrieval/retrieval.py (1)

271-271: Dropping the second return value.
You are now exclusively capturing the DDL portion ([0]) from build_table_ddl. If the boolean flag is needed elsewhere (e.g., to detect calculated fields), confirm it’s handled correctly.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
wren-launcher/utils/docker.go (1)

162-165: Consider using a dedicated YAML parser to set the property accurately.

By using strings.ReplaceAll(), there's a risk of partial or multiple unintended replacements if the target string appears more than once or in a slightly different context. A more robust approach is to parse the YAML, update the specific property programmatically, and then re-serialize it, preventing accidental changes and improving maintainability.

Example diff using a YAML library (pseudo-code):

+import (
+  "gopkg.in/yaml.v3"
+)

// ...
- config = strings.ReplaceAll(config, "allow_using_db_schemas_without_pruning: false", "allow_using_db_schemas_without_pruning: true")

+var parsedCfg map[string]interface{}
+err = yaml.Unmarshal([]byte(config), &parsedCfg)
+if err != nil {
+  return err
+}
+parsedCfg["allow_using_db_schemas_without_pruning"] = true
+newCfgBytes, err := yaml.Marshal(parsedCfg)
+if err != nil {
+  return err
+}
+config = string(newCfgBytes)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 118daa0 and b11d578.

📒 Files selected for processing (2)
  • wren-ai-service/src/pipelines/retrieval/retrieval.py (1 hunks)
  • wren-launcher/utils/docker.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • wren-ai-service/src/pipelines/retrieval/retrieval.py

Copy link
Member

@cyyeh cyyeh left a comment

Choose a reason for hiding this comment

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

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci/ai-service ai-service related module/ai-service ai-service related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants