From 6768fa9ed3b944f06bb9511c481db581d55a358c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=82=96=E6=B3=BD=E6=B6=9B?= Date: Wed, 25 Feb 2026 19:09:53 +0800 Subject: [PATCH] =?UTF-8?q?fix(kb):=20=E4=BF=AE=E5=A4=8D=20worker=20?= =?UTF-8?q?=E5=AE=B9=E5=99=A8=20=E8=8E=B7=E5=8F=96=E4=B8=8D=E5=88=B0=20?= =?UTF-8?q?=E7=9F=A5=E8=AF=86=E5=BA=93=E5=AE=9E=E4=BE=8B=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/knowledge/manager.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/knowledge/manager.py b/src/knowledge/manager.py index a74192c4..a9dc4fee 100644 --- a/src/knowledge/manager.py +++ b/src/knowledge/manager.py @@ -175,16 +175,28 @@ class KnowledgeBaseManager: kb_repo = KnowledgeBaseRepository() rows = await kb_repo.get_all() - all_databases = [] + metadata_reloaded_types: set[str] = set() for row in rows: - kb_instance = self._get_or_create_kb_instance(row.kb_type or "lightrag") + kb_type = row.kb_type or "lightrag" + kb_instance = self._get_or_create_kb_instance(kb_type) db_info = kb_instance.get_database_info(row.db_id) - if db_info: - # 补充 share_config 和 additional_params - db_info["share_config"] = row.share_config or {"is_shared": True, "accessible_departments": []} - db_info["additional_params"] = ensure_chunk_defaults_in_additional_params(row.additional_params) - all_databases.append(db_info) + if not db_info and kb_type not in metadata_reloaded_types: + try: + await kb_instance._load_metadata() + metadata_reloaded_types.add(kb_type) + except Exception as e: + logger.warning(f"Failed to reload metadata for kb_type={kb_type}: {e}") + db_info = kb_instance.get_database_info(row.db_id) + + if not db_info: + logger.warning(f"Skip database due to missing metadata: db_id={row.db_id}, kb_type={kb_type}") + continue + + # 补充 share_config 和 additional_params + db_info["share_config"] = row.share_config or {"is_shared": True, "accessible_departments": []} + db_info["additional_params"] = ensure_chunk_defaults_in_additional_params(row.additional_params) + all_databases.append(db_info) return {"databases": all_databases} async def check_accessible(self, user: dict, db_id: str) -> bool: