- 将 api 测试重组为 integration 测试 - 新增 unit 和 e2e 测试目录分类 - 新增 testing-guidelines.md 测试指南文档 - 更新 pyproject.toml 和 run_tests.sh 以适配新结构 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
import os
|
|
|
|
from ..config import config
|
|
from .factory import KnowledgeBaseFactory
|
|
from .implementations.dify import DifyKB
|
|
from .manager import KnowledgeBaseManager
|
|
|
|
_LITE_MODE = os.environ.get("LITE_MODE", "").lower() in ("true", "1")
|
|
_SKIP_APP_INIT = os.environ.get("YUXI_SKIP_APP_INIT") == "1"
|
|
|
|
if not _LITE_MODE:
|
|
from .graphs.upload_graph_service import UploadGraphService
|
|
from .implementations.lightrag import LightRagKB
|
|
from .implementations.milvus import MilvusKB
|
|
|
|
# 注册知识库类型
|
|
KnowledgeBaseFactory.register("milvus", MilvusKB, {"description": "基于 Milvus 的生产级向量知识库,适合高性能部署"})
|
|
KnowledgeBaseFactory.register("lightrag", LightRagKB, {"description": "基于图的知识库,支持实体关系构建和复杂查询"})
|
|
|
|
KnowledgeBaseFactory.register("dify", DifyKB, {"description": "连接 Dify Dataset 的只读检索知识库"})
|
|
|
|
# 创建知识库管理器
|
|
work_dir = os.path.join(config.save_dir, "knowledge_base_data")
|
|
knowledge_base = KnowledgeBaseManager(work_dir)
|
|
|
|
# 创建图数据库实例
|
|
if _LITE_MODE or _SKIP_APP_INIT:
|
|
from ..utils import logger
|
|
|
|
class _LiteGraphStub:
|
|
"""Lite 模式下的图数据库占位实例,所有操作报告为不可用"""
|
|
|
|
def is_running(self):
|
|
return False
|
|
|
|
def get_graph_info(self, *args, **kwargs):
|
|
return None
|
|
|
|
graph_base = _LiteGraphStub()
|
|
# 向后兼容
|
|
GraphDatabase = _LiteGraphStub
|
|
if _LITE_MODE:
|
|
logger.info("LITE_MODE enabled, knowledge graph services disabled")
|
|
else:
|
|
logger.info("YUXI_SKIP_APP_INIT enabled, knowledge graph services disabled for current process")
|
|
else:
|
|
graph_base = UploadGraphService()
|
|
# 向后兼容:让 GraphDatabase 指向 UploadGraphService
|
|
GraphDatabase = UploadGraphService
|
|
|
|
__all__ = ["GraphDatabase", "knowledge_base", "graph_base"]
|