临时禁用RAG服务并添加日志记录
- 在RAGService中添加_disabled标志,临时禁用所有RAG功能 - 添加详细的日志记录,便于调试和监控被跳过的操作 - 在TableRAGService中同样添加禁用机制,避免索引构建 refactor(file): 更新.gitignore忽略日志目录 - 添加**/logs/到.gitignore文件中 docs(plan): 添加比赛备赛规划文档 - 创建完整的比赛备赛规划文档,包含功能清单和待办事项 - 记录已完成功能和核心缺失模块,便于项目跟踪 chore(excel): 添加Q&A参考文件 - 添加Q&A.xlsx作为参考文档,包含比赛相关问题解答
This commit is contained in:
@@ -36,9 +36,15 @@ class RAGService:
|
||||
self._dimension: int = 0
|
||||
self._initialized = False
|
||||
self._persist_dir = settings.FAISS_INDEX_DIR
|
||||
# 临时禁用 RAG API 调用,仅记录日志
|
||||
self._disabled = True
|
||||
logger.info("RAG 服务已禁用(_disabled=True),仅记录索引操作日志")
|
||||
|
||||
def _init_embeddings(self):
|
||||
"""初始化嵌入模型"""
|
||||
if self._disabled:
|
||||
logger.debug("RAG 已禁用,跳过嵌入模型初始化")
|
||||
return
|
||||
if self.embedding_model is None:
|
||||
# 使用轻量级本地模型,避免网络问题
|
||||
model_name = 'all-MiniLM-L6-v2'
|
||||
@@ -90,6 +96,10 @@ class RAGService:
|
||||
sample_values: Optional[List[str]] = None
|
||||
):
|
||||
"""将字段信息索引到向量数据库"""
|
||||
if self._disabled:
|
||||
logger.info(f"[RAG DISABLED] 字段索引操作已跳过: {table_name}.{field_name}")
|
||||
return
|
||||
|
||||
if not self._initialized:
|
||||
self._init_vector_store()
|
||||
|
||||
@@ -117,6 +127,10 @@ class RAGService:
|
||||
metadata: Optional[Dict[str, Any]] = None
|
||||
):
|
||||
"""将文档内容索引到向量数据库"""
|
||||
if self._disabled:
|
||||
logger.info(f"[RAG DISABLED] 文档索引操作已跳过: {doc_id}")
|
||||
return
|
||||
|
||||
if not self._initialized:
|
||||
self._init_vector_store()
|
||||
|
||||
@@ -154,6 +168,10 @@ class RAGService:
|
||||
|
||||
def retrieve(self, query: str, top_k: int = 5) -> List[Dict[str, Any]]:
|
||||
"""根据查询检索相关文档"""
|
||||
if self._disabled:
|
||||
logger.info(f"[RAG DISABLED] 检索操作已跳过: query={query}, top_k={top_k}")
|
||||
return []
|
||||
|
||||
if not self._initialized:
|
||||
self._init_vector_store()
|
||||
|
||||
@@ -186,6 +204,9 @@ class RAGService:
|
||||
|
||||
def get_vector_count(self) -> int:
|
||||
"""获取向量总数"""
|
||||
if self._disabled:
|
||||
logger.info("[RAG DISABLED] get_vector_count 返回 0")
|
||||
return 0
|
||||
if self.index is None:
|
||||
return 0
|
||||
return self.index.ntotal
|
||||
@@ -243,6 +264,9 @@ class RAGService:
|
||||
|
||||
def clear(self):
|
||||
"""清空所有索引"""
|
||||
if self._disabled:
|
||||
logger.info("[RAG DISABLED] clear 操作已跳过")
|
||||
return
|
||||
self._init_vector_store()
|
||||
if self.index is not None:
|
||||
self.index.reset()
|
||||
|
||||
@@ -30,6 +30,9 @@ class TableRAGService:
|
||||
self.llm = llm_service
|
||||
self.rag = rag_service
|
||||
self.excel_storage = excel_storage_service
|
||||
# 临时禁用 RAG 索引构建
|
||||
self._disabled = True
|
||||
logger.info("TableRAG 服务已禁用(_disabled=True),仅记录索引操作日志")
|
||||
|
||||
def _extract_sheet_names_from_xml(self, file_path: str) -> List[str]:
|
||||
"""
|
||||
@@ -389,13 +392,16 @@ class TableRAGService:
|
||||
all_fields=all_fields_data
|
||||
)
|
||||
|
||||
# 存入 RAG
|
||||
self.rag.index_field(
|
||||
table_name=table_name,
|
||||
field_name=col,
|
||||
field_description=description,
|
||||
sample_values=[str(v) for v in sample_values[:5]]
|
||||
)
|
||||
# 存入 RAG(如果未禁用)
|
||||
if self._disabled:
|
||||
logger.info(f"[RAG DISABLED] 字段索引已跳过: {table_name}.{col}")
|
||||
else:
|
||||
self.rag.index_field(
|
||||
table_name=table_name,
|
||||
field_name=col,
|
||||
field_description=description,
|
||||
sample_values=[str(v) for v in sample_values[:5]]
|
||||
)
|
||||
|
||||
indexed_count += 1
|
||||
results["indexed_fields"].append({
|
||||
@@ -526,13 +532,16 @@ class TableRAGService:
|
||||
all_fields=all_fields_data
|
||||
)
|
||||
|
||||
# 存入 RAG
|
||||
self.rag.index_field(
|
||||
table_name=table_name,
|
||||
field_name=col,
|
||||
field_description=description,
|
||||
sample_values=[str(v) for v in col_values[:5]]
|
||||
)
|
||||
# 存入 RAG(如果未禁用)
|
||||
if self._disabled:
|
||||
logger.info(f"[RAG DISABLED] 文档表格字段索引已跳过: {table_name}.{col}")
|
||||
else:
|
||||
self.rag.index_field(
|
||||
table_name=table_name,
|
||||
field_name=col,
|
||||
field_description=description,
|
||||
sample_values=[str(v) for v in col_values[:5]]
|
||||
)
|
||||
|
||||
indexed_count += 1
|
||||
results["indexed_fields"].append({
|
||||
|
||||
Reference in New Issue
Block a user