Skip to content

Conversation

@cyyeh
Copy link
Member

@cyyeh cyyeh commented Aug 15, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved validation for relationship recommendations to ensure only existing models and valid columns are suggested.
    • Filters out relationships that reference unknown models or non-existent/non-relationship columns, reducing invalid suggestions.
  • Refactor

    • Adjusted internal validation workflow to incorporate model and column presence checks, enhancing reliability without changing visible behavior.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 15, 2025

Walkthrough

Updated relationship validation to require a model catalog input. The validated function now accepts mdl: dict, builds a set of non-relationship columns per model, and filters relationships to include only those with allowed relation types and existing models/columns. Return shape remains {"relationships": [...] }.

Changes

Cohort / File(s) Summary of Changes
Relationship validation update
wren-ai-service/src/pipelines/generation/relationship_recommendation.py
Changed signature to validated(normalized: dict, mdl: dict) -> dict; added model_columns derived from mdl.models; enforced presence checks for fromModel/toModel and their columns; retained RelationType.is_include filtering; output structure unchanged.

Sequence Diagram(s)

sequenceDiagram participant Client participant RelationshipValidator as relationship_recommendation.validated participant ModelCatalog as mdl Client->>RelationshipValidator: validated(normalized, mdl) RelationshipValidator->>ModelCatalog: Read models and columns RelationshipValidator->>RelationshipValidator: Build model_columns map loop For each candidate relationship RelationshipValidator->>RelationshipValidator: Check relation type is include RelationshipValidator->>RelationshipValidator: Verify fromModel/toModel exist RelationshipValidator->>RelationshipValidator: Verify fromColumn/toColumn exist end RelationshipValidator-->>Client: {"relationships": validated_list} 
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

I nibble on specs with whiskers high,
Mapping models under data sky.
From-to columns, hop in line—
Only valid links may shine.
With careful paws I filter through,
Returning bonds both clean and true. 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/ai-service/fix-relationship-recommendation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.
@cyyeh cyyeh added module/ai-service ai-service related ci/ai-service ai-service related labels Aug 15, 2025
@cyyeh cyyeh requested a review from yichieh-lu August 15, 2025 03:32
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/src/pipelines/generation/relationship_recommendation.py (3)

137-147: Align column filtering with cleaned_models; guard against None and simplify set construction

Use the same predicate as cleaned_models for detecting non-relationship columns, handle potential None columns safely, skip nameless models, and simplify with set comprehensions.

-def validated(normalized: dict, mdl: dict) -> dict: - model_columns = { - model["name"]: set( - [ - column["name"] - for column in model.get("columns", []) - if not column.get("relationship") - ] - ) - for model in mdl.get("models", []) - } +def validated(normalized: dict, mdl: dict) -> dict: + model_columns = { + model.get("name"): { + column.get("name") + for column in (model.get("columns") or []) + if column.get("name") and ("relationship" not in column) + } + for model in mdl.get("models", []) + if model.get("name") + }

149-151: Defensively normalize relationships from LLM output

The LLM may return an unexpected shape; type-guard to avoid runtime issues.

- relationships = normalized.get("relationships", []) + relationships = normalized.get("relationships") or [] + if not isinstance(relationships, list): + relationships = []

154-159: Exclude same-model relationships and avoid None in membership checks

Enforce the “no intra-model relationships” rule and make membership checks robust with a default empty set.

- and relationship.get("fromModel") in model_columns - and relationship.get("toModel") in model_columns - and relationship.get("fromColumn") - in model_columns.get(relationship.get("fromModel")) - and relationship.get("toColumn") - in model_columns.get(relationship.get("toModel")) + and relationship.get("fromModel") in model_columns + and relationship.get("toModel") in model_columns + and relationship.get("fromModel") != relationship.get("toModel") + and relationship.get("fromColumn") in model_columns.get(relationship.get("fromModel"), set()) + and relationship.get("toColumn") in model_columns.get(relationship.get("toModel"), set())
📜 Review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between a3cd3f4 and 270e0a8.

📒 Files selected for processing (1)
  • wren-ai-service/src/pipelines/generation/relationship_recommendation.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
wren-ai-service/src/pipelines/generation/relationship_recommendation.py (1)
wren-ai-service/src/web/v1/routers/semantics_description.py (1)
  • get (67-98)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: pytest
  • GitHub Check: pytest
  • GitHub Check: Analyze (go)
🔇 Additional comments (1)
wren-ai-service/src/pipelines/generation/relationship_recommendation.py (1)

137-137: Signature change — no direct callers found

Verified: the only occurrence of validated(...) is its definition at wren-ai-service/src/pipelines/generation/relationship_recommendation.py:137. No other call sites or rebindings were found in the repository.

  • Location: wren-ai-service/src/pipelines/generation/relationship_recommendation.py:137
@cyyeh cyyeh merged commit 278d903 into main Aug 15, 2025
15 checks passed
@cyyeh cyyeh deleted the chore/ai-service/fix-relationship-recommendation branch August 15, 2025 03:38
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 wren-ai-service

3 participants