From 51c9968093a9a84dbf86be009c6619d146729158 Mon Sep 17 00:00:00 2001 From: ymq Date: Tue, 25 Aug 2026 15:45:44 +0800 Subject: [PATCH] =?UTF-8?q?fix(host):=20=E5=90=8E=E5=8F=B0=E5=85=A5?= =?UTF-8?q?=E5=BA=93=E4=BB=BB=E5=8A=A1=E7=A6=81=E7=A1=AC=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E5=BA=93=E5=90=8D=EF=BC=8C=E6=94=B9=E7=BB=8F=20get=5Fmodule=5F?= =?UTF-8?q?dbname=20=E6=98=A0=E5=B0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ingest_doc 是 background_reco 后台任务(无 request/env),原用 db.sqlorContext('rag') 6 处。 在 ragserver 上库名恰为 rag 所以能跑,接入 pipeline-app(库名 pipeline)后 sqlorFactory 报 NoneType.get → 入库全程失败,status 永久 pending、向量丢失。 改为函数开头 _dbname = get_module_dbname('rag') 统一映射。 --- wwwroot/knowledge_bases_list/upload_file.dspy | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/wwwroot/knowledge_bases_list/upload_file.dspy b/wwwroot/knowledge_bases_list/upload_file.dspy index 907ddd3..4cab01a 100644 --- a/wwwroot/knowledge_bases_list/upload_file.dspy +++ b/wwwroot/knowledge_bases_list/upload_file.dspy @@ -47,11 +47,14 @@ ext_l = ext.lower() # ============================================================ async def ingest_doc(doc_id, kb_id, file_name, ext_l, real_path): db = DBPools() + # 库名必须经宿主的 get_module_dbname 映射(ragserver→'rag',pipeline-app→'pipeline') + # 后台任务无 request/env,用注入的全局函数解析;禁硬编码库名 + _dbname = get_module_dbname('rag') # 读知识库向量引擎:bge-m3=文本(走 /txte),clip-vith14=多媒体(走 /mme) emb_engine = 'clip-vith14' try: - async with db.sqlorContext('rag') as sor: + async with db.sqlorContext(_dbname) as sor: krecs = await sor.sqlExe("SELECT embedding_engine FROM rag_knowledge_bases WHERE id=${kb_id}$", {"kb_id": kb_id}) if krecs: emb_engine = (getattr(krecs[0], 'embedding_engine', '') or 'clip-vith14').strip() @@ -116,7 +119,7 @@ async def ingest_doc(doc_id, kb_id, file_name, ext_l, real_path): # --- 文本知识库不支持媒体文件 --- if is_text and (ext_l in image_exts or ext_l in audio_exts or ext_l in video_exts): try: - async with db.sqlorContext('rag') as sor: + async with db.sqlorContext(_dbname) as sor: await sor.sqlExe( "UPDATE rag_documents SET status='failed', metadata=${meta}$, updated_at=NOW() WHERE id=${id}$", {"id": doc_id, "meta": json.dumps({"error": "文本知识库不支持媒体文件,请上传文本类文件(txt/md/pdf/docx等)或改用多媒体知识库"}, ensure_ascii=False)}) @@ -193,7 +196,7 @@ async def ingest_doc(doc_id, kb_id, file_name, ext_l, real_path): chunk_meta = {"start_time": 0} if frame_bboxes: chunk_meta["bboxes"] = frame_bboxes - async with db.sqlorContext('rag') as sor: + async with db.sqlorContext(_dbname) as sor: await sor.sqlExe( "INSERT INTO rag_document_chunks (id, doc_id, kb_id, chunk_index, content, vector_id, metadata, created_at) " "VALUES (${id}$, ${doc_id}$, ${kb_id}$, 0, ${content}$, ${vid}$, ${meta}$, NOW())", @@ -273,7 +276,7 @@ async def ingest_doc(doc_id, kb_id, file_name, ext_l, real_path): except: pass - async with db.sqlorContext('rag') as sor: + async with db.sqlorContext(_dbname) as sor: for i, chunk_text in enumerate(chunks): vid = vector_ids[i] if i < len(vector_ids) else '' await sor.sqlExe( @@ -284,7 +287,7 @@ async def ingest_doc(doc_id, kb_id, file_name, ext_l, real_path): chunks_n = len(chunks) except Exception as e: try: - async with db.sqlorContext('rag') as sor: + async with db.sqlorContext(_dbname) as sor: await sor.sqlExe( "UPDATE rag_documents SET status='failed', metadata=${meta}$, updated_at=NOW() WHERE id=${id}$", {"id": doc_id, "meta": json.dumps({"error": str(e)[:300]}, ensure_ascii=False)}) @@ -294,7 +297,7 @@ async def ingest_doc(doc_id, kb_id, file_name, ext_l, real_path): # --- finalize: mark document done + update KB chunk counts --- meta_json = json.dumps(meta_parts, ensure_ascii=False) try: - async with db.sqlorContext('rag') as sor: + async with db.sqlorContext(_dbname) as sor: await sor.sqlExe( "UPDATE rag_documents SET status='done', chunk_count=${chunks}$, metadata=${meta}$, updated_at=NOW() WHERE id=${id}$", {"id": doc_id, "chunks": chunks_n, "meta": meta_json})