fix(ids): 全仓 ID 生成统一 getID()/uuid()——禁 uuid4 截断
- api_core.py 5处、init.py 6处、pipeline.py 1处: uuid4().hex -> getID()
(uuid4 hex 32位+chunk后缀_cN 溢出 VARCHAR(32) → ingest 1406 DataError,
即 search 0 命中根因;getID() 21位放得下)
- upload_file.dspy: 去掉 replace('-','')[:16] 手工截断,直用沙箱 uuid()
- 规范:.py 必须 getID(),.dspy 必须 uuid()
This commit is contained in:
parent
282845bbf1
commit
98389da60b
@ -21,7 +21,7 @@ org 注入方式(session_env):返回真实请求 _run_ns,get_userorgid/g
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import uuid as _uuid
|
||||
from appPublic.uniqueID import getID
|
||||
|
||||
from ahserver.serverenv import ServerEnv
|
||||
from appPublic.dictObject import DictObject
|
||||
@ -107,7 +107,7 @@ async def kb_create(env, ns):
|
||||
if emb not in _ENGINES:
|
||||
return _err("embedding_engine must be one of " + "/".join(_ENGINES))
|
||||
org_id = await env.get_userorgid()
|
||||
kb_id = _uuid.uuid4().hex
|
||||
kb_id = getID()
|
||||
from rag.init import get_rags_base, ensure_kb_dir
|
||||
async with get_sor_context(env, 'rag') as sor:
|
||||
dup = await sor.sqlExe(
|
||||
@ -289,7 +289,7 @@ async def tag_create(env, ns):
|
||||
if existing:
|
||||
r = existing[0]
|
||||
return _ok(tag_id=r.id, name=r.name, color=r.color, duplicate=True)
|
||||
tag_id = _uuid.uuid4().hex
|
||||
tag_id = getID()
|
||||
await sor.sqlExe(
|
||||
"INSERT INTO rag_tags (id, kb_id, name, color, org_id, created_at) "
|
||||
"VALUES (${id}$, ${k}$, ${n}$, ${c}$, ${o}$, NOW())",
|
||||
@ -333,7 +333,7 @@ async def doc_set_tags(env, ns):
|
||||
if recs:
|
||||
tag_ids_in.append(recs[0].id)
|
||||
else:
|
||||
tid = _uuid.uuid4().hex
|
||||
tid = getID()
|
||||
await sor.sqlExe(
|
||||
"INSERT INTO rag_tags (id, kb_id, name, color, org_id, created_at) "
|
||||
"VALUES (${id}$, ${k}$, ${n}$, '#3b82f6', ${o}$, NOW())",
|
||||
@ -366,7 +366,7 @@ async def doc_set_tags(env, ns):
|
||||
await sor.sqlExe(
|
||||
"INSERT INTO rag_media_tags (id, kb_id, media_type, media_id, tag_id, created_at) "
|
||||
"VALUES (${id}$, ${k}$, 'document', ${d}$, ${t}$, NOW())",
|
||||
{"id": _uuid.uuid4().hex, "k": kb_id, "d": doc_id, "t": tid})
|
||||
{"id": getID(), "k": kb_id, "d": doc_id, "t": tid})
|
||||
added += 1
|
||||
await sor.sqlExe("COMMIT", {})
|
||||
# 回读最终标签列表
|
||||
@ -411,7 +411,7 @@ async def doc_upload(env, ns, file_data, file_name):
|
||||
return _err(quota_msg, code="storage_quota_exceeded")
|
||||
rags_base = await get_rags_base(sor)
|
||||
|
||||
doc_id = _uuid.uuid4().hex
|
||||
doc_id = getID()
|
||||
kb_dir = ensure_kb_dir(rags_base, org_id, kb_id)
|
||||
safe_name = file_name.replace('/', '_').replace('\\', '_')
|
||||
disk_name = doc_id[:8] + '_' + safe_name
|
||||
|
||||
15
rag/init.py
15
rag/init.py
@ -7,7 +7,8 @@ from ahserver.serverenv import ServerEnv
|
||||
from appPublic.registerfunction import RegisterFunction
|
||||
from appPublic.log import debug, exception
|
||||
from sqlor.dbpools import get_sor_context
|
||||
import json, os, uuid, time
|
||||
import json, os, time
|
||||
from appPublic.uniqueID import getID
|
||||
|
||||
|
||||
async def status_handler(request, params_kw, *args, **kwargs):
|
||||
@ -433,7 +434,7 @@ async def doc_upload_handler(request, params_kw, *args, **kwargs):
|
||||
"message": "存储配额超限:机构已用 " + _fmt_bytes(used) + ",限额 " + _fmt_bytes(quota_limit) + ",本文件 " + _fmt_bytes(file_size)}, ensure_ascii=False)
|
||||
|
||||
# ---- 保存到机构 rags 目录:{workspace_base}/{org}/rags/{kb}/ ----
|
||||
doc_id = uuid.uuid4().hex
|
||||
doc_id = getID()
|
||||
async with get_sor_context(env, 'rag') as sor:
|
||||
rags_base = await get_rags_base(sor)
|
||||
kb_dir = ensure_kb_dir(rags_base, userorgid, kb_id)
|
||||
@ -875,7 +876,7 @@ async def dir_create_handler(request, params_kw, *args, **kwargs):
|
||||
ok, kb, msg = await check_kb_perm(env, sor, kb_id, 'maintain')
|
||||
if not ok:
|
||||
return json.dumps({"error": "kb_perm_denied", "message": msg}, ensure_ascii=False)
|
||||
dir_id = uuid.uuid4().hex
|
||||
dir_id = getID()
|
||||
await sor.sqlExe(
|
||||
"INSERT INTO rag_document_chunks (id, doc_id, kb_id, chunk_index, chunk_type, content, description, created_at) "
|
||||
"VALUES (${id}$, '', ${kb_id}$, 0, 'directory', ${name}$, ${parent}$, NOW())",
|
||||
@ -952,7 +953,7 @@ async def tag_create_handler(request, params_kw, *args, **kwargs):
|
||||
if existing:
|
||||
return json.dumps({"status": "SUCCEEDED", "tag_id": existing[0].id, "name": name,
|
||||
"color": existing[0].color, "duplicate": True}, ensure_ascii=False)
|
||||
tag_id = uuid.uuid4().hex
|
||||
tag_id = getID()
|
||||
await sor.sqlExe(
|
||||
"INSERT INTO rag_tags (id, kb_id, name, color, org_id, created_at) "
|
||||
"VALUES (${id}$, ${kb_id}$, ${name}$, ${color}$, ${org_id}$, NOW())",
|
||||
@ -1009,7 +1010,7 @@ async def tag_assign_handler(request, params_kw, *args, **kwargs):
|
||||
if media_type not in ("document", "face", "voice"):
|
||||
return json.dumps({"error": "media_type must be document/face/voice"})
|
||||
async with get_sor_context(env, 'rag') as sor:
|
||||
mt_id = uuid.uuid4().hex
|
||||
mt_id = getID()
|
||||
await sor.sqlExe(
|
||||
"INSERT INTO rag_media_tags (id, kb_id, media_type, media_id, tag_id, created_at) "
|
||||
"VALUES (${id}$, ${kb_id}$, ${type}$, ${mid}$, ${tid}$, NOW())",
|
||||
@ -1164,7 +1165,7 @@ async def tag_sync_handler(request, params_kw, *args, **kwargs):
|
||||
added = 0
|
||||
for tid in wanted_ids:
|
||||
if tid not in current:
|
||||
mt_id = uuid.uuid4().hex
|
||||
mt_id = getID()
|
||||
await sor.sqlExe(
|
||||
"INSERT INTO rag_media_tags (id, kb_id, media_type, media_id, tag_id, created_at) "
|
||||
"VALUES (${id}$, ${kb_id}$, ${type}$, ${mid}$, ${tid}$, NOW())",
|
||||
@ -1243,7 +1244,7 @@ async def engine_cfg_save_handler(request, params_kw, *args, **kwargs):
|
||||
from appPublic.jsonConfig import getConfig
|
||||
key = getConfig().password_key or 'QRIVSRHrthhwyjy176556332'
|
||||
enc = password(api_key_plain, key=key) if api_key_plain else ""
|
||||
rid = uuid.uuid4().hex
|
||||
rid = getID()
|
||||
await sor.sqlExe(
|
||||
"INSERT INTO rag_engine_configs (id, engine_type, engine_name, endpoint_url, api_key, "
|
||||
"model_name, is_default, priority, status, created_at, updated_at) "
|
||||
|
||||
@ -143,8 +143,8 @@ async def extract_voiceprint(file_data, file_name):
|
||||
|
||||
async def process_upload(env, file_data, kb_id, folder_id, file_name):
|
||||
"""Full upload pipeline — save + classify + process + DB record"""
|
||||
import uuid as _uuid
|
||||
doc_id = str(_uuid.uuid4()).hex[:16]
|
||||
from appPublic.uniqueID import getID
|
||||
doc_id = getID()
|
||||
ext = '.' + file_name.rsplit('.', 1)[1] if '.' in file_name else '.bin'
|
||||
saved_name = doc_id + ext
|
||||
file_path = '/d/rag/ragserver/pkgs/rag/rag/files/' + saved_name
|
||||
|
||||
@ -35,7 +35,7 @@ if used + file_size > quota_limit:
|
||||
web_path = await env.save_file(file_data, file_name)
|
||||
real_path = env.realpath(web_path)
|
||||
|
||||
doc_id = str(uuid()).replace('-', '')[:16]
|
||||
doc_id = uuid()
|
||||
ext = '.' + file_name.rsplit('.', 1)[1] if '.' in file_name else '.bin'
|
||||
ext_l = ext.lower()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user