Skip to main content

CogmAIT LangExtract

基于 LangExtract 的知识图谱信息抽取库,默认通过 LiteLLM 调用模型,支持从非结构化文本中提取结构化实体和关系。

特性

  • 🎯 多模式抽取:支持实体抽取、关系抽取、图谱一键抽取
  • 🔌 适配器模式:可插拔的抽取后端,当前支持 LangExtract
  • 📦 异步支持:原生异步 API,支持高并发场景
  • 🧩 分块处理:自动处理长文本,支持并行抽取
  • 🎨 可扩展:支持自定义 Adapter、自定义 Prompt 模板

安装

# 基础安装
pip install cogmait-langextract

# 完整功能(含 Langfuse 集成)
pip install cogmait-langextract[full]

# 开发安装
pip install cogmait-langextract[dev]

快速开始

import asyncio
from cogmait_langextract import (
    GraphExtraction,
    LangextractConfig,
)

async def main():
    # 1. 配置
    config = LangextractConfig(
        model_name="qwen-long",
        api_key="litellm-api-key",
        api_base="http://localhost:4000",
    )

    # 2. 创建抽取器
    extractor = GraphExtraction(
        node_config={"config": config},
        edge_config={"config": config},
    )

    # 3. 执行抽取
    result = await extractor.extract_graph(
        prompt="从文本中提取知识图谱",
        schema={
            "nodes": """
## 公司
### 描述
公司是指依法设立的,以营利为目的从事商业经营活动的企业法人。
### 属性
- 经营范围:公司依法被允许从事的经营项目描述。
## 品牌
### 描述
品牌是指用于识别特定企业、产品或服务的名称、术语、符号、设计或其组合,旨在与竞争对手形成区分。
### 属性
- 品牌名称:品牌的官方全称,如“小米”。
            """,
            "edges": """
## 隶属
### 描述
表示品牌与公司之间的所属关系,即某一品牌归属于特定公司实体所有。
### 关系三元组
- 品牌-隶属-公司
            """
        },
        input_text="华为技术有限公司,主要从事信息与通信技术(ICT)解决方案的研究、开发、销售与服务,其旗下品牌为华为。",
    )

    # 4. 处理结果
    for node in result["nodes"]:
        print(f"节点:{node.node_name} ({node.node_type})")
    for edge in result["edges"]:
        print(f"关系:{edge.source_id} -{edge.relation_type}-> {edge.target_id}")

asyncio.run(main())

核心组件

组件 说明
GraphExtraction 图谱抽取编排器,提供 extract_graph、extract_entities、extract_relations 方法
InformationExtractionFactory 适配器工厂,用于创建和管理抽取适配器
Entity / Relationship 数据模型
GraphNode / GraphEdge 图谱模型
LangextractConfig LangExtract 配置类

文档

入门指南

文档 说明
安装指南 安装方法和环境配置
快速开始 5 分钟上手指南
核心概念 架构设计和核心概念

进阶文档

文档 说明
使用指南 高级配置、Langfuse 集成、自定义 Adapter
[API 参考](docs/API 参考.md) 完整 API 接口文档
示例代码 6 个实用示例代码
[v2 仓库迁移指南](v2 仓库迁移指南.md) 从旧版迁移到新包的指南
[CI/CD 实施指南](CI-CD 实施指南.md) GitLab CI/CD 配置指南

License

Apache 2.0

Metadata

Release files for cogmait-langextract 1.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cogmait-langextract 1.3.1
File Size Uploaded Provenance Actions
cogmait_langextract-1.3.1.tar.gz 75.8 kB Without provenance Details for cogmait_langextract-1.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cogmait-langextract 1.3.1
File Interpreter ABI Platform Actions
cogmait_langextract-1.3.1-py3-none-any.whl Python 3 none any Details for cogmait_langextract-1.3.1-py3-none-any.whl

Total release size: 166.1 kB

Release files / cogmait_langextract-1.3.1.tar.gz

Download URL cogmait_langextract-1.3.1.tar.gz
Size 75.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e63dd39bb354f53b5b3f037af0107d9e5dec864bfad7d4728db027f95290e341
BLAKE2b-256 checksum
How to use checksums
78e15925ad239a82d5f74f2b3f5e4cc7a7bcc48796c17ca53ea755f48a967201
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / cogmait_langextract-1.3.1-py3-none-any.whl

Download URL cogmait_langextract-1.3.1-py3-none-any.whl
Size 90.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
892be1880e4f2055ec4101d7eb6694abe6977dff334ed740a3978f112f1ae350
BLAKE2b-256 checksum
How to use checksums
9ff8aeb5b00c4d0e4ea35f38bdfad173bd995a157a3bdc79e169bb71bcd1e533
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Security for cogmait-langextract 1.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page