Enhance environment configuration and error handling in API server and backend. Implement dynamic loading of .env files for various execution contexts, improve schema file path resolution, and refine vector search error handling in the orchestrator. Update ChromaDB integration to support memory mode and add persistence options for few-shot learning. Include additional logging for better traceability.
This commit is contained in:
@@ -175,25 +175,36 @@ class Text2SQLOrchestrator:
|
||||
"""
|
||||
if not self.use_vector_search:
|
||||
# 不使用向量检索时,返回所有表
|
||||
logger.info("[Orchestrator] 向量搜索已禁用,使用所有表")
|
||||
return self.schema_manager.list_tables()
|
||||
|
||||
indexer = self._get_vector_index()
|
||||
try:
|
||||
indexer = self._get_vector_index()
|
||||
|
||||
# 确保索引已构建
|
||||
if indexer.count() == 0:
|
||||
logger.info("向量索引为空,正在构建...")
|
||||
indexer.build_index(self.schema_manager, force_rebuild=True)
|
||||
# 确保索引已构建
|
||||
if indexer.count() == 0:
|
||||
logger.info("向量索引为空,正在构建...")
|
||||
indexer.build_index(self.schema_manager, force_rebuild=True)
|
||||
logger.info(f"[OK] 索引构建完成,共 {indexer.count()} 张表")
|
||||
|
||||
# 检索
|
||||
results = indexer.search(
|
||||
query=question,
|
||||
top_k=top_k,
|
||||
score_threshold=0.1 # 降低阈值以提高召回率(原0.2)
|
||||
)
|
||||
# 检索
|
||||
logger.info(f"[Orchestrator] 开始向量检索: query='{question[:50]}...'")
|
||||
results = indexer.search(
|
||||
query=question,
|
||||
top_k=top_k,
|
||||
score_threshold=0.1 # 降低阈值以提高召回率
|
||||
)
|
||||
|
||||
candidate_tables = [r["table_name"] for r in results]
|
||||
logger.debug(f"粗筛候选表:{candidate_tables[:10]}...(共{len(candidate_tables)}个)")
|
||||
return candidate_tables
|
||||
candidate_tables = [r["table_name"] for r in results]
|
||||
logger.debug(f"粗筛候选表:{candidate_tables[:10]}...(共{len(candidate_tables)}个)")
|
||||
return candidate_tables
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"[Orchestrator] 向量检索失败: {e},降级为使用所有表", exc_info=True)
|
||||
import traceback
|
||||
logger.error(traceback.format_exc())
|
||||
# 降级:返回所有表
|
||||
return self.schema_manager.list_tables()
|
||||
|
||||
def _llm_select_tables(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user