fix(datasource): retain explicitly referenced tables in schema selection - #1380
Merged
Merged
Conversation
There was a problem hiding this comment.
🔵 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_endsweep does not actually collapse every overlapping occurrence: if two spans cross (for example commentsabcdandcdefginabcdefg), the second span extends pastfurthest_end, so both names are added toexplicit_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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
Validation
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.