Skip to content

Conversation

@WainWong
Copy link

Summary

  • 添加基于 LLM 的表选择功能,优先于 RAG 表嵌入方式
  • LLM 可以更准确地理解用户问题并选择相关表,特别是对于复杂的多表查询场景
  • 支持配置开关,可灵活选择使用 LLM 表选择或 RAG 表嵌入

Changes

  • backend/apps/datasource/llm_select/table_selection.py: 新增 LLM 表选择核心逻辑
  • backend/apps/template/select_table/generator.py: 表选择 prompt 生成器
  • backend/apps/datasource/crud/datasource.py: 集成 LLM 表选择到表 schema 获取流程
  • backend/apps/chat/task/llm.py: 延迟 schema 获取以支持日志记录
  • backend/common/core/config.py: 添加 LLM 表选择配置项
  • backend/alembic/versions/054_add_table_select_answer.py: 数据库迁移脚本

WainWong and others added 2 commits December 24, 2025 17:41
Add a new LLM-based table selection feature that can replace or work alongside
the existing RAG-based table embedding. Key changes:

- New table selection module (backend/apps/datasource/llm_select/)
- New config option TABLE_LLM_SELECTION_ENABLED (default: true)
- Add table_select_answer field to ChatRecord for logging LLM selections
- Add SELECT_TABLE operation type for tracking in chat logs
- Skip foreign key relation table completion when using LLM selection
  (LLM already sees table relations and can decide which tables to include)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add MULTI_TURN_EMBEDDING_ENABLED and MULTI_TURN_HISTORY_COUNT config
- Add get_chat_history_questions() to retrieve recent questions from same chat
- Add build_context_query() to concatenate history questions with current question
- Update calc_table_embedding() to use context query for better table matching
- Pass history_questions through get_table_schema() to LLMService

This improves table structure retrieval accuracy by considering the full
conversation context instead of just the latest question.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

1 participant