diff --git a/rag/folderinfo.py b/rag/folderinfo.py index 80eadd6..d075e99 100644 --- a/rag/folderinfo.py +++ b/rag/folderinfo.py @@ -131,7 +131,9 @@ where a.orgid = b.orgid fiid = ns.get('fiid', '') id = ns.get('id', '') orgid = ns.get('ownerid', '') + hashvalue = ns.get('hashvalue', '') db_type = '' + api_service = APIService() debug( f'Inserting document: file_path={realpath}, userid={orgid}, db_type={db_type}, knowledge_base_id={fiid}, document_id={id}') @@ -147,6 +149,28 @@ where a.orgid = b.orgid if not os.path.exists(realpath): raise ValueError(f"文件 {realpath} 不存在") + # 检查 hashvalue 是否已存在 + db = DBPools() + dbname = "kyrag" + sql_check_hash = """ + SELECT hashvalue + FROM file + WHERE hashvalue = ${hashvalue}$ + """ + async with db.sqlorContext(dbname) as sor: + hash_result = await sor.sqlExe(sql_check_hash, {"hashvalue": hashvalue}) + if hash_result: + debug(f"文件已存在: hashvalue={hashvalue}") + timings["total"] = time.time() - start_total + return { + "status": "error", + "document_id": id, + "collection_name": "ragdb", + "timings": timings, + "message": f"文件已存在: hashvalue={hashvalue}", + "status_code": 400 + } + # 获取服务参数 service_params = await self.get_service_params(orgid) if not service_params: