Skip to main content

SAGE Middleware - Domain Operators and Service Components (L4)

Project description

SAGE Middleware(中间件)

用于构建带有 AI 能力的流式数据应用的中间件层

Python Version License PyPI

📋 Overview

SAGE Middleware 是 SAGE 框架的 L4 中间件层,提供高性能的数据处理组件和 AI 能力集成。它集成了多家大模型提供商、异步任务调度、安全鉴权以及核心数据处理组件(向量数据库、流处理引擎等)。

🧭 Governance / 团队协作制度

本仓库协作规范与质量门槛请参考:

  • .github/copilot-instructions.md
  • quickstart.sh
  • hooks/pre-commit
  • hooks/pre-push

✨ Key Features

  • 🤖 LLM 推理
    • sageLLM ✅ 推荐:统一 LLM 推理引擎,支持 CUDA/Ascend/Mock 后端
  • 🔎 检索与向量:RAG、BM25、FAISS 等
  • 📋 任务调度:Celery 异步任务
  • 🔐 安全鉴权:JWT、密码学工具
  • ⚙️ 核心组件:
    • sage_db:数据库/向量存储相关组件(含 C/C++ 扩展)
    • sage_flow:高性能向量流处理(可能包含扩展或独立子模块)

🚀 Installation

Basic Installation

pip install isage-middleware

Development Installation

git clone https://github.com/intellistream/SAGE.git
cd SAGE/packages/sage-middleware
pip install -e .

说明:中间件组件(sage_db/sage_flow/sage_tsdb 等)现已随源码直接提供或通过 pip 依赖分发,无需初始化任何子模块。

With Optional Dependencies

# 可选:Embedding 相关支持
pip install isage-common[embedding]

# 可选:与完整 SAGE 框架集成
pip install isage-middleware[sage]

📖 Quick Start

LLM 推理(推荐:sageLLM)

from sage.middleware.operators.llm import SageLLMGenerator

# 自动选择最佳后端
generator = SageLLMGenerator(
    model_path="Qwen/Qwen2.5-7B-Instruct",
    backend_type="auto",  # auto/cuda/ascend/mock
    temperature=0.7,
    max_tokens=2048,
)

result = generator.execute("你好,世界!")
print(result)

API 客户端

from sage.middleware.api.client import APIClient
from sage.middleware.auth.jwt import JWTManager

client = APIClient()
jwt_manager = JWTManager()

resp = client.chat_completion(
    provider="openai",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(resp)

📖 说明:LLM 推理默认使用 sageLLM,建议通过统一配置管理模型后端。

📦 Package Structure

sage-middleware/
├── src/
│   └── sage/
│       └── middleware/
│           ├── __init__.py
│           ├── operators/          # Dataflow operators
│           │   ├── llm/           # LLM operators (sageLLM)
│           │   ├── rag/           # RAG operators
│           │   └── agentic/       # Agent operators
│           ├── components/         # Core components
│           │   ├── sage_db/       # Vector database (C++ extensions)
│           │   ├── sage_flow/     # Stream processing (C++ extensions)
│           │   ├── sage_tsdb/     # Time-series DB (C++ extensions)
│           │   ├── sage_mem/      # Memory management
│           │   └── sage_refiner/  # Context compression
│           ├── api/                # API clients
│           └── auth/               # Authentication
├── tests/
│   ├── unit/
│   └── integration/
├── docs/
│   └── governance/                # Team collaboration
├── README.md
├── pyproject.toml
└── setup.py

🔧 Configuration

配置可以通过以下方式提供:

  • 环境变量
  • YAML/TOML 配置文件
  • 直接通过 API 参数

配置示例

# config.yaml
middleware:
  auth:
    secret_key: "your-secret-key"  # pragma: allowlist secret
    algorithm: "HS256"
  providers:
    openai:
      api_key: "sk-..."  # pragma: allowlist secret
      base_url: "https://api.openai.com/v1"

📚 Documentation

🧪 Testing

# 运行单元测试
pytest tests/unit -v

# 运行集成测试
pytest tests/integration -v

# 运行所有测试并生成覆盖率报告
pytest --cov=sage.middleware --cov-report=html

🤝 Contributing

欢迎贡献!请参阅:

新增中间件组件规范

当添加新的中间件组件时,请遵循以下要求:

  1. 目录结构: 在 src/sage/middleware/components/ 下创建组件目录
  2. C++ 扩展: 如包含 C++ 扩展,必须遵守依赖约束(参见下文详细规范)
  3. 构建脚本: 提供标准的 build.sh,支持 --install-deps
  4. setup.py 集成: 在 setup.py 中添加构建方法
  5. 测试: 添加单元测试和集成测试
  6. 文档: 更新 README 和相关文档

📄 License

本项目采用 MIT License - 详见 LICENSE 文件

🔗 Related Packages

  • sage-kernel: 核心计算引擎(L3)
  • sage-common: 通用工具(L1)
  • sage-libs: 可复用算法库(L3)
  • sage-platform: 平台服务(L2)
  • isage-vdb: 向量数据库(独立包)
  • isage-neuromem: 内存管理系统(独立包)
  • isage-refiner: 上下文压缩(独立包)

📮 Support


Part of the SAGE Framework | 主仓库

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

isage_middleware-0.2.4.31.tar.gz (154.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

isage_middleware-0.2.4.31-py2.py3-none-any.whl (202.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file isage_middleware-0.2.4.31.tar.gz.

File metadata

  • Download URL: isage_middleware-0.2.4.31.tar.gz
  • Upload date:
  • Size: 154.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for isage_middleware-0.2.4.31.tar.gz
Algorithm Hash digest
SHA256 5b84bfabc613e6949c00a50531bd746427eed4fdb0363eb4158f850afff0fa86
MD5 cda811c1429373f993708b0631829138
BLAKE2b-256 f30521277edd3cdf8b2c53e5551a4d341fc95ce98b04d82a27e9ca6a6ed19443

See more details on using hashes here.

File details

Details for the file isage_middleware-0.2.4.31-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for isage_middleware-0.2.4.31-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1dcf9781276306ec5e3464b6d332a9533127416e2bfbd553a5e1b10dbf939503
MD5 d94182cf2b7f1ea74c843a1d49a45adb
BLAKE2b-256 51bdab65717c0e9e429d67a3bde420daea9b50e953e69bc415f4d5fac5498df6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page