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())
核心组件
1.5.0 粗细溯源行为变化
trace_flag=False(也是图抽取默认值)现在返回分块来源,不再表示关闭来源信息;
它跳过基础和模糊对齐。trace_flag=True 额外执行原文对齐,并兼容旧位置字段。
两个模式均返回 text_classes,节点和关系均带 source_entries。
条目的 text 是未经核验的模型摘录;位置可空,不能据此伪造精确原文。
这是公开行为变化,旧调用方升级前需阅读粗细溯源迁移指南。
| 组件 | 说明 |
|---|---|
GraphExtraction |
图谱抽取编排器,提供 extract_graph、extract_entities、extract_relations 方法 |
InformationExtractionFactory |
适配器工厂,用于创建和管理抽取适配器 |
Entity / Relationship |
数据模型 |
SourceEntry / TextClass |
模型摘录、分块关联与可选位置 |
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.5.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cogmait_langextract-1.5.2.tar.gz | 79.3 kB | Without provenance | Details for cogmait_langextract-1.5.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cogmait_langextract-1.5.2-py3-none-any.whl | Python 3 | none | any | Details for cogmait_langextract-1.5.2-py3-none-any.whl |
Total release size: 173.2 kB
Release files / cogmait_langextract-1.5.2.tar.gz
| Download URL | cogmait_langextract-1.5.2.tar.gz |
|---|---|
| Size | 79.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
203190b9ac667b4b933983e7e91cbed431360cad0ade6fd46b30190a8afea8ba
|
|
BLAKE2b-256 checksum How to use checksums |
8b8377ac8fc3c8559dc97606500dd98c38d3fb6a0cfe23c8ec286dd43555216a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.12.11 Windows/11
|
Release files / cogmait_langextract-1.5.2-py3-none-any.whl
| Download URL | cogmait_langextract-1.5.2-py3-none-any.whl |
|---|---|
| Size | 94.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9a129714b7e7007465ae4329e05d1f56ad745f8f135b799c1aac3f4fbe65f121
|
|
BLAKE2b-256 checksum How to use checksums |
4cc593ae262a1b831492b96d1e6a36fbf5246e065a962dd195677d7348aebde0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.12.11 Windows/11
|
Security for cogmait-langextract 1.5.2
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.