Skip to main content

SAG data engine: ingest, extract, and retrieve over a lightweight event/entity graph

Project description

zleap-sag

SAG 数据引擎:在轻量"事件/实体图"上做 数据写入 / 抽取 / 检索 / 查询

分发名 zleap-sag,import 名 zleap_sag。 接入指南见 docs/接入指南.md

状态(v0.2.0)

已真机验证、生产可用(MySQL + Elasticsearch)。公开入口 DataEngine 编排 load/extract/search;注入式 config(支持 from_env)、解耦 results、统一 SagError、 幂等 init_schema 均就绪。make verify 在 3.11 全绿;ingest→extract→search(全 4 策略) 已对真机 MySQL+ES+LLM+Embedding 端到端跑通(openai 与 litellm 两种 LLM provider 均验证)。

工程能力(对标 cognee):后端适配器层 + 能力模型 + provider 注册表DI 资源容器Alembic 迁移启动健康检查(fail-fast)chunk() 只切不存、可选 litellm 多 provider。 详见 docs/接入指南.md

后端范围(真机验证):关系库 MySQL / PostgreSQL / SQLite / OceanBase;向量库 Elasticsearch / pgvector。 全 4 检索策略在 MySQL+ESPostgreSQL+ESPostgreSQL+pgvector(单库,零 ES)OceanBase(CE v4.4.2.1)+ES 四套组合均端到端跑通。见 docs/接入指南.md

安装与验证(开发)

make install                  # 创建 .venv + 安装开发依赖(可编辑)
make verify                   # 全量验证:lint → type → test → build
make help                     # 查看全部命令

# 解释器需 >= 3.11;如默认 python3 较旧:
make PYTHON=python3.11 verify

用法

from zleap_sag import DataEngine, EngineConfig
from zleap_sag.config import MySQLConfig, ESConfig, LLMConfig, EmbeddingConfig

config = EngineConfig(
    mysql=MySQLConfig(user="sag2", password="...", database="sag2"),
    es=ESConfig(hosts=["http://localhost:9200"]),
    llm=LLMConfig(api_key="...", model="qwen3.6-flash"),
    embedding=EmbeddingConfig(model="bge-large-en-v1.5", dimensions=1024),
)

async with DataEngine(config) as engine:
    await engine.init_schema()                          # 全新库首次建表(幂等,不删表)
    ing = await engine.ingest("doc.md")                 # 加载单个文档
    await engine.extract()                              # 抽取事件/实体
    res = await engine.search("Who founded X?", strategy="multi", top_k=10)
    print(len(res.sections))

也可从环境变量加载配置(SAG_ 前缀,__ 表示嵌套):

export SAG_MYSQL__USER=sag2 SAG_MYSQL__PASSWORD=... SAG_MYSQL__DATABASE=sag2
export SAG_ES__HOSTS='["http://localhost:9200"]'
export SAG_LLM__API_KEY=... SAG_LLM__MODEL=qwen3.6-flash
export SAG_EMBEDDING__MODEL=bge-large-en-v1.5
config = EngineConfig.from_env()          # 或 EngineConfig.from_env(env_file=".env")

统一异常捕获:

from zleap_sag import SagError            # 所有引擎异常的基类

try:
    res = await engine.search("...")
except SagError as e:
    ...

⚠️ 已知限制(v0.2)

多配置隔离(演进中):已引入 DI 资源容器(ResourceContainer + ContextVar 单源解析), 但底层部分核心仍复用进程级全局连接(DB/ES)。因此同一进程内并发多套不同配置尚未完全隔离, 建议一个进程一套配置;完整隔离随核心逐点切换到容器继续推进。

  • 关系库可切换 MySQL / PostgreSQL / SQLite / OceanBase;向量库可切换 Elasticsearch / pgvector(单库 PG 可跑完整引擎)。均已真机验证。
  • ES 目前取 hosts 列表的第一个地址。
  • ingest文件路径为输入(单文档);字符串/只切不存见 DataEngine.chunk()

常用命令

命令 作用
make install 创建 .venv + 安装开发依赖
make lint ruff 检查 + 格式校验
make format ruff 自动修复 + 格式化
make type mypy 类型检查
make test 单元测试(跳过 integration)
make test-integration 集成测试(需 docker mysql/es)
make build 构建 sdist + wheel 并 twine check
make verify lint → type → test → build 全量验证
make clean 清理构建与缓存产物

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

zleap_sag-0.4.0.tar.gz (2.3 MB view details)

Uploaded Source

Built Distribution

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

zleap_sag-0.4.0-py3-none-any.whl (2.4 MB view details)

Uploaded Python 3

File details

Details for the file zleap_sag-0.4.0.tar.gz.

File metadata

  • Download URL: zleap_sag-0.4.0.tar.gz
  • Upload date:
  • Size: 2.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.7

File hashes

Hashes for zleap_sag-0.4.0.tar.gz
Algorithm Hash digest
SHA256 073168a4cac623d626f176e84df3a92931a0c36224b7d62daa60f6d508c803aa
MD5 b1c6cc645cb2679cdbd3deca43043d3f
BLAKE2b-256 83264326e03c2912a0b4305c98c28e2eca9a39808cc35d920115e4471be4f7fd

See more details on using hashes here.

File details

Details for the file zleap_sag-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: zleap_sag-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 2.4 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.7

File hashes

Hashes for zleap_sag-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e7323e25036efc5d3ded478443b0d9f010f6f03cddbd4100afbd22e77a713269
MD5 bca804182f0d4f4744b6588cd502853b
BLAKE2b-256 bf6ecc6e73f84e052fc90cbe55c27d8a2b5186e9007eec981df5e5b49645959c

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