isage-middleware 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of isage-middleware might be problematic. Click here for more details.
- isage_middleware-0.1.0.dist-info/METADATA +424 -0
- isage_middleware-0.1.0.dist-info/RECORD +191 -0
- isage_middleware-0.1.0.dist-info/WHEEL +5 -0
- isage_middleware-0.1.0.dist-info/top_level.txt +1 -0
- sage/__init__.py +2 -0
- sage/__pycache__/__init__.cpython-311.opt-2.pyc +0 -0
- sage/__pycache__/__init__.cpython-311.pyc +0 -0
- sage/middleware/__init__.py +83 -0
- sage/middleware/__pycache__/__init__.cpython-311.opt-2.pyc +0 -0
- sage/middleware/__pycache__/__init__.cpython-311.pyc +0 -0
- sage/middleware/api/__init__.py +22 -0
- sage/middleware/api/__pycache__/__init__.cpython-311.opt-2.pyc +0 -0
- sage/middleware/api/__pycache__/__init__.cpython-311.pyc +0 -0
- sage/middleware/api/__pycache__/graph_api.cpython-311.opt-2.pyc +0 -0
- sage/middleware/api/__pycache__/graph_api.cpython-311.pyc +0 -0
- sage/middleware/api/__pycache__/kv_api.cpython-311.opt-2.pyc +0 -0
- sage/middleware/api/__pycache__/kv_api.cpython-311.pyc +0 -0
- sage/middleware/api/__pycache__/memory_api.cpython-311.opt-2.pyc +0 -0
- sage/middleware/api/__pycache__/memory_api.cpython-311.pyc +0 -0
- sage/middleware/api/__pycache__/vdb_api.cpython-311.opt-2.pyc +0 -0
- sage/middleware/api/__pycache__/vdb_api.cpython-311.pyc +0 -0
- sage/middleware/api/graph_api.py +74 -0
- sage/middleware/api/kv_api.py +45 -0
- sage/middleware/api/memory_api.py +64 -0
- sage/middleware/api/vdb_api.py +60 -0
- sage/middleware/enterprise/__init__.py +75 -0
- sage/middleware/enterprise/__pycache__/__init__.cpython-311.opt-2.pyc +0 -0
- sage/middleware/enterprise/__pycache__/__init__.cpython-311.pyc +0 -0
- sage/middleware/enterprise/sage_db/__init__.py +132 -0
- sage/middleware/enterprise/sage_db/__pycache__/__init__.cpython-311.opt-2.pyc +0 -0
- sage/middleware/enterprise/sage_db/__pycache__/__init__.cpython-311.pyc +0 -0
- sage/middleware/enterprise/sage_db/__pycache__/sage_db.cpython-311.opt-2.pyc +0 -0
- sage/middleware/enterprise/sage_db/__pycache__/sage_db.cpython-311.pyc +0 -0
- sage/middleware/enterprise/sage_db/python/__init__.py +7 -0
- sage/middleware/enterprise/sage_db/python/__pycache__/__init__.cpython-311.opt-2.pyc +0 -0
- sage/middleware/enterprise/sage_db/python/__pycache__/__init__.cpython-311.pyc +0 -0
- sage/middleware/enterprise/sage_db/python/__pycache__/sage_db.cpython-311.opt-2.pyc +0 -0
- sage/middleware/enterprise/sage_db/python/__pycache__/sage_db.cpython-311.pyc +0 -0
- sage/middleware/enterprise/sage_db/python/sage_db.py +44 -0
- sage/middleware/enterprise/sage_db/sage_db.py +395 -0
- sage/middleware/enterprise/sage_db/tests/__pycache__/test_python.cpython-311.opt-2.pyc +0 -0
- sage/middleware/enterprise/sage_db/tests/__pycache__/test_python.cpython-311.pyc +0 -0
- sage/middleware/enterprise/sage_db/tests/test_python.py +144 -0
- sage/middleware/examples/__pycache__/api_usage_tutorial.cpython-311.opt-2.pyc +0 -0
- sage/middleware/examples/__pycache__/api_usage_tutorial.cpython-311.pyc +0 -0
- sage/middleware/examples/__pycache__/dag_microservices_demo.cpython-311.opt-2.pyc +0 -0
- sage/middleware/examples/__pycache__/dag_microservices_demo.cpython-311.pyc +0 -0
- sage/middleware/examples/__pycache__/microservices_demo.cpython-311.opt-2.pyc +0 -0
- sage/middleware/examples/__pycache__/microservices_demo.cpython-311.pyc +0 -0
- sage/middleware/examples/__pycache__/microservices_integration_demo.cpython-311.opt-2.pyc +0 -0
- sage/middleware/examples/__pycache__/microservices_integration_demo.cpython-311.pyc +0 -0
- sage/middleware/examples/__pycache__/microservices_registration_demo.cpython-311.opt-2.pyc +0 -0
- sage/middleware/examples/__pycache__/microservices_registration_demo.cpython-311.pyc +0 -0
- sage/middleware/examples/api_usage_tutorial.py +339 -0
- sage/middleware/examples/dag_microservices_demo.py +220 -0
- sage/middleware/examples/microservices_demo.py +0 -0
- sage/middleware/examples/microservices_integration_demo.py +373 -0
- sage/middleware/examples/microservices_registration_demo.py +144 -0
- sage/middleware/py.typed +2 -0
- sage/middleware/services/graph/__init__.py +8 -0
- sage/middleware/services/graph/__pycache__/__init__.cpython-311.opt-2.pyc +0 -0
- sage/middleware/services/graph/__pycache__/__init__.cpython-311.pyc +0 -0
- sage/middleware/services/graph/__pycache__/graph_index.cpython-311.opt-2.pyc +0 -0
- sage/middleware/services/graph/__pycache__/graph_index.cpython-311.pyc +0 -0
- sage/middleware/services/graph/__pycache__/graph_service.cpython-311.opt-2.pyc +0 -0
- sage/middleware/services/graph/__pycache__/graph_service.cpython-311.pyc +0 -0
- sage/middleware/services/graph/examples/__pycache__/graph_demo.cpython-311.opt-2.pyc +0 -0
- sage/middleware/services/graph/examples/__pycache__/graph_demo.cpython-311.pyc +0 -0
- sage/middleware/services/graph/examples/graph_demo.py +177 -0
- sage/middleware/services/graph/graph_index.py +194 -0
- sage/middleware/services/graph/graph_service.py +541 -0
- sage/middleware/services/graph/search_engine/__init__.py +0 -0
- sage/middleware/services/graph/search_engine/__pycache__/__init__.cpython-311.opt-2.pyc +0 -0
- sage/middleware/services/graph/search_engine/__pycache__/__init__.cpython-311.pyc +0 -0
- sage/middleware/services/graph/search_engine/__pycache__/base_graph_index.cpython-311.opt-2.pyc +0 -0
- sage/middleware/services/graph/search_engine/__pycache__/base_graph_index.cpython-311.pyc +0 -0
- sage/middleware/services/graph/search_engine/base_graph_index.py +0 -0
- sage/middleware/services/kv/__init__.py +8 -0
- sage/middleware/services/kv/__pycache__/__init__.cpython-311.opt-2.pyc +0 -0
- sage/middleware/services/kv/__pycache__/__init__.cpython-311.pyc +0 -0
- sage/middleware/services/kv/__pycache__/kv_service.cpython-311.opt-2.pyc +0 -0
- sage/middleware/services/kv/__pycache__/kv_service.cpython-311.pyc +0 -0
- sage/middleware/services/kv/examples/__pycache__/kv_demo.cpython-311.opt-2.pyc +0 -0
- sage/middleware/services/kv/examples/__pycache__/kv_demo.cpython-311.pyc +0 -0
- sage/middleware/services/kv/examples/kv_demo.py +213 -0
- sage/middleware/services/kv/kv_service.py +306 -0
- sage/middleware/services/kv/search_engine/__init__.py +0 -0
- sage/middleware/services/kv/search_engine/__pycache__/__init__.cpython-311.opt-2.pyc +0 -0
- sage/middleware/services/kv/search_engine/__pycache__/__init__.cpython-311.pyc +0 -0
- sage/middleware/services/kv/search_engine/__pycache__/base_kv_index.cpython-311.opt-2.pyc +0 -0
- sage/middleware/services/kv/search_engine/__pycache__/base_kv_index.cpython-311.pyc +0 -0
- sage/middleware/services/kv/search_engine/__pycache__/bm25s_index.cpython-311.opt-2.pyc +0 -0
- sage/middleware/services/kv/search_engine/__pycache__/bm25s_index.cpython-311.pyc +0 -0
- sage/middleware/services/kv/search_engine/base_kv_index.py +75 -0
- sage/middleware/services/kv/search_engine/bm25s_index.py +238 -0
- sage/middleware/services/memory/__init__.py +12 -0
- sage/middleware/services/memory/__pycache__/__init__.cpython-311.opt-2.pyc +0 -0
- sage/middleware/services/memory/__pycache__/__init__.cpython-311.pyc +0 -0
- sage/middleware/services/memory/__pycache__/memory_service.cpython-311.opt-2.pyc +0 -0
- sage/middleware/services/memory/__pycache__/memory_service.cpython-311.pyc +0 -0
- sage/middleware/services/memory/examples/__pycache__/dag_microservices_demo.cpython-311.opt-2.pyc +0 -0
- sage/middleware/services/memory/examples/__pycache__/dag_microservices_demo.cpython-311.pyc +0 -0
- sage/middleware/services/memory/examples/__pycache__/memory_demo.cpython-311.opt-2.pyc +0 -0
- sage/middleware/services/memory/examples/__pycache__/memory_demo.cpython-311.pyc +0 -0
- sage/middleware/services/memory/examples/dag_microservices_demo.py +220 -0
- sage/middleware/services/memory/examples/memory_demo.py +490 -0
- sage/middleware/services/memory/memory_collection/__pycache__/base_collection.cpython-311.opt-2.pyc +0 -0
- sage/middleware/services/memory/memory_collection/__pycache__/base_collection.cpython-311.pyc +0 -0
- sage/middleware/services/memory/memory_collection/__pycache__/graph_collection.cpython-311.opt-2.pyc +0 -0
- sage/middleware/services/memory/memory_collection/__pycache__/graph_collection.cpython-311.pyc +0 -0
- sage/middleware/services/memory/memory_collection/__pycache__/kv_collection.cpython-311.opt-2.pyc +0 -0
- sage/middleware/services/memory/memory_collection/__pycache__/kv_collection.cpython-311.pyc +0 -0
- sage/middleware/services/memory/memory_collection/__pycache__/vdb_collection.cpython-311.opt-2.pyc +0 -0
- sage/middleware/services/memory/memory_collection/__pycache__/vdb_collection.cpython-311.pyc +0 -0
- sage/middleware/services/memory/memory_collection/base_collection.py +0 -0
- sage/middleware/services/memory/memory_collection/graph_collection.py +0 -0
- sage/middleware/services/memory/memory_collection/kv_collection.py +0 -0
- sage/middleware/services/memory/memory_collection/vdb_collection.py +0 -0
- sage/middleware/services/memory/memory_service.py +474 -0
- sage/middleware/services/memory/utils/__init__.py +0 -0
- sage/middleware/services/memory/utils/__pycache__/__init__.cpython-311.opt-2.pyc +0 -0
- sage/middleware/services/memory/utils/__pycache__/__init__.cpython-311.pyc +0 -0
- sage/middleware/services/memory/utils/__pycache__/path_utils.cpython-311.opt-2.pyc +0 -0
- sage/middleware/services/memory/utils/__pycache__/path_utils.cpython-311.pyc +0 -0
- sage/middleware/services/memory/utils/path_utils.py +0 -0
- sage/middleware/services/vdb/__init__.py +8 -0
- sage/middleware/services/vdb/__pycache__/__init__.cpython-311.opt-2.pyc +0 -0
- sage/middleware/services/vdb/__pycache__/__init__.cpython-311.pyc +0 -0
- sage/middleware/services/vdb/__pycache__/vdb_service.cpython-311.opt-2.pyc +0 -0
- sage/middleware/services/vdb/__pycache__/vdb_service.cpython-311.pyc +0 -0
- sage/middleware/services/vdb/examples/__pycache__/vdb_demo.cpython-311.opt-2.pyc +0 -0
- sage/middleware/services/vdb/examples/__pycache__/vdb_demo.cpython-311.pyc +0 -0
- sage/middleware/services/vdb/examples/vdb_demo.py +447 -0
- sage/middleware/services/vdb/search_engine/__init__.py +0 -0
- sage/middleware/services/vdb/search_engine/__pycache__/__init__.cpython-311.opt-2.pyc +0 -0
- sage/middleware/services/vdb/search_engine/__pycache__/__init__.cpython-311.pyc +0 -0
- sage/middleware/services/vdb/search_engine/__pycache__/base_vdb_index.cpython-311.opt-2.pyc +0 -0
- sage/middleware/services/vdb/search_engine/__pycache__/base_vdb_index.cpython-311.pyc +0 -0
- sage/middleware/services/vdb/search_engine/__pycache__/faiss_index.cpython-311.opt-2.pyc +0 -0
- sage/middleware/services/vdb/search_engine/__pycache__/faiss_index.cpython-311.pyc +0 -0
- sage/middleware/services/vdb/search_engine/base_vdb_index.py +58 -0
- sage/middleware/services/vdb/search_engine/faiss_index.py +461 -0
- sage/middleware/services/vdb/vdb_service.py +433 -0
- sage/middleware/utils/__init__.py +5 -0
- sage/middleware/utils/__pycache__/__init__.cpython-311.opt-2.pyc +0 -0
- sage/middleware/utils/__pycache__/__init__.cpython-311.pyc +0 -0
- sage/middleware/utils/embedding/__init__.py +35 -0
- sage/middleware/utils/embedding/__pycache__/__init__.cpython-311.opt-2.pyc +0 -0
- sage/middleware/utils/embedding/__pycache__/__init__.cpython-311.pyc +0 -0
- sage/middleware/utils/embedding/__pycache__/_cohere.cpython-311.opt-2.pyc +0 -0
- sage/middleware/utils/embedding/__pycache__/_cohere.cpython-311.pyc +0 -0
- sage/middleware/utils/embedding/__pycache__/bedrock.cpython-311.opt-2.pyc +0 -0
- sage/middleware/utils/embedding/__pycache__/bedrock.cpython-311.pyc +0 -0
- sage/middleware/utils/embedding/__pycache__/embedding_api.cpython-311.opt-2.pyc +0 -0
- sage/middleware/utils/embedding/__pycache__/embedding_api.cpython-311.pyc +0 -0
- sage/middleware/utils/embedding/__pycache__/embedding_model.cpython-311.opt-2.pyc +0 -0
- sage/middleware/utils/embedding/__pycache__/embedding_model.cpython-311.pyc +0 -0
- sage/middleware/utils/embedding/__pycache__/hf.cpython-311.opt-2.pyc +0 -0
- sage/middleware/utils/embedding/__pycache__/hf.cpython-311.pyc +0 -0
- sage/middleware/utils/embedding/__pycache__/instructor.cpython-311.opt-2.pyc +0 -0
- sage/middleware/utils/embedding/__pycache__/instructor.cpython-311.pyc +0 -0
- sage/middleware/utils/embedding/__pycache__/jina.cpython-311.opt-2.pyc +0 -0
- sage/middleware/utils/embedding/__pycache__/jina.cpython-311.pyc +0 -0
- sage/middleware/utils/embedding/__pycache__/lollms.cpython-311.opt-2.pyc +0 -0
- sage/middleware/utils/embedding/__pycache__/lollms.cpython-311.pyc +0 -0
- sage/middleware/utils/embedding/__pycache__/mockembedder.cpython-311.opt-2.pyc +0 -0
- sage/middleware/utils/embedding/__pycache__/mockembedder.cpython-311.pyc +0 -0
- sage/middleware/utils/embedding/__pycache__/nvidia_openai.cpython-311.opt-2.pyc +0 -0
- sage/middleware/utils/embedding/__pycache__/nvidia_openai.cpython-311.pyc +0 -0
- sage/middleware/utils/embedding/__pycache__/ollama.cpython-311.opt-2.pyc +0 -0
- sage/middleware/utils/embedding/__pycache__/ollama.cpython-311.pyc +0 -0
- sage/middleware/utils/embedding/__pycache__/openai.cpython-311.opt-2.pyc +0 -0
- sage/middleware/utils/embedding/__pycache__/openai.cpython-311.pyc +0 -0
- sage/middleware/utils/embedding/__pycache__/siliconcloud.cpython-311.opt-2.pyc +0 -0
- sage/middleware/utils/embedding/__pycache__/siliconcloud.cpython-311.pyc +0 -0
- sage/middleware/utils/embedding/__pycache__/zhipu.cpython-311.opt-2.pyc +0 -0
- sage/middleware/utils/embedding/__pycache__/zhipu.cpython-311.pyc +0 -0
- sage/middleware/utils/embedding/_cohere.py +68 -0
- sage/middleware/utils/embedding/bedrock.py +174 -0
- sage/middleware/utils/embedding/embedding_api.py +12 -0
- sage/middleware/utils/embedding/embedding_model.py +150 -0
- sage/middleware/utils/embedding/hf.py +90 -0
- sage/middleware/utils/embedding/instructor.py +10 -0
- sage/middleware/utils/embedding/jina.py +115 -0
- sage/middleware/utils/embedding/lollms.py +100 -0
- sage/middleware/utils/embedding/mockembedder.py +46 -0
- sage/middleware/utils/embedding/nvidia_openai.py +97 -0
- sage/middleware/utils/embedding/ollama.py +97 -0
- sage/middleware/utils/embedding/openai.py +112 -0
- sage/middleware/utils/embedding/siliconcloud.py +133 -0
- sage/middleware/utils/embedding/zhipu.py +85 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""
|
|
2
|
+
SAGE Middleware Framework
|
|
3
|
+
|
|
4
|
+
This module provides middleware components including API services, database
|
|
5
|
+
integrations, and messaging infrastructure.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
__version__ = "1.0.1"
|
|
9
|
+
|
|
10
|
+
# Core middleware components
|
|
11
|
+
try:
|
|
12
|
+
from .api import *
|
|
13
|
+
except ImportError:
|
|
14
|
+
pass
|
|
15
|
+
|
|
16
|
+
try:
|
|
17
|
+
from .services import *
|
|
18
|
+
except ImportError:
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
try:
|
|
22
|
+
from .utils import *
|
|
23
|
+
except ImportError:
|
|
24
|
+
pass
|
|
25
|
+
|
|
26
|
+
# Enterprise features (if available and licensed)
|
|
27
|
+
try:
|
|
28
|
+
from .enterprise import *
|
|
29
|
+
except ImportError:
|
|
30
|
+
# Enterprise features not available or not licensed
|
|
31
|
+
pass
|
|
32
|
+
|
|
33
|
+
__all__ = [
|
|
34
|
+
"__version__",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
__version__ = "2.0.0"
|
|
38
|
+
__author__ = "SAGE Team"
|
|
39
|
+
__description__ = "SAGE Microservices as Service Tasks"
|
|
40
|
+
|
|
41
|
+
# 微服务组件 - 基于BaseService的服务任务
|
|
42
|
+
try:
|
|
43
|
+
# KV服务
|
|
44
|
+
from .services.kv.kv_service import KVService, create_kv_service_factory
|
|
45
|
+
|
|
46
|
+
# VDB服务
|
|
47
|
+
from .services.vdb.vdb_service import VDBService, create_vdb_service_factory
|
|
48
|
+
|
|
49
|
+
# Memory服务
|
|
50
|
+
from .services.memory.memory_service import MemoryService, create_memory_service_factory
|
|
51
|
+
|
|
52
|
+
# Graph服务
|
|
53
|
+
from .services.graph.graph_service import GraphService, create_graph_service_factory
|
|
54
|
+
|
|
55
|
+
__all__ = [
|
|
56
|
+
# 服务任务类
|
|
57
|
+
"KVService",
|
|
58
|
+
"VDBService",
|
|
59
|
+
"MemoryService",
|
|
60
|
+
"GraphService",
|
|
61
|
+
|
|
62
|
+
# 工厂函数
|
|
63
|
+
"create_kv_service_factory",
|
|
64
|
+
"create_vdb_service_factory",
|
|
65
|
+
"create_memory_service_factory",
|
|
66
|
+
"create_graph_service_factory"
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
except ImportError as e:
|
|
70
|
+
print(f"⚠️ Microservices components not available: {e}")
|
|
71
|
+
print("Some dependencies may be missing for the new microservices architecture")
|
|
72
|
+
__all__ = []
|
|
73
|
+
|
|
74
|
+
# 兼容性:保留原有的memory service导入
|
|
75
|
+
try:
|
|
76
|
+
from .services.memory.memory_service import MemoryService as LegacyMemoryService
|
|
77
|
+
|
|
78
|
+
# 添加到导出列表
|
|
79
|
+
if 'LegacyMemoryService' not in locals().get('__all__', []):
|
|
80
|
+
__all__.extend(['LegacyMemoryService'])
|
|
81
|
+
|
|
82
|
+
except ImportError:
|
|
83
|
+
pass
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""
|
|
2
|
+
SAGE Service API Module
|
|
3
|
+
提供统一的服务API接口
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
# 服务API接口
|
|
7
|
+
try:
|
|
8
|
+
from .kv_api import KVServiceAPI
|
|
9
|
+
from .vdb_api import VDBServiceAPI
|
|
10
|
+
from .memory_api import MemoryServiceAPI
|
|
11
|
+
from .graph_api import GraphServiceAPI
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"KVServiceAPI",
|
|
15
|
+
"VDBServiceAPI",
|
|
16
|
+
"MemoryServiceAPI",
|
|
17
|
+
"GraphServiceAPI"
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
except ImportError as e:
|
|
21
|
+
print(f"⚠️ Some API modules not available: {e}")
|
|
22
|
+
__all__ = []
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Graph Service API Interface
|
|
3
|
+
图数据库服务的API接口定义
|
|
4
|
+
"""
|
|
5
|
+
from typing import Dict, Any, List, Optional
|
|
6
|
+
from abc import ABC, abstractmethod
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class GraphServiceAPI(ABC):
|
|
10
|
+
"""Graph服务API接口"""
|
|
11
|
+
|
|
12
|
+
@abstractmethod
|
|
13
|
+
def add_node(
|
|
14
|
+
self,
|
|
15
|
+
node_id: str,
|
|
16
|
+
node_type: str,
|
|
17
|
+
properties: Optional[Dict[str, Any]] = None
|
|
18
|
+
) -> bool:
|
|
19
|
+
"""添加节点"""
|
|
20
|
+
pass
|
|
21
|
+
|
|
22
|
+
@abstractmethod
|
|
23
|
+
def add_edge(
|
|
24
|
+
self,
|
|
25
|
+
from_node: str,
|
|
26
|
+
to_node: str,
|
|
27
|
+
edge_type: str,
|
|
28
|
+
properties: Optional[Dict[str, Any]] = None
|
|
29
|
+
) -> bool:
|
|
30
|
+
"""添加边"""
|
|
31
|
+
pass
|
|
32
|
+
|
|
33
|
+
@abstractmethod
|
|
34
|
+
def get_node(self, node_id: str) -> Optional[Dict[str, Any]]:
|
|
35
|
+
"""获取节点"""
|
|
36
|
+
pass
|
|
37
|
+
|
|
38
|
+
@abstractmethod
|
|
39
|
+
def get_neighbors(
|
|
40
|
+
self,
|
|
41
|
+
node_id: str,
|
|
42
|
+
edge_type: Optional[str] = None
|
|
43
|
+
) -> List[Dict[str, Any]]:
|
|
44
|
+
"""获取邻居节点"""
|
|
45
|
+
pass
|
|
46
|
+
|
|
47
|
+
@abstractmethod
|
|
48
|
+
def find_path(
|
|
49
|
+
self,
|
|
50
|
+
start_node: str,
|
|
51
|
+
end_node: str,
|
|
52
|
+
max_depth: int = 3
|
|
53
|
+
) -> Optional[List[Dict[str, Any]]]:
|
|
54
|
+
"""查找路径"""
|
|
55
|
+
pass
|
|
56
|
+
|
|
57
|
+
@abstractmethod
|
|
58
|
+
def delete_node(self, node_id: str) -> bool:
|
|
59
|
+
"""删除节点"""
|
|
60
|
+
pass
|
|
61
|
+
|
|
62
|
+
@abstractmethod
|
|
63
|
+
def delete_edge(self, from_node: str, to_node: str, edge_type: str) -> bool:
|
|
64
|
+
"""删除边"""
|
|
65
|
+
pass
|
|
66
|
+
|
|
67
|
+
@abstractmethod
|
|
68
|
+
def query_nodes(
|
|
69
|
+
self,
|
|
70
|
+
node_type: Optional[str] = None,
|
|
71
|
+
properties_filter: Optional[Dict[str, Any]] = None
|
|
72
|
+
) -> List[Dict[str, Any]]:
|
|
73
|
+
"""查询节点"""
|
|
74
|
+
pass
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""
|
|
2
|
+
KV Service API Interface
|
|
3
|
+
键值存储服务的API接口定义
|
|
4
|
+
"""
|
|
5
|
+
from typing import Dict, Any, List, Optional
|
|
6
|
+
from abc import ABC, abstractmethod
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class KVServiceAPI(ABC):
|
|
10
|
+
"""KV服务API接口"""
|
|
11
|
+
|
|
12
|
+
@abstractmethod
|
|
13
|
+
def put(self, key: str, value: Any) -> bool:
|
|
14
|
+
"""存储键值对"""
|
|
15
|
+
pass
|
|
16
|
+
|
|
17
|
+
@abstractmethod
|
|
18
|
+
def get(self, key: str) -> Optional[Any]:
|
|
19
|
+
"""获取值"""
|
|
20
|
+
pass
|
|
21
|
+
|
|
22
|
+
@abstractmethod
|
|
23
|
+
def delete(self, key: str) -> bool:
|
|
24
|
+
"""删除键值对"""
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
@abstractmethod
|
|
28
|
+
def exists(self, key: str) -> bool:
|
|
29
|
+
"""检查键是否存在"""
|
|
30
|
+
pass
|
|
31
|
+
|
|
32
|
+
@abstractmethod
|
|
33
|
+
def list_keys(self, prefix: Optional[str] = None) -> List[str]:
|
|
34
|
+
"""列出所有键或指定前缀的键"""
|
|
35
|
+
pass
|
|
36
|
+
|
|
37
|
+
@abstractmethod
|
|
38
|
+
def size(self) -> int:
|
|
39
|
+
"""获取存储大小"""
|
|
40
|
+
pass
|
|
41
|
+
|
|
42
|
+
@abstractmethod
|
|
43
|
+
def clear(self) -> bool:
|
|
44
|
+
"""清空所有数据"""
|
|
45
|
+
pass
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Memory Service API Interface
|
|
3
|
+
记忆服务的API接口定义
|
|
4
|
+
"""
|
|
5
|
+
from typing import Dict, Any, List, Optional
|
|
6
|
+
from abc import ABC, abstractmethod
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class MemoryServiceAPI(ABC):
|
|
10
|
+
"""Memory服务API接口 - 高级记忆管理"""
|
|
11
|
+
|
|
12
|
+
@abstractmethod
|
|
13
|
+
def store_memory(
|
|
14
|
+
self,
|
|
15
|
+
content: str,
|
|
16
|
+
vector: List[float],
|
|
17
|
+
session_id: Optional[str] = None,
|
|
18
|
+
memory_type: str = "conversation",
|
|
19
|
+
metadata: Optional[Dict[str, Any]] = None
|
|
20
|
+
) -> str:
|
|
21
|
+
"""存储记忆"""
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
@abstractmethod
|
|
25
|
+
def retrieve_memories(
|
|
26
|
+
self,
|
|
27
|
+
query_vector: List[float],
|
|
28
|
+
session_id: Optional[str] = None,
|
|
29
|
+
memory_type: Optional[str] = None,
|
|
30
|
+
top_k: int = 10
|
|
31
|
+
) -> List[Dict[str, Any]]:
|
|
32
|
+
"""检索相关记忆"""
|
|
33
|
+
pass
|
|
34
|
+
|
|
35
|
+
@abstractmethod
|
|
36
|
+
def get_memory(self, memory_id: str) -> Optional[Dict[str, Any]]:
|
|
37
|
+
"""获取特定记忆"""
|
|
38
|
+
pass
|
|
39
|
+
|
|
40
|
+
@abstractmethod
|
|
41
|
+
def delete_memory(self, memory_id: str) -> bool:
|
|
42
|
+
"""删除记忆"""
|
|
43
|
+
pass
|
|
44
|
+
|
|
45
|
+
@abstractmethod
|
|
46
|
+
def search_memories(
|
|
47
|
+
self,
|
|
48
|
+
query: str,
|
|
49
|
+
session_id: Optional[str] = None,
|
|
50
|
+
memory_type: Optional[str] = None,
|
|
51
|
+
top_k: int = 10
|
|
52
|
+
) -> List[Dict[str, Any]]:
|
|
53
|
+
"""基于文本搜索记忆"""
|
|
54
|
+
pass
|
|
55
|
+
|
|
56
|
+
@abstractmethod
|
|
57
|
+
def get_session_memories(self, session_id: str) -> List[Dict[str, Any]]:
|
|
58
|
+
"""获取会话的所有记忆"""
|
|
59
|
+
pass
|
|
60
|
+
|
|
61
|
+
@abstractmethod
|
|
62
|
+
def clear_session_memories(self, session_id: str) -> bool:
|
|
63
|
+
"""清空会话记忆"""
|
|
64
|
+
pass
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""
|
|
2
|
+
VDB Service API Interface
|
|
3
|
+
向量数据库服务的API接口定义
|
|
4
|
+
"""
|
|
5
|
+
from typing import Dict, Any, List, Optional, Tuple
|
|
6
|
+
from abc import ABC, abstractmethod
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class VDBServiceAPI(ABC):
|
|
10
|
+
"""VDB服务API接口"""
|
|
11
|
+
|
|
12
|
+
@abstractmethod
|
|
13
|
+
def add_vectors(self, documents: List[Dict[str, Any]]) -> List[str]:
|
|
14
|
+
"""添加向量文档"""
|
|
15
|
+
pass
|
|
16
|
+
|
|
17
|
+
@abstractmethod
|
|
18
|
+
def search(
|
|
19
|
+
self,
|
|
20
|
+
query_vector: List[float],
|
|
21
|
+
top_k: int = 10,
|
|
22
|
+
similarity_threshold: Optional[float] = None
|
|
23
|
+
) -> List[Dict[str, Any]]:
|
|
24
|
+
"""向量相似性搜索"""
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
@abstractmethod
|
|
28
|
+
def get_vector(self, doc_id: str) -> Optional[Dict[str, Any]]:
|
|
29
|
+
"""获取向量文档"""
|
|
30
|
+
pass
|
|
31
|
+
|
|
32
|
+
@abstractmethod
|
|
33
|
+
def delete_vectors(self, doc_ids: List[str]) -> bool:
|
|
34
|
+
"""删除向量文档"""
|
|
35
|
+
pass
|
|
36
|
+
|
|
37
|
+
@abstractmethod
|
|
38
|
+
def update_vector(self, doc_id: str, document: Dict[str, Any]) -> bool:
|
|
39
|
+
"""更新向量文档"""
|
|
40
|
+
pass
|
|
41
|
+
|
|
42
|
+
@abstractmethod
|
|
43
|
+
def count(self) -> int:
|
|
44
|
+
"""获取向量总数"""
|
|
45
|
+
pass
|
|
46
|
+
|
|
47
|
+
@abstractmethod
|
|
48
|
+
def clear(self) -> bool:
|
|
49
|
+
"""清空所有向量"""
|
|
50
|
+
pass
|
|
51
|
+
|
|
52
|
+
@abstractmethod
|
|
53
|
+
def save_index(self, path: str) -> bool:
|
|
54
|
+
"""保存索引到磁盘"""
|
|
55
|
+
pass
|
|
56
|
+
|
|
57
|
+
@abstractmethod
|
|
58
|
+
def load_index(self, path: str) -> bool:
|
|
59
|
+
"""从磁盘加载索引"""
|
|
60
|
+
pass
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""
|
|
2
|
+
SAGE sage-middleware Enterprise Edition
|
|
3
|
+
企业版功能需要有效的商业许可证
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import os
|
|
7
|
+
import sys
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
# 添加license工具到路径
|
|
11
|
+
_PROJECT_ROOT = Path(__file__).parent.parent.parent.parent.parent.parent.parent
|
|
12
|
+
_LICENSE_TOOLS = _PROJECT_ROOT / "tools" / "license"
|
|
13
|
+
|
|
14
|
+
if _LICENSE_TOOLS.exists():
|
|
15
|
+
sys.path.insert(0, str(_LICENSE_TOOLS))
|
|
16
|
+
sys.path.insert(0, str(_LICENSE_TOOLS / "shared"))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _check_enterprise_license():
|
|
20
|
+
"""检查企业版license"""
|
|
21
|
+
try:
|
|
22
|
+
from shared.validation import LicenseValidator
|
|
23
|
+
|
|
24
|
+
validator = LicenseValidator()
|
|
25
|
+
if not validator.has_valid_license():
|
|
26
|
+
return False
|
|
27
|
+
|
|
28
|
+
features = validator.get_license_features()
|
|
29
|
+
# 检查是否有企业版功能
|
|
30
|
+
required_features = ["enterprise", "high-performance", "enterprise-db", "advanced-analytics"]
|
|
31
|
+
return any(feature in features for feature in required_features)
|
|
32
|
+
|
|
33
|
+
except ImportError:
|
|
34
|
+
# License工具不可用,检查环境变量
|
|
35
|
+
return os.getenv("SAGE_ENTERPRISE_ENABLED", "").lower() in ["true", "1", "yes"]
|
|
36
|
+
except Exception:
|
|
37
|
+
return False
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
# 企业版功能可用性检查
|
|
41
|
+
_ENTERPRISE_AVAILABLE = _check_enterprise_license()
|
|
42
|
+
|
|
43
|
+
# Note: Enterprise license warning is now handled in the main sage package
|
|
44
|
+
# to avoid duplicate warnings when importing multiple enterprise modules
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def require_enterprise_license(func):
|
|
48
|
+
"""装饰器:要求企业版license"""
|
|
49
|
+
def wrapper(*args, **kwargs):
|
|
50
|
+
if not _ENTERPRISE_AVAILABLE:
|
|
51
|
+
raise RuntimeError(
|
|
52
|
+
f"SAGE sage-middleware Enterprise feature requires a valid commercial license. "
|
|
53
|
+
f"This functionality is not available with your current license."
|
|
54
|
+
)
|
|
55
|
+
return func(*args, **kwargs)
|
|
56
|
+
return wrapper
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
# 根据license状态导入功能
|
|
60
|
+
if _ENTERPRISE_AVAILABLE:
|
|
61
|
+
# 导入所有企业版功能
|
|
62
|
+
try:
|
|
63
|
+
# 这里会根据实际的企业版模块来调整
|
|
64
|
+
pass
|
|
65
|
+
except ImportError as e:
|
|
66
|
+
print(f"Warning: Failed to import some enterprise features: {e}")
|
|
67
|
+
else:
|
|
68
|
+
# 企业版功能不可用时的占位符
|
|
69
|
+
pass
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
__all__ = [
|
|
73
|
+
"_ENTERPRISE_AVAILABLE",
|
|
74
|
+
"require_enterprise_license"
|
|
75
|
+
]
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"""
|
|
2
|
+
SAGE Database Extension
|
|
3
|
+
|
|
4
|
+
High-performance vector database with FAISS backend.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import os
|
|
8
|
+
import sys
|
|
9
|
+
import warnings
|
|
10
|
+
from typing import List, Optional
|
|
11
|
+
|
|
12
|
+
__version__ = "0.1.0"
|
|
13
|
+
|
|
14
|
+
# 设置库路径以便找到依赖的 .so 文件
|
|
15
|
+
_current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
16
|
+
if _current_dir not in sys.path:
|
|
17
|
+
sys.path.insert(0, _current_dir)
|
|
18
|
+
|
|
19
|
+
# 设置 LD_LIBRARY_PATH 环境变量
|
|
20
|
+
if "LD_LIBRARY_PATH" in os.environ:
|
|
21
|
+
os.environ["LD_LIBRARY_PATH"] = f"{_current_dir}:{os.environ['LD_LIBRARY_PATH']}"
|
|
22
|
+
else:
|
|
23
|
+
os.environ["LD_LIBRARY_PATH"] = _current_dir
|
|
24
|
+
|
|
25
|
+
# 尝试导入C++扩展
|
|
26
|
+
_cpp_available = False
|
|
27
|
+
_import_error = None
|
|
28
|
+
|
|
29
|
+
try:
|
|
30
|
+
# 直接导入 C++ 扩展模块
|
|
31
|
+
from . import _sage_db
|
|
32
|
+
|
|
33
|
+
# 导入所有必要的类和函数
|
|
34
|
+
IndexType = _sage_db.IndexType
|
|
35
|
+
DistanceMetric = _sage_db.DistanceMetric
|
|
36
|
+
QueryResult = _sage_db.QueryResult
|
|
37
|
+
SearchParams = _sage_db.SearchParams
|
|
38
|
+
DatabaseConfig = _sage_db.DatabaseConfig
|
|
39
|
+
SageDBException = _sage_db.SageDBException
|
|
40
|
+
|
|
41
|
+
# 检查是否有工厂函数
|
|
42
|
+
if hasattr(_sage_db, 'create_database'):
|
|
43
|
+
create_database = _sage_db.create_database
|
|
44
|
+
else:
|
|
45
|
+
# 如果没有工厂函数,创建一个简单的包装器
|
|
46
|
+
def create_database(dimension, index_type=None, metric=None):
|
|
47
|
+
if index_type is None:
|
|
48
|
+
index_type = IndexType.AUTO
|
|
49
|
+
if metric is None:
|
|
50
|
+
metric = DistanceMetric.L2
|
|
51
|
+
|
|
52
|
+
config = DatabaseConfig()
|
|
53
|
+
config.dimension = dimension
|
|
54
|
+
config.index_type = index_type
|
|
55
|
+
config.distance_metric = metric
|
|
56
|
+
return _sage_db.SageDB(config)
|
|
57
|
+
|
|
58
|
+
# 导入核心 SageDB 类
|
|
59
|
+
SageDB = _sage_db.SageDB
|
|
60
|
+
|
|
61
|
+
_cpp_available = True
|
|
62
|
+
print("✓ SAGE DB C++ extension loaded successfully")
|
|
63
|
+
|
|
64
|
+
except ImportError as e:
|
|
65
|
+
_import_error = str(e)
|
|
66
|
+
warnings.warn(f"SAGE DB C++ extension not available: {e}")
|
|
67
|
+
|
|
68
|
+
# 提供 fallback 实现
|
|
69
|
+
class SageDB:
|
|
70
|
+
"""Fallback SageDB implementation"""
|
|
71
|
+
def __init__(self, *args, **kwargs):
|
|
72
|
+
raise ImportError(f"SAGE DB C++ extension not available: {_import_error}")
|
|
73
|
+
|
|
74
|
+
class IndexType:
|
|
75
|
+
FLAT = "FLAT"
|
|
76
|
+
IVF_FLAT = "IVF_FLAT"
|
|
77
|
+
HNSW = "HNSW"
|
|
78
|
+
AUTO = "AUTO"
|
|
79
|
+
|
|
80
|
+
class DistanceMetric:
|
|
81
|
+
L2 = "L2"
|
|
82
|
+
INNER_PRODUCT = "INNER_PRODUCT"
|
|
83
|
+
COSINE = "COSINE"
|
|
84
|
+
|
|
85
|
+
class QueryResult:
|
|
86
|
+
def __init__(self, id, score, metadata=None):
|
|
87
|
+
self.id = id
|
|
88
|
+
self.score = score
|
|
89
|
+
self.metadata = metadata or {}
|
|
90
|
+
|
|
91
|
+
class SearchParams:
|
|
92
|
+
def __init__(self, k=10):
|
|
93
|
+
self.k = k
|
|
94
|
+
|
|
95
|
+
class DatabaseConfig:
|
|
96
|
+
def __init__(self):
|
|
97
|
+
self.dimension = 128
|
|
98
|
+
self.index_type = IndexType.AUTO
|
|
99
|
+
self.distance_metric = DistanceMetric.L2
|
|
100
|
+
|
|
101
|
+
class SageDBException(Exception):
|
|
102
|
+
pass
|
|
103
|
+
|
|
104
|
+
def create_database(*args, **kwargs):
|
|
105
|
+
raise ImportError(f"SAGE DB C++ extension not available: {_import_error}")
|
|
106
|
+
|
|
107
|
+
# 导出的API
|
|
108
|
+
__all__ = [
|
|
109
|
+
'SageDB',
|
|
110
|
+
'IndexType',
|
|
111
|
+
'DistanceMetric',
|
|
112
|
+
'QueryResult',
|
|
113
|
+
'SearchParams',
|
|
114
|
+
'DatabaseConfig',
|
|
115
|
+
'SageDBException',
|
|
116
|
+
'create_database',
|
|
117
|
+
'is_available',
|
|
118
|
+
'get_status'
|
|
119
|
+
]
|
|
120
|
+
|
|
121
|
+
# 状态检查函数
|
|
122
|
+
def is_available() -> bool:
|
|
123
|
+
"""Check if SAGE DB is available"""
|
|
124
|
+
return _cpp_available
|
|
125
|
+
|
|
126
|
+
def get_status() -> dict:
|
|
127
|
+
"""Get detailed status information"""
|
|
128
|
+
return {
|
|
129
|
+
'cpp_extension': _cpp_available,
|
|
130
|
+
'import_error': _import_error,
|
|
131
|
+
'fully_available': _cpp_available
|
|
132
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Python interface for SAGE Database.
|
|
3
|
+
|
|
4
|
+
This module provides a Python interface to the SAGE vector database.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
class SageDB:
|
|
8
|
+
"""
|
|
9
|
+
SAGE Database Python interface.
|
|
10
|
+
|
|
11
|
+
In minimal mode (without C++ extensions), this provides a placeholder
|
|
12
|
+
implementation that raises appropriate errors.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
def __init__(self, **kwargs):
|
|
16
|
+
"""Initialize SAGE Database."""
|
|
17
|
+
# Check if C++ extension is available
|
|
18
|
+
try:
|
|
19
|
+
# Try to load the C++ extension
|
|
20
|
+
import sage_ext.sage_db._sage_db_cpp
|
|
21
|
+
self._impl = sage_ext.sage_db._sage_db_cpp.SageDB(**kwargs)
|
|
22
|
+
self._has_cpp = True
|
|
23
|
+
except ImportError:
|
|
24
|
+
# C++ extension not available - minimal mode
|
|
25
|
+
self._impl = None
|
|
26
|
+
self._has_cpp = False
|
|
27
|
+
raise RuntimeError(
|
|
28
|
+
"SAGE Database C++ extension not available. "
|
|
29
|
+
"Please use full installation mode for vector database features."
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
def add_documents(self, documents, embeddings=None):
|
|
33
|
+
"""Add documents to the database."""
|
|
34
|
+
if not self._has_cpp:
|
|
35
|
+
raise RuntimeError("C++ extension required for database operations")
|
|
36
|
+
return self._impl.add_documents(documents, embeddings)
|
|
37
|
+
|
|
38
|
+
def search(self, query, k=10):
|
|
39
|
+
"""Search for similar documents."""
|
|
40
|
+
if not self._has_cpp:
|
|
41
|
+
raise RuntimeError("C++ extension required for database operations")
|
|
42
|
+
return self._impl.search(query, k)
|
|
43
|
+
|
|
44
|
+
__all__ = ['SageDB']
|