RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
Fix: predictable token generation (#10868)
Yongteng Leia3bb4aadcc34
diff --git a/api/apps/api_app.py b/api/apps/api_app.pyindex 76e10d8601..206dc15810 100644--- a/api/apps/api_app.py+++ b/api/apps/api_app.py@@ -59,7 +59,7 @@ def new_token():return get_data_error_result(message="Tenant not found!")tenant_id = tenants[0].tenant_id- obj = {"tenant_id": tenant_id, "token": generate_confirmation_token(tenant_id),+ obj = {"tenant_id": tenant_id, "token": generate_confirmation_token(),"create_time": current_timestamp(),"create_date": datetime_format(datetime.now()),"update_time": None,@@ -868,7 +868,7 @@ def retrieval():similarity_threshold = float(req.get("similarity_threshold", 0.2))vector_similarity_weight = float(req.get("vector_similarity_weight", 0.3))top = int(req.get("top_k", 1024))- highlight = bool(req.get("highlight", False))+ highlight = bool(req.get("highlight", False))try:kbs = KnowledgebaseService.get_by_ids(kb_ids)diff --git a/api/apps/system_app.py b/api/apps/system_app.pyindex 8144206e12..c1467f3d10 100644--- a/api/apps/system_app.py+++ b/api/apps/system_app.py@@ -217,8 +217,8 @@ def new_token():tenant_id = [tenant for tenant in tenants if tenant.role == 'owner'][0].tenant_idobj = {"tenant_id": tenant_id,- "token": generate_confirmation_token(tenant_id),- "beta": generate_confirmation_token(generate_confirmation_token(tenant_id)).replace("ragflow-", "")[:32],+ "token": generate_confirmation_token(),+ "beta": generate_confirmation_token().replace("ragflow-", "")[:32],"create_time": current_timestamp(),"create_date": datetime_format(datetime.now()),"update_time": None,@@ -274,7 +274,7 @@ def token_list():objs = [o.to_dict() for o in objs]for o in objs:if not o["beta"]:- o["beta"] = generate_confirmation_token(generate_confirmation_token(tenants[0].tenant_id)).replace(+ o["beta"] = generate_confirmation_token().replace("ragflow-", "")[:32]APITokenService.filter_update([APIToken.tenant_id == tenant_id, APIToken.token == o["token"]], o)return get_json_result(data=objs)diff --git a/api/utils/api_utils.py b/api/utils/api_utils.pyindex a06bff09fd..46f6135989 100644--- a/api/utils/api_utils.py+++ b/api/utils/api_utils.py@@ -43,7 +43,6 @@ from flask_login import current_userfrom flask import (request as flask_request,)-from itsdangerous import URLSafeTimedSerializerfrom peewee import OperationalErrorfrom werkzeug.http import HTTP_STATUS_CODES@@ -52,7 +51,6 @@ from api.constants import REQUEST_MAX_WAIT_SEC, REQUEST_WAIT_SECfrom api.db import ActiveEnumfrom api.db.db_models import APITokenfrom api.utils.json_encode import CustomJSONEncoder, json_dumps-from api.utils import get_uuidfrom rag.utils.mcp_tool_call_conn import MCPToolCallSession, close_multiple_mcp_toolcall_sessionsrequests.models.complexjson.dumps = functools.partial(json.dumps, cls=CustomJSONEncoder)@@ -410,9 +408,9 @@ def get_error_operating_result(message="Operating error"):return get_result(code=settings.RetCode.OPERATING_ERROR, message=message)-def generate_confirmation_token(tenant_id):- serializer = URLSafeTimedSerializer(tenant_id)- return "ragflow-" + serializer.dumps(get_uuid(), salt=tenant_id)[2:34]+def generate_confirmation_token():+ import secrets+ return "ragflow-" + secrets.token_urlsafe(32)def get_parser_config(chunk_method, parser_config):diff --git a/rag/utils/redis_conn.py b/rag/utils/redis_conn.pyindex 17248db6d3..63010576e0 100644--- a/rag/utils/redis_conn.py+++ b/rag/utils/redis_conn.py@@ -71,16 +71,21 @@ class RedisDB:def __open__(self):try:- self.REDIS = redis.StrictRedis(- host=self.config["host"].split(":")[0],- port=int(self.config.get("host", ":6379").split(":")[1]),- db=int(self.config.get("db", 1)),- password=self.config.get("password"),- decode_responses=True,- )+ conn_params = {+ "host": self.config["host"].split(":")[0],+ "port": int(self.config.get("host", ":6379").split(":")[1]),+ "db": int(self.config.get("db", 1)),+ "decode_responses": True,+ }+ password = self.config.get("password")+ if password:+ conn_params["password"] = password++ self.REDIS = redis.StrictRedis(**conn_params)+self.register_scripts()- except Exception:- logging.warning("Redis can't be connected.")+ except Exception as e:+ logging.warning(f"Redis can't be connected. Error: {str(e)}")return self.REDISdef health(self):