Skip to content

fix(datasource): retain explicitly referenced tables in schema selection - #1380

Merged
xuwei-fit2cloud merged 1 commit into
mainfrom
codex/fix-1376-explicit-table-selection
Sep 17, 2026
Merged

xuwei-fit2cloud merged 1 commit into
mainfrom
codex/fix-1376-explicit-table-selection

Conversation

@xuwei-fit2cloud

Copy link
Copy Markdown
Collaborator

Summary

Fixes #1376. A question that explicitly names an enabled table or its complete comment can currently lose that table during top-10 schema selection. Preserve explicit references from the original question independently of keyword extraction and vector scores, then fill remaining slots using the existing ranking.

  • Match physical names with identifier boundaries and complete quoted identifiers; resolve overlapping names and comments by occurrence while retaining ambiguous duplicate comments.
  • Keep all explicitly referenced candidates even when they exceed the normal selection limit. Only inspect candidates already filtered by the caller.
  • Preserve the existing full-candidate fallback when vector loading, encoding, or parsing fails, with explicit matches moved to the front.
  • Add regression coverage for selection limits, Chinese comments and names, quoted identifiers, overlapping names, and fallback behavior.

Validation

  • 85 table-matching tests passed on the PR branch based on the latest main.
  • All 12 schema scenarios passed against a local PostgreSQL fixture containing 20 similar tables and 800 fields, using the PR branch's production selection code and controlled vectors.
  • Verified disabled-table exclusion, custom-comment precedence, original-comment fallback, and all 20 candidates retained on model failure.
  • git diff --check passed.

Real LLM SQL generation was not tested because the local environment has no configured LLM or default embedding model. Local fixture scripts and generated reports are excluded from this PR.

Copilot AI lite review requested due to automatic review settings September 17, 2026 06:48
@xuwei-fit2cloud
xuwei-fit2cloud merged commit 2681896 into main Sep 17, 2026
4 checks passed
@xuwei-fit2cloud
xuwei-fit2cloud deleted the codex/fix-1376-explicit-table-selection branch September 17, 2026 06:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Crossing overlapping spans can retain both candidates instead of selecting the longest mention.

Pull request overview

Updates schema selection to retain explicitly referenced tables while preserving ranking and fallback behavior.

Changes:

  • Adds boundary-aware matching for names, comments, and quoted identifiers.
  • Preserves explicit candidates beyond selection limits and during fallback.
  • Adds regression coverage for matching, limits, overlaps, and failures.
File summaries
File Description
backend/tests/test_table_embedding.py Adds regression coverage for selection and matching behavior.
backend/apps/datasource/embedding/table_embedding.py Implements explicit table selection and fallback ordering.
Review details

Suppressed comments (1)

backend/apps/datasource/embedding/table_embedding.py:33

  • The furthest_end sweep does not actually collapse every overlapping occurrence: if two spans cross (for example comments abcd and cdefg in abcdefg), the second span extends past furthest_end, so both names are added to explicit_names. With a low selection limit this retains both candidates even though the helper promises to keep the longest overlapping mention; group overlapping spans and choose the longest span(s) per occurrence while leaving non-overlapping occurrences independent.
    for start, end in sorted(spans, key=lambda span: (span[0], -span[1])):
        if end > furthest_end:
            longest_spans.add((start, end))
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

[BUG] 问句已明确表名/表备注,生成 SQL 时仍无法匹配到对应表

2 participants