Skip to content

Hypergraph is more powerful. Transform unstructured text into structured knowledge with LLMs. Graphs, hypergraphs, and spatio-temporal extractions — with one command.

feat: Add generic spatial, spatio-temporal, and temporal graph implementations

yifanfeng9711cbdbfe7816
diff --git a/README.md b/README.md
index 3f0f554..714be00 100644
--- a/README.md
+++ b/README.md
@@ -41,7 +41,7 @@ Hyper-Extract makes complex extraction and interaction dead simple:
```python
from pydantic import BaseModel, Field
-from hyperextract.graphs import AutoGraph
+from hyperextract.types import AutoGraph
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
# 1. Define your world view (Schema)
@@ -96,9 +96,8 @@ The `hyperextract/templates` directory provides a wealth of domain-specific defi
## 🏗️ Core Components
-- **`hyperextract.core`**: Core abstraction layer handling long-text chunking, parallel processing, and knowledge aggregation.
-- **`hyperextract.graphs`**: Various graph components including spatial, temporal, and standard graphs.
-- **`hyperextract.hypergraphs`**: Powerful Hypergraph-based RAG implementations for complex multi-entity logic.
+- **`hyperextract.types`**: Core AutoTypes data structures (AutoModel, AutoGraph, AutoHypergraph, etc.).
+- **`hyperextract.methods`**: Extraction algorithms and RAG strategies (Hyper-RAG, Cog-RAG, iText2KG, etc.).
- **`hyperextract.utils`**: Essential utilities for logging and merging strategies.
---
diff --git a/README_ZH.md b/README_ZH.md
index 77a4432..12a29b3 100644
--- a/README_ZH.md
+++ b/README_ZH.md
@@ -41,7 +41,7 @@ Hyper-Extract 让复杂结构的提取和使用变得异常简单:
```python
from pydantic import BaseModel, Field
-from hyperextract.graphs import AutoGraph
+from hyperextract.types import AutoGraph
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
# 1. 定义你想要提取的结构 (Schema)
@@ -96,9 +96,8 @@ print(answer.content)
## 🏗️ 核心组件
-- **`hyperextract.core`**: 核心抽象层,管理长文本切片、并行处理与知识聚合。
-- **`hyperextract.graphs`**: 各类图谱组件(包括时空、地理、标准图谱)。
-- **`hyperextract.hypergraphs`**: 强大的超图 RAG 实现,处理超出一对一关系的复杂逻辑。
+- **`hyperextract.types`**: 核心 AutoTypes 数据类型(如 AutoModel, AutoGraph, AutoHypergraph 等)。
+- **`hyperextract.methods`**: 知识提取算法与 RAG 策略(如 Hyper-RAG, Cog-RAG, iText2KG 等)。
- **`hyperextract.utils`**: 日志、合并策略等实用工具。
---
diff --git a/examples/atom_demo.py b/examples/atom_demo.py
index eccc485..0aad04b 100644
--- a/examples/atom_demo.py
+++ b/examples/atom_demo.py
@@ -20,7 +20,7 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
-from hyperextract.graphs import Atom
+from hyperextract.types import Atom
load_dotenv()
diff --git a/examples/auto_graph_demo.py b/examples/auto_graph_demo.py
index c8d0127..45da129 100644
--- a/examples/auto_graph_demo.py
+++ b/examples/auto_graph_demo.py
@@ -21,7 +21,7 @@ sys.path.append(str(project_root))
from pydantic import BaseModel, Field
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
-from hyperextract.graphs import AutoGraph
+from hyperextract.types import AutoGraph
from ontomem import MergeStrategy
import dotenv
diff --git a/examples/auto_hypergraph_demo.py b/examples/auto_hypergraph_demo.py
index c458380..42a444d 100644
--- a/examples/auto_hypergraph_demo.py
+++ b/examples/auto_hypergraph_demo.py
@@ -17,7 +17,7 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from dotenv import load_dotenv
from pydantic import BaseModel, Field
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
-from hyperextract.hypergraphs import AutoHypergraph
+from hyperextract.types import AutoHypergraph
load_dotenv()
diff --git a/examples/auto_spatial_graph_demo.py b/examples/auto_spatial_graph_demo.py
index cfa3650..74585e8 100644
--- a/examples/auto_spatial_graph_demo.py
+++ b/examples/auto_spatial_graph_demo.py
@@ -23,7 +23,7 @@ from pydantic import BaseModel, Field
from typing import Optional
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
-from hyperextract.graphs import AutoSpatialGraph
+from hyperextract.types import AutoSpatialGraph
from ontomem import MergeStrategy
load_dotenv()
diff --git a/examples/auto_spatio_temporal_graph_demo.py b/examples/auto_spatio_temporal_graph_demo.py
index e9c83c3..fcddfa7 100644
--- a/examples/auto_spatio_temporal_graph_demo.py
+++ b/examples/auto_spatio_temporal_graph_demo.py
@@ -25,7 +25,7 @@ sys.path.append(str(project_root))
from pydantic import BaseModel, Field
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
-from hyperextract.graphs import AutoSpatioTemporalGraph
+from hyperextract.types import AutoSpatioTemporalGraph
from ontomem import MergeStrategy
import dotenv
diff --git a/examples/auto_temporal_graph_demo.py b/examples/auto_temporal_graph_demo.py
index 5d56917..b73ba54 100644
--- a/examples/auto_temporal_graph_demo.py
+++ b/examples/auto_temporal_graph_demo.py
@@ -23,7 +23,7 @@ sys.path.append(str(project_root))
from pydantic import BaseModel, Field
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
-from hyperextract.graphs import AutoTemporalGraph
+from hyperextract.types import AutoTemporalGraph
from ontomem import MergeStrategy
import dotenv
diff --git a/examples/cog_rag_demo.py b/examples/cog_rag_demo.py
index 5c0ef0f..ce0abdb 100644
--- a/examples/cog_rag_demo.py
+++ b/examples/cog_rag_demo.py
@@ -22,7 +22,7 @@ from dotenv import load_dotenv
load_dotenv()
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
-from hyperextract.hypergraphs.cog_rag import Cog_RAG
+from hyperextract.types.cog_rag import Cog_RAG
# ============================================================================
# Sample Story for Extraction
diff --git a/examples/hyper_rag_demo.py b/examples/hyper_rag_demo.py
index 3ac1ea6..5b3dd5f 100644
--- a/examples/hyper_rag_demo.py
+++ b/examples/hyper_rag_demo.py
@@ -16,7 +16,7 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
-from hyperextract.hypergraphs import Hyper_RAG
+from hyperextract.types import Hyper_RAG
load_dotenv()
diff --git a/examples/hypergraph_rag_demo.py b/examples/hypergraph_rag_demo.py
index 952cb8e..15c5c81 100644
--- a/examples/hypergraph_rag_demo.py
+++ b/examples/hypergraph_rag_demo.py
@@ -13,7 +13,7 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
-from hyperextract.hypergraphs import HyperGraph_RAG
+from hyperextract.types import HyperGraph_RAG
load_dotenv()
diff --git a/examples/itext2kg_demo.py b/examples/itext2kg_demo.py
index d46197b..206ecb1 100644
--- a/examples/itext2kg_demo.py
+++ b/examples/itext2kg_demo.py
@@ -14,7 +14,7 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
-from hyperextract.graphs import iText2KG
+from hyperextract.types import iText2KG
load_dotenv()
diff --git a/examples/itext2kg_star_demo.py b/examples/itext2kg_star_demo.py
index 289feae..0e4e5f3 100644
--- a/examples/itext2kg_star_demo.py
+++ b/examples/itext2kg_star_demo.py
@@ -16,7 +16,7 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
-from hyperextract.graphs.itext2kg_star import iText2KG_Star
+from hyperextract.types.itext2kg_star import iText2KG_Star
load_dotenv()
diff --git a/examples/kg_gen_demo.py b/examples/kg_gen_demo.py
index 5c4a3ff..79c4702 100644
--- a/examples/kg_gen_demo.py
+++ b/examples/kg_gen_demo.py
@@ -14,7 +14,7 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
-from hyperextract.graphs import KG_Gen
+from hyperextract.types import KG_Gen
load_dotenv()
diff --git a/examples/light_rag_demo.py b/examples/light_rag_demo.py
new file mode 100644
index 0000000..f8c0e1e
--- /dev/null
+++ b/examples/light_rag_demo.py
@@ -0,0 +1,258 @@
+"""
+Light-RAG Demo: Entity-Relationship Extraction with Standard Binary Graphs
+
+This demo demonstrates:
+1. Extracting entities and binary relationships from a complex sci-fi story.
+2. Analysis of standard graph relationships (Source -> Target).
+3. Semantic Search over the constructed Knowledge Graph (Q&A).
+"""
+
+import os
+import sys
+
+# 添加项目根目录到路径
+sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+
+from dotenv import load_dotenv
+load_dotenv()
+
+from langchain_openai import ChatOpenAI, OpenAIEmbeddings
+from hyperextract.methods.rag import Light_RAG
+
+# ============================================================================
+# Sample Story for Extraction (Shared with AutoHypergraph Demo)
+# ============================================================================
+
+STORY = """
+【银河纪元 3042年 - 赤红星云事件报告】
+
+危机在这一周达到了顶峰。整个银河系似乎都陷入了暗流涌动的政治漩涡。
+
+【第一阶段:秘密接触】
+臭名昭著的星际海盗黑蛇驾驶着他的旗舰复仇号,在泰坦空间站秘密会见了银河联邦的背叛者议员 Valerius。
+目击者称,两人在午夜时分登上了空间站的顶层禁区。据情报部门推测,这是一次肮脏的交易——
+双方达成了针对皇室的同盟关系。参与此会议的还有 Valerius 手下的特务头目 Shadow,
+他负责处理所有不可告人的细节。这个同盟的形成标志着大麻烦即将到来。
+
+【第二阶段:叛变与夺权】
+在这次会议的两天后,事态急剧恶化。黑蛇这种疯狂的家伙竟然在极光星区伏击了皇家护卫队。
+这场突然的冲突中,皇家护卫队的队长 Leona 与副队长 Marcus 奋力抵抗,
+但他们陷入了黑蛇手下的精锐战士的包围。这场激战导致队长 Leona 身受重伤。
+而黑蛇的目标不是为了杀戮,而是为了夺取一件神圣的物品——传说中的虚空水晶。
+这枚水晶散发着幽蓝的光芒,据说能够打开先祖之门的第一道密封。
+黑蛇在战斗中成功夺取了水晶,但 Leona 在临终前用最后的力量将其重新夺回。
+
+【第三阶段:流亡与隐藏】
+Leona 被迫带着虚空水晶,从极光星区逃往荒凉的废土行星 Z-9。
+在这个被遗忘的角落,她向仅有的几个信任者求救:还有副队长 Marcus 以及隐秘组织"地下抵抗军"的领导人 Cipher。
+同时,议员 Valerius 非法持有了开启先祖之门的钥匙——这把钥匙本应被安全保管在皇家金库中。
+他现在藏匿在浮空都市中,与黑蛇遥相呼应,计划着下一步的政变。
+
+【第四阶段:势力重组】
+银河联邦的最高委员会得知了这一系列事件,决定采取行动。
+高级顾问 Artemis 被任命为特使,她与 Leona 在废土行星 Z-9 进行了秘密会晤,
+讨论如何制止这场即将到来的危机。同时,地下抵抗军的 Cipher 也加入了这次会议,
+三人共同制定了一个大胆的计划。
+
+【第五阶段:最后的筹码】
+虽然黑蛇未能获得虚空水晶,但他已经从 Valerius 那里获得了先祖之门钥匙的复制品。
+根据情报,这个复制品目前被秘密运往到黑蛇的秘密基地——位于辐射荒漠中的要塞。
+参与此次运送的还有 Shadow 和黑蛇手下的精锐战士群体。
+与此同时,Leona 和 Marcus 正在准备一场反击,他们计划在虚空水晶的力量下重新夺回局势的控制权。
+
+目前局势:
+- 黑蛇:手持复制品钥匙,掌控旗舰复仇号,计划进行最终的攻击
+- 议员 Valerius:躲在浮空都市中,与黑蛇保持联系
+- Leona:守护虚空水晶,在废土行星 Z-9 养伤,准备反击
+- 银河联邦:通过特使 Artemis 支持 Leona,正在调集力量
+- 地下抵抗军:Cipher 领导,与 Leona 和 Marcus 联手,准备对抗黑蛇和 Valerius 的同盟
+
+这场战争的走向仍不确定。虚空水晶、先祖之门、以及隐藏在这一切背后的秘密,
+都将在接下来的日子里浮出水面。银河的命运,可能就在这些关键人物和物品的碰撞中决定。
+"""
+
+
+if __name__ == "__main__":
+ # ============================================================================
+ # Initialize the Light-RAG system with LLM and Embeddings
+ # ============================================================================
+ print("=" * 80)
+ print("Initializing Light-RAG System...")
+ print("=" * 80)
+
+ # Use a capable model for extraction
+ llm_client = ChatOpenAI(
+ model="gpt-4o-mini",
+ extra_body={
+ "system": "You are a helpful assistant. Always respond in Chinese."
+ },
+ temperature=0,
+ )
+ embedder = OpenAIEmbeddings(model="text-embedding-3-small")
+
+ rag = Light_RAG(
+ llm_client=llm_client,
+ embedder=embedder,
+ verbose=True,
+ chunk_size=1000,
+ )
+
+ # ============================================================================
+ # Feed text to the system
+ # ============================================================================
+ print("\nFeeding story to the system...")
+ rag.feed_text(STORY)
+ print("✓ Story processed successfully\n")
+
+ # ============================================================================
+ # Display Extracted Entities
+ # ============================================================================
+ print("=" * 80)
+ print("EXTRACTED ENTITIES")
+ print("=" * 80)
+
+ for node in rag.nodes:
+ print(f"\n【{node.name}】(Type: {node.type})")
+ print(f" Description: {node.description}")
+
+ print(f"\n✓ Total entities extracted: {len(rag.nodes)}\n")
+
+ # ============================================================================
+ # Display Extracted Edges
+ # ============================================================================
+ print("=" * 80)
+ print("EXTRACTED EDGES (Binary Relationships)")
+ print("=" * 80)
+
+ for i, edge in enumerate(rag.edges, 1):
+ print(f"\n{i}. {edge.source} -> {edge.target}")
+ print(f" Description: {edge.description}")
+ print(f" Keywords: {edge.keywords}")
+ print(f" Strength: {edge.strength}/10")
+
+ print(f"\n✓ Total edges extracted: {len(rag.edges)}\n")
+
+ # ============================================================================
+ # Statistics
+ # ============================================================================
+ print("=" * 80)
+ print("STATISTICS")
+ print("=" * 80)
+
+ # Entity type distribution
+ type_counts = {}
+ for node in rag.nodes:
+ type_counts[node.type] = type_counts.get(node.type, 0) + 1
+
+ print("\nEntity Type Distribution:")
+ for entity_type, count in sorted(type_counts.items()):
+ print(f" {entity_type}: {count}")
+
+ # Average edge strength
+ if rag.edges:
+ avg_strength = sum(e.strength for e in rag.edges) / len(rag.edges)
+ print(f"\nAverage Edge Strength: {avg_strength:.2f}/10")
+
+ # Centrality (Out-degree + In-degree)
+ print("\nEntity Centrality (Degree):")
+ centrality = {}
+ for edge in rag.edges:
+ centrality[edge.source] = centrality.get(edge.source, 0) + 1
+ centrality[edge.target] = centrality.get(edge.target, 0) + 1
+
+ for entity, count in sorted(centrality.items(), key=lambda x: x[1], reverse=True)[
+ :10
+ ]:
+ print(f" {entity}: {count}")
+
+ # ============================================================================
+ # Build Semantic Index for Q&A
+ # ============================================================================
+ print("\n" + "=" * 80)
+ print("Building Semantic Index...")
+ print("=" * 80)
+
+ rag.build_index()
+ print("✓ Semantic index built successfully\n")
+
+ # ============================================================================
+ # Q&A: Semantic Search over Graph
+ # ============================================================================
+ print("=" * 80)
+ print("Q&A: SEMANTIC SEARCH")
+ print("=" * 80)
+
+ queries = [
+ "虚空水晶现在在哪里?",
+ "黑蛇和议员Valerius有什么阴谋?",
+ "谁参与了泰坦空间站的秘密会议?",
+ "Leona目前的状况如何?",
+ ]
+
+ for i, query in enumerate(queries, 1):
+ print(f"\n【问题 {i}】{query}")
+ print("-" * 60)
+
+ try:
+ results = rag.search_edges(query, top_k=3)
+
+ if results:
+ for j, result in enumerate(results, 1):
+ # LightRAG search_edges returns (Edge, score) tuples or just Edges depending on impl
+ edge = result[0] if isinstance(result, tuple) else result
+ score = result[1] if isinstance(result, tuple) else 1.0
+
+ print(f"\n {j}. [Score: {score:.3f}]")
+ # Note: LightRAG EdgeSchema uses source/target, not participants list
+ print(f" Relation: {edge.source} -> {edge.target}")
+ print(f" Description: {edge.description}")
+ print(f" Strength: {edge.strength}/10")
+ else:
+ print(" (No relevant relationships found)")
+ except Exception as e:
+ print(f" Search error: {str(e)}")
+
+ # ============================================================================
+ # Chat with LightRAG
+ # ============================================================================
+ print("\n" + "=" * 80)
+ print("💬 Interactive Chat with LightRAG")
+ print("=" * 80)
+ print("Engaging in multi-turn dialogue based on extracted knowledge...\n")
+
+ for q in queries:
+ print(f"❓ User: {q}")
+ try:
+ response = rag.chat(q)
+ print(f"🤖 LightRAG: {response.content}\n")
+ except Exception as e:
+ print(f"⚠️ Chat error: {e}\n")
+
+ # ============================================================================
+ # Save Results
+ # ============================================================================
+ print("\n" + "=" * 80)
+ print("Saving Results...")
+ print("=" * 80)
+
+ try:
+ output_dir = "temp/light_rag_demo"
+ rag.dump(output_dir)
+ print(f"✓ Results saved to {output_dir}/")
+
+ # List saved files
+ saved_files = []
+ if os.path.exists(output_dir):
+ for root, dirs, files in os.walk(output_dir):
+ for file in files:
+ rel_path = os.path.relpath(os.path.join(root, file), output_dir)
+ saved_files.append(rel_path)
+
+ if saved_files:
+ print("\n Saved files:")
+ for f in saved_files:
+ print(f" - {f}")
+ except Exception as e:
+ print(f"⚠ Warning: Could not save results: {str(e)}")
+
+ print("\n" + "=" * 80 + "\n")
diff --git a/hyperextract/__init__.py b/hyperextract/__init__.py
index 3405a6c..550c14e 100644
--- a/hyperextract/__init__.py
+++ b/hyperextract/__init__.py
@@ -2,16 +2,41 @@
This library provides Auto-prefixed intelligent data structures that automatically
extract structured information from text using Large Language Models (LLMs).
+
+Architecture:
+- types: Core data structure primitives (AutoModel, AutoList, AutoSet, AutoGraph, etc.)
+- methods: Algorithms and strategies (rag, typical graph construction methods)
+- templates: Domain-specific extraction templates
"""
-from .core import AutoModel, AutoList, AutoSet
+# Core AutoType primitives
+from .types import (
+ BaseAutoType,
+ AutoModel,
+ AutoList,
+ AutoSet,
+ AutoGraph,
+ AutoHypergraph,
+ AutoTemporalGraph,
+ AutoSpatialGraph,
+ AutoSpatioTemporalGraph,
+)
-__version__ = "0.2.0"
+__version__ = "0.1.0"
__author__ = "Yifan Feng"
__email__ = "[email protected]"
__all__ = [
+ # Base class
+ "BaseAutoType",
+ # Scalar types
"AutoModel",
"AutoList",
"AutoSet",
+ # Graph types
+ "AutoGraph",
+ "AutoHypergraph",
+ "AutoTemporalGraph",
+ "AutoSpatialGraph",
+ "AutoSpatioTemporalGraph",
]
diff --git a/hyperextract/core/__init__.py b/hyperextract/core/__init__.py
deleted file mode 100644
index 3c763a7..0000000
--- a/hyperextract/core/__init__.py
+++ /dev/null
@@ -1,13 +0,0 @@
-"""Core knowledge patterns - fundamental data structure patterns."""
-
-from .base import BaseAutoType
-from .model import AutoModel
-from .list import AutoList
-from .set import AutoSet
-
-__all__ = [
- "BaseAutoType",
- "AutoModel",
- "AutoList",
- "AutoSet",
-]
diff --git a/hyperextract/graphs/__init__.py b/hyperextract/graphs/__init__.py
deleted file mode 100644
index 9ea5cdc..0000000
--- a/hyperextract/graphs/__init__.py
+++ /dev/null
@@ -1,20 +0,0 @@
-from .base import AutoGraph
-from .kg_gen import KG_Gen
-from .itext2kg import iText2KG
-from .itext2kg_star import iText2KG_Star
-from .atom import Atom
-from .temporal_graph import AutoTemporalGraph
-from .spatial_graph import AutoSpatialGraph
-from .spatio_temporal_graph import AutoSpatioTemporalGraph
-
-
-__all__ = [
- "AutoGraph",
- "KG_Gen",
- "iText2KG",
- "iText2KG_Star",
- "Atom",
- "AutoTemporalGraph",
- "AutoSpatialGraph",
- "AutoSpatioTemporalGraph",
-]
diff --git a/hyperextract/graphs/graphiti.py b/hyperextract/graphs/graphiti.py
deleted file mode 100644
index e69de29..0000000
diff --git a/hyperextract/graphs/light_rag.py b/hyperextract/graphs/light_rag.py
deleted file mode 100644
index e69de29..0000000
diff --git a/hyperextract/hypergraphs/__init__.py b/hyperextract/hypergraphs/__init__.py
deleted file mode 100644
index 1c0ff6d..0000000
--- a/hyperextract/hypergraphs/__init__.py
+++ /dev/null
@@ -1,11 +0,0 @@
-from .base import AutoHypergraph
-from .hyper_rag import Hyper_RAG
-from .hypergraph_rag import HyperGraph_RAG
-from .cog_rag import Cog_RAG
-
-__all__ = [
- "AutoHypergraph",
- "Hyper_RAG",
- "HyperGraph_RAG",
- "Cog_RAG",
-]
diff --git a/hyperextract/methods/__init__.py b/hyperextract/methods/__init__.py
new file mode 100644
index 0000000..50689b3
--- /dev/null
+++ b/hyperextract/methods/__init__.py
@@ -0,0 +1,13 @@
+"""Methods Layer - Algorithms and strategies for knowledge extraction.
+
+This module organizes concrete algorithms and strategies that operate on
+the AutoTypes primitives. It's divided into:
+- rag: Retrieval-augmented generation strategies
+- typical: Typical/canonical graph construction pipelines
+"""
+
+from . import rag
+from . import typical
+
+__all__ = ["rag", "typical"]
+
diff --git a/hyperextract/methods/rag/__init__.py b/hyperextract/methods/rag/__init__.py
new file mode 100644
index 0000000..5268c87
--- /dev/null
+++ b/hyperextract/methods/rag/__init__.py
@@ -0,0 +1,20 @@
+"""RAG (Retrieval-Augmented Generation) Strategies.
+
+This module contains various RAG implementations that leverage graph structures
+(both binary and hypergraphs) for context retrieval and augmented generation.
+"""
+
+from .hyper_rag import Hyper_RAG
+from .hypergraph_rag import HyperGraph_RAG
+from .cog_rag import Cog_RAG, Cog_RAG_ThemeLayer, Cog_RAG_DetailLayer
+from .light_rag import Light_RAG
+
+__all__ = [
+ "Hyper_RAG",
+ "HyperGraph_RAG",
+ "Cog_RAG",
+ "Cog_RAG_ThemeLayer",
+ "Cog_RAG_DetailLayer",
+ "Light_RAG",
+]
+
diff --git a/hyperextract/hypergraphs/cog_rag.py b/hyperextract/methods/rag/cog_rag.py
similarity index 99%
rename from hyperextract/hypergraphs/cog_rag.py
rename to hyperextract/methods/rag/cog_rag.py
index 2084469..360740f 100644
--- a/hyperextract/hypergraphs/cog_rag.py
+++ b/hyperextract/methods/rag/cog_rag.py
@@ -6,7 +6,7 @@ Extracts and manages Theme-Entity relationships where Themes act as Hyperedges c
from typing import List
from hashlib import md5
from pydantic import BaseModel, Field
-from hyperextract.hypergraphs.base import AutoHypergraph, AutoHypergraphSchema
+from hyperextract.types import AutoHypergraph, AutoHypergraphSchema
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.embeddings import Embeddings
from langchain_core.language_models import BaseChatModel
@@ -482,3 +482,4 @@ class Cog_RAG:
def edges(self):
"""Return all edges (Themes + Relations)."""
return self.theme_layer.edges + self.detail_layer.edges
+
diff --git a/hyperextract/hypergraphs/hyper_rag.py b/hyperextract/methods/rag/hyper_rag.py
similarity index 99%
rename from hyperextract/hypergraphs/hyper_rag.py
rename to hyperextract/methods/rag/hyper_rag.py
index b433af7..8075d58 100644
--- a/hyperextract/hypergraphs/hyper_rag.py
+++ b/hyperextract/methods/rag/hyper_rag.py
@@ -5,7 +5,7 @@ Extracts and manages multi-entity relationships with support for n-ary hyperedge
from typing import List
from pydantic import BaseModel, Field
-from hyperextract.hypergraphs.base import AutoHypergraph
+from hyperextract.types import AutoHypergraph
from langchain_core.embeddings import Embeddings
from langchain_core.language_models import BaseChatModel
from ontomem.merger import CustomRuleMerger
@@ -196,3 +196,4 @@ class Hyper_RAG(AutoHypergraph[NodeSchema, EdgeSchema]):
max_workers=max_workers,
verbose=verbose,
)
+
diff --git a/hyperextract/hypergraphs/hypergraph_rag.py b/hyperextract/methods/rag/hypergraph_rag.py
similarity index 99%
rename from hyperextract/hypergraphs/hypergraph_rag.py
rename to hyperextract/methods/rag/hypergraph_rag.py
index 1bd2605..70e9318 100644
--- a/hyperextract/hypergraphs/hypergraph_rag.py
+++ b/hyperextract/methods/rag/hypergraph_rag.py
@@ -18,7 +18,7 @@ from langchain_core.language_models import BaseChatModel
from langchain_core.prompts.chat import ChatPromptTemplate
from ontomem.merger import MergeStrategy
-from hyperextract.hypergraphs.base import AutoHypergraph, AutoHypergraphSchema
+from hyperextract.types import AutoHypergraph, AutoHypergraphSchema
# ============================================================================
# Node Schema
@@ -315,3 +315,4 @@ class HyperGraph_RAG(AutoHypergraph[NodeSchema, EdgeSchema]):
raw_hypergraph = self.merge_batch_data(partial_hypergraphs)
return self._prune_dangling_edges(raw_hypergraph)
+
diff --git a/hyperextract/methods/rag/light_rag.py b/hyperextract/methods/rag/light_rag.py
new file mode 100644
index 0000000..b128e76
--- /dev/null
+++ b/hyperextract/methods/rag/light_rag.py
@@ -0,0 +1,199 @@
+"""
+Light-RAG: Lightweight Graph-based Retrieval-Augmented Generation
+Extracts and manages entity-relationship knowledge graphs with standard binary edges.
+"""
+
+from pydantic import BaseModel, Field
+from hyperextract.types import AutoGraph
+from langchain_core.embeddings import Embeddings
+from langchain_core.language_models import BaseChatModel
+from ontomem.merger import CustomRuleMerger
+
+# ============================================================================
+# Node Schema
+# ============================================================================
+
+
+class NodeSchema(BaseModel):
+ """Represents an entity extracted from the source text."""
+
+ name: str = Field(description="Name of the entity")
+ type: str = Field(
+ description="Entity type (person, organization, geo, event, role, concept, etc.)",
+ )
+ description: str = Field(
+ description="Comprehensive description of the entity's attributes and activities",
+ )
+
+
+# ============================================================================
+# Edge Schema
+# ============================================================================
+
+
+class EdgeSchema(BaseModel):
+ """Represents a directed relationship between two entities."""
+
+ source: str = Field(description="Name of the source entity")
+ target: str = Field(description="Name of the target entity")
+ description: str = Field(
+ description="Detailed explanation of the relationship or event connection"
+ )
+ keywords: str = Field(
+ description="Keywords summarizing the relationship (e.g., 'conflict, trade')",
+ )
+ strength: int = Field(
+ ge=1,
+ le=10,
+ description="Numerical score indicating relationship strength (1-10)",
+ )
+
+
+# ============================================================================
+# Extraction Prompts
+# ============================================================================
+
+Light_RAG_NODE_EXTRACTION_PROMPT = """
+-Goal-
+Identify relevant entities from the text.
+Entities will serve as nodes in the knowledge graph.\n\n
+### Source Text:
+"""
+
+Light_RAG_EDGE_EXTRACTION_PROMPT = """
+-Goal-
+You are an expert knowledge graph extraction assistant.
+Extract binary "Edges" that represent relationships between exactly TWO entities.
+
+-Definition-
+An Edge represents a specific connection (action, relation, ownership, etc.) from a Source entity to a Target entity.
+
+-Constraints-
+1. You MUST ONLY use names from the "Allowed Entities" list provided below.
+2. Ensure every edge has exactly one Source and one Target.
+3. Provide a clear, comprehensive description for each edge.
+
+"""
+
+# ============================================================================
+# Merge Templates for LLM.CUSTOM_RULE Strategy
+# ============================================================================
+
+Light_RAG_NODE_MERGE_RULE = """You are an intelligent data merging assistant.
+You will receive a list of objects representing the same Entity.
+
+Your task is to merge them into a SINGLE object exactly matching the schema.
+
+Merge strategy:
+1. **name/type**: Keep the most frequent or precise value.
+2. **description**: Synthesize a single, comprehensive description containing all unique details from the input descriptions. Write it in the third person. Resolve any contradictions coherently.
+"""
+
+Light_RAG_EDGE_MERGE_RULE = """You are an intelligent data merging assistant.
+You will receive a list of objects representing the same Relationship (Edge).
+
+Your task is to merge them into a SINGLE object exactly matching the schema.
+
+Merge strategy:
+1. **source/target**: Keep them identical to the inputs.
+2. **description**: Synthesize a single, comprehensive description covering the relationship dynamics from all inputs. Write it in the third person.
+3. **keywords**: Merge keywords from all inputs into a single comma-separated string, removing duplicates.
+4. **strength**: Calculate the average of the input strengths (round to nearest integer).
+"""
+
+# ============================================================================
+# Light_RAG Class
+# ============================================================================
+
+
+class Light_RAG(AutoGraph[NodeSchema, EdgeSchema]):
+ """
+ Light-RAG: Standard Graph-based Retrieval-Augmented Generation
+
+ Extracts entity-relationship graphs (nodes and binary edges) from text documents.
+ Optimized for standard Knowledge Graph construction and traversal.
+
+ Features:
+ - Two-stage extraction: Entities first, then binary relationships.
+ - Custom Key Extractors: Precise deduplication using name-based node keys and (Source, Target) keys for edges.
+ - Structured Knowledge Representation: Pydantic-based schemas.
+ - Specialized Merging: Custom LLM rules for merging duplicate entities and relationships.
+ """
+
+ def __init__(
+ self,
+ llm_client: BaseChatModel,
+ embedder: Embeddings,
+ chunk_size: int = 2048,
+ chunk_overlap: int = 256,
+ max_workers: int = 10,
+ verbose: bool = True,
+ ):
+ """
+ Initialize Light_RAG engine.
+
+ Args:
+ llm_client (BaseChatModel): LLM client for text generation.
+ embedder (Embeddings): Embedding model for text embeddings.
+ chunk_size (int): Size of text chunks for indexing.
+ chunk_overlap (int): Overlap between text chunks for indexing.
+ max_workers (int): Maximum number of workers for indexing.
+ verbose (bool): Display detailed execution logs and progress information.
+ """
+ # 1. Define Key Extractors
+ # Node key: exact match by name
+ node_key_fn = lambda x: x.name
+
+ # Edge key: (source, target) tuple
+ # Note: LightRAG typically treats relations as directed.
+ # For undirected behavior, one might sort specific relation types, but here we enforce Source->Target directionality uniqueness.
+ edge_key_fn = lambda x: f"{x.source}->{x.target}"
+
+ # 2. Edge consistency check: tell AutoGraph which nodes this edge connects
+ # Returns (source, target) tuple
+ nodes_in_edge_fn = lambda x: (x.source, x.target)
+
+ # 3. Create custom Mergers
+ # Node merger
+ node_merger = CustomRuleMerger(
+ key_extractor=node_key_fn,
+ llm_client=llm_client,
+ item_schema=NodeSchema,
+ rule=Light_RAG_NODE_MERGE_RULE,
+ )
+
+ # Edge merger
+ edge_merger = CustomRuleMerger(
+ key_extractor=edge_key_fn,
+ llm_client=llm_client,
+ item_schema=EdgeSchema,
+ rule=Light_RAG_EDGE_MERGE_RULE,
+ )
+
+ # 4. Call parent class initialization
+ super().__init__(
+ node_schema=NodeSchema,
+ edge_schema=EdgeSchema,
+ node_key_extractor=node_key_fn,
+ edge_key_extractor=edge_key_fn,
+ nodes_in_edge_extractor=nodes_in_edge_fn,
+ llm_client=llm_client,
+ embedder=embedder,
+ # Enforce two-stage extraction (nodes first, then edges)
+ extraction_mode="two_stage",
+ # Inject customized prompts for extraction
+ prompt_for_node_extraction=Light_RAG_NODE_EXTRACTION_PROMPT,
+ prompt_for_edge_extraction=Light_RAG_EDGE_EXTRACTION_PROMPT,
+ # Pass custom merger instances
+ node_strategy_or_merger=node_merger,
+ edge_strategy_or_merger=edge_merger,
+ # Optimize indexing
+ node_fields_for_index=["name", "type", "description"],
+ edge_fields_for_index=["keywords", "description"],
+ # Other parameters
+ chunk_size=chunk_size,
+ chunk_overlap=chunk_overlap,
+ max_workers=max_workers,
+ verbose=verbose,
+ )
+
diff --git a/hyperextract/methods/typical/__init__.py b/hyperextract/methods/typical/__init__.py
new file mode 100644
index 0000000..cc288f7
--- /dev/null
+++ b/hyperextract/methods/typical/__init__.py
@@ -0,0 +1,18 @@
+"""Typical/Canonical Pipelines.
+
+This module contains typical and canonical methods for constructing knowledge graphs
+from text, including Graphiti, iText2KG, and other established graph-building techniques.
+"""
+
+from .itext2kg import iText2KG
+from .itext2kg_star import iText2KG_Star
+from .kg_gen import KG_Gen
+from .atom import Atom
+
+__all__ = [
+ "iText2KG",
+ "iText2KG_Star",
+ "KG_Gen",
+ "Atom",
+]
+
diff --git a/hyperextract/graphs/atom.py b/hyperextract/methods/typical/atom.py
similarity index 92%
rename from hyperextract/graphs/atom.py
rename to hyperextract/methods/typical/atom.py
index d4d0144..2618f97 100644
--- a/hyperextract/graphs/atom.py
+++ b/hyperextract/methods/typical/atom.py
@@ -17,7 +17,7 @@ from langchain_core.embeddings import Embeddings
from ontomem.merger import MergeStrategy, CustomRuleMerger
from hyperextract.utils.logging import logger
-from hyperextract.graphs.base import AutoGraph, AutoGraphSchema
+from hyperextract.types import AutoGraph, AutoGraphSchema
# ==============================================================================
# 1. Schema Definition - Consistent with original Atom implementation
@@ -85,14 +85,14 @@ class EdgeSchema(BaseModel):
description=(
"A time or interval indicating when this relationship begins or is active. "
"Resolve relative temporal expressions based on the observation_time:\n"
- " - 'today' → exact observation_time\n"
- " - 'yesterday' → observation_time minus 1 day\n"
- " - 'this week' → Monday of observation_time's week\n"
- " - 'last week' → Monday of the week before observation_time\n"
- " - 'this month' → first day of observation_time's month\n"
- " - 'last month' → first day of the month before observation_time\n"
- " - 'this year' → January 1st of observation_time's year\n"
- " - 'last year' → January 1st of the year before observation_time\n"
+ " - 'today' 鈫?exact observation_time\n"
+ " - 'yesterday' 鈫?observation_time minus 1 day\n"
+ " - 'this week' 鈫?Monday of observation_time's week\n"
+ " - 'last week' 鈫?Monday of the week before observation_time\n"
+ " - 'this month' 鈫?first day of observation_time's month\n"
+ " - 'last month' 鈫?first day of the month before observation_time\n"
+ " - 'this year' 鈫?January 1st of observation_time's year\n"
+ " - 'last year' 鈫?January 1st of the year before observation_time\n"
"Keep explicit dates as-is (e.g., '18-06-2024'). "
"For example, if 'Yassir became CEO from 2023', then t_start=['01-01-2023']. "
"This can be a single year, a date, or a resolved relative reference. "
@@ -104,9 +104,9 @@ class EdgeSchema(BaseModel):
description=(
"A time or interval indicating when this relationship ceases to hold. "
"Resolve relative temporal expressions based on the observation_time using the same rules as t_start:\n"
- " - 'today' → exact observation_time\n"
- " - 'yesterday' → observation_time minus 1 day\n"
- " - 'this week' → Monday of observation_time's week\n"
+ " - 'today' 鈫?exact observation_time\n"
+ " - 'yesterday' 鈫?observation_time minus 1 day\n"
+ " - 'this week' 鈫?Monday of observation_time's week\n"
" - etc. (same resolution rules as t_start)\n"
"Keep explicit dates as-is. "
"For example, if 'Yassir left his position in 2025', then t_end=['01-01-2025']. "
@@ -161,14 +161,14 @@ Given an input paragraph and an `observation_time`, generate a list of all disti
- Convert ALL time references to absolute dates/times using the observation_time
#### Conversion Rules:
-- "today" → exact observation_time
-- "yesterday" → observation_time minus 1 day
-- "this week" → Monday of observation_time's week
-- "last week" → Monday of the week before observation_time
-- "this month" → first day of observation_time's month
-- "last month" → first day of the month before observation_time
-- "this year" → January 1st of observation_time's year
-- "last year" → January 1st of the year before observation_time
+- "today" 鈫?exact observation_time
+- "yesterday" 鈫?observation_time minus 1 day
+- "this week" 鈫?Monday of observation_time's week
+- "last week" 鈫?Monday of the week before observation_time
+- "this month" 鈫?first day of observation_time's month
+- "last month" 鈫?first day of the month before observation_time
+- "this year" 鈫?January 1st of observation_time's year
+- "last year" 鈫?January 1st of the year before observation_time
- Keep explicit dates as-is (e.g., "June 18, 2024")
#### Additional Temporal Guidelines:
@@ -203,7 +203,7 @@ Observation Date: {observation_time}
You are a precise knowledge extraction engine designed to distill unstructured text into a structured Knowledge Graph.
Your goal is to extract all meaningful relationships (edges) between entities, while rigorously capturing their temporal bounds and grounding evidence.
-### 🎯 Objective
+### 馃幆 Objective
Extract a list of relationships where each relationship consists of:
1. **Start Node**: The subject entity (Name + Label).
2. **End Node**: The object entity (Name + Label).
@@ -212,7 +212,7 @@ Extract a list of relationships where each relationship consists of:
5. **Time End (`t_end`)**: Strategies for when the relation ended.
6. **Evidence (`atomic_facts`)**: The exact source sentences/facts supporting this edge.
-### 📝 Guidelines
+### 馃摑 Guidelines
#### 1. Entity & Relation Standards
- **Entities**: Extract precise names (e.g., "Apple Inc.", "Steve Jobs"). Assign accurate semantic labels (e.g., "Organization", "Person").
@@ -235,7 +235,7 @@ Extract a list of relationships where each relationship consists of:
- **NO Paraphrasing**: Do not summarize or rewrite the source text in this field.
- If a relationship is derived from multiple facts, include all distinct facts in the list.
-### 🧠 Few-Shot Examples
+### 馃�� Few-Shot Examples
**Input**: "Michel served as CFO at Acme Corp from 2019 to 2021. He was hired by Beta Inc in 2021, but left that role in 2023."
**Output**:
@@ -255,7 +255,7 @@ Extract a list of relationships where each relationship consists of:
**Output**:
- (John Doe, has_status, Married, t_start=["2026-02-26"], t_end=[], atomic_facts=["John Doe's marriage is happening on 26-02-2026."])
-### 🚀 Directives
+### 馃殌 Directives
- Extract strictly what is in the text. Do not hallucinate external facts.
- Use the **Observation Date** as the anchor for all relative temporal expressions.
- Maintain consistency: The same entity name should be used across multiple relations.
@@ -361,7 +361,7 @@ class Atom(AutoGraph[NodeSchema, EdgeSchema]):
)
# 3. Call parent class initialization
- logger.info("🚀 Initializing Atom")
+ logger.info("馃殌 Initializing Atom")
super().__init__(
node_schema=NodeSchema,
edge_schema=EdgeSchema,
@@ -408,7 +408,7 @@ class Atom(AutoGraph[NodeSchema, EdgeSchema]):
obs_date_str = self.observation_time or datetime.now().strftime("%Y-%m-%d")
# ==================== Step 1: Extract Atomic Facts ====================
- logger.info("🔍 [Phase 1] Extracting Atomic Facts...")
+ logger.info("馃攳 [Phase 1] Extracting Atomic Facts...")
# 1. Prepare raw chunks
if len(text) <= self.chunk_size:
@@ -439,14 +439,14 @@ class Atom(AutoGraph[NodeSchema, EdgeSchema]):
if fact_list and fact_list.atomic_fact:
all_facts.extend(fact_list.atomic_fact)
- logger.info(f"✅ Extracted {len(all_facts)} atomic facts.")
+ logger.info(f"鉁?Extracted {len(all_facts)} atomic facts.")
if not all_facts:
- logger.warning("⚠️ No facts extracted. Returning empty graph.")
+ logger.warning("鈿狅笍 No facts extracted. Returning empty graph.")
return AutoGraphSchema()
# ==================== Step 2: Extract Edges from Facts ====================
- logger.info("🔍 [Phase 2] Extracting Edges from Atomic Facts...")
+ logger.info("馃攳 [Phase 2] Extracting Edges from Atomic Facts...")
# 5. Group Facts into Chunks (Controlled by count AND size)
# This ensures each fact remains intact and fact IDs reset per chunk
@@ -548,23 +548,23 @@ class Atom(AutoGraph[NodeSchema, EdgeSchema]):
The updated Atom instance with matched nodes and updated edges.
"""
logger.info(
- f"🔄 Starting node matching and edge update (threshold={threshold})..."
+ f"馃攧 Starting node matching and edge update (threshold={threshold})..."
)
nodes, edges = self.nodes, self.edges
if not nodes:
- logger.warning("⚠️ No nodes to match; skipping matching.")
+ logger.warning("鈿狅笍 No nodes to match; skipping matching.")
return self
# 1. Generate Embeddings using self.embedder.embed_documents
node_names = [n.name for n in nodes]
- logger.info(f"📊 Generating embeddings for {len(node_names)} nodes...")
+ logger.info(f"馃搳 Generating embeddings for {len(node_names)} nodes...")
try:
embeddings = self.embedder.embed_documents(node_names)
except Exception as e:
- logger.error(f"❌ Failed to generate embeddings: {e}")
+ logger.error(f"鉂?Failed to generate embeddings: {e}")
return self
# 2. Initialize SemHash from embeddings
@@ -585,10 +585,10 @@ class Atom(AutoGraph[NodeSchema, EdgeSchema]):
mapping[record.record] = record.duplicates[0][0]
if not mapping:
- logger.info("✅ No similar nodes found above threshold.")
+ logger.info("鉁?No similar nodes found above threshold.")
return self
- logger.info(f"🔗 Found {len(mapping)} nodes to merge.")
+ logger.info(f"馃敆 Found {len(mapping)} nodes to merge.")
# 5. Apply mapping to graph data
# Update Node names
@@ -608,6 +608,7 @@ class Atom(AutoGraph[NodeSchema, EdgeSchema]):
self._set_data_state(new_data)
logger.info(
- f"✅ Node matching complete: Nodes {len(nodes)} -> {len(self.nodes)}, Edges: {len(edges)}"
+ f"鉁?Node matching complete: Nodes {len(nodes)} -> {len(self.nodes)}, Edges: {len(edges)}"
)
return self
+
diff --git a/hyperextract/methods/typical/graphiti.py b/hyperextract/methods/typical/graphiti.py
new file mode 100644
index 0000000..74e128c
--- /dev/null
+++ b/hyperextract/methods/typical/graphiti.py
@@ -0,0 +1,2 @@
+# graphiti.py - Reserved for Graphiti implementation
+
diff --git a/hyperextract/graphs/itext2kg.py b/hyperextract/methods/typical/itext2kg.py
similarity index 99%
rename from hyperextract/graphs/itext2kg.py
rename to hyperextract/methods/typical/itext2kg.py
index a9042e8..808e500 100644
--- a/hyperextract/graphs/itext2kg.py
+++ b/hyperextract/methods/typical/itext2kg.py
@@ -12,7 +12,7 @@ from langchain_core.language_models import BaseChatModel
from langchain_core.embeddings import Embeddings
from ontomem.merger import MergeStrategy
-from hyperextract.graphs.base import AutoGraph
+from hyperextract.types import AutoGraph
from hyperextract.utils.logging import logger
# ==============================================================================
@@ -172,3 +172,4 @@ class iText2KG(AutoGraph[NodeSchema, EdgeSchema]):
max_workers=max_workers,
verbose=verbose,
)
+
diff --git a/hyperextract/graphs/itext2kg_star.py b/hyperextract/methods/typical/itext2kg_star.py
similarity index 95%
rename from hyperextract/graphs/itext2kg_star.py
rename to hyperextract/methods/typical/itext2kg_star.py
index f1b6a20..70f0921 100644
--- a/hyperextract/graphs/itext2kg_star.py
+++ b/hyperextract/methods/typical/itext2kg_star.py
@@ -16,7 +16,7 @@ from langchain_core.prompts import ChatPromptTemplate
from langchain_core.embeddings import Embeddings
from ontomem.merger import MergeStrategy
-from hyperextract.graphs.base import AutoGraph, AutoGraphSchema
+from hyperextract.types import AutoGraph, AutoGraphSchema
from hyperextract.utils.logging import logger
# ==============================================================================
@@ -165,7 +165,7 @@ class iText2KG_Star(AutoGraph[NodeSchema, EdgeSchema]):
nodes_in_edge_fn = lambda x: (x.startNode.name, x.endNode.name)
# 3. Call parent class initialization
- logger.info("🚀 Initializing iText2KG_Star")
+ logger.info("馃殌 Initializing iText2KG_Star")
super().__init__(
node_schema=NodeSchema,
edge_schema=EdgeSchema,
@@ -274,23 +274,23 @@ class iText2KG_Star(AutoGraph[NodeSchema, EdgeSchema]):
The updated iText2KG_Star instance with matched nodes and updated edges.
"""
logger.info(
- f"🔄 Starting node matching and edge update (threshold={threshold})..."
+ f"馃攧 Starting node matching and edge update (threshold={threshold})..."
)
nodes, edges = self.nodes, self.edges
if not nodes:
- logger.warning("⚠️ No nodes to match; skipping matching.")
+ logger.warning("鈿狅笍 No nodes to match; skipping matching.")
return self
# 1. Generate Embeddings using self.embedder.embed_documents
node_names = [n.name for n in nodes]
- logger.info(f"📊 Generating embeddings for {len(node_names)} nodes...")
+ logger.info(f"馃搳 Generating embeddings for {len(node_names)} nodes...")
try:
embeddings = self.embedder.embed_documents(node_names)
except Exception as e:
- logger.error(f"❌ Failed to generate embeddings: {e}")
+ logger.error(f"鉂?Failed to generate embeddings: {e}")
return self
# 2. Initialize SemHash from embeddings
@@ -311,10 +311,10 @@ class iText2KG_Star(AutoGraph[NodeSchema, EdgeSchema]):
mapping[record.record] = record.duplicates[0][0]
if not mapping:
- logger.info("✅ No similar nodes found above threshold.")
+ logger.info("鉁?No similar nodes found above threshold.")
return self
- logger.info(f"🔗 Found {len(mapping)} nodes to merge.")
+ logger.info(f"馃敆 Found {len(mapping)} nodes to merge.")
# 5. Apply mapping to graph data
# Update Node names
@@ -334,6 +334,7 @@ class iText2KG_Star(AutoGraph[NodeSchema, EdgeSchema]):
self._set_data_state(new_data)
logger.info(
- f"✅ Node matching complete: Nodes {len(nodes)} -> {len(self.nodes)}, Edges: {len(edges)}"
+ f"鉁?Node matching complete: Nodes {len(nodes)} -> {len(self.nodes)}, Edges: {len(edges)}"
)
return self
+
diff --git a/hyperextract/graphs/kg_gen.py b/hyperextract/methods/typical/kg_gen.py
similarity index 94%
rename from hyperextract/graphs/kg_gen.py
rename to hyperextract/methods/typical/kg_gen.py
index 3c44dfd..2f0016a 100644
--- a/hyperextract/graphs/kg_gen.py
+++ b/hyperextract/methods/typical/kg_gen.py
@@ -13,7 +13,7 @@ from langchain_core.language_models import BaseChatModel
from langchain_core.embeddings import Embeddings
from ontomem.merger import MergeStrategy
-from hyperextract.graphs.base import AutoGraph, AutoGraphSchema
+from hyperextract.types import AutoGraph, AutoGraphSchema
from hyperextract.utils.logging import logger
# ==============================================================================
@@ -128,7 +128,7 @@ class KG_Gen(AutoGraph[NodeSchema, EdgeSchema]):
nodes_in_edge_fn = lambda x: (x.subject, x.object)
# 3. Call parent class initialization
- logger.info("🚀 Initializing KGGenGraph (Knowledge Graph Generator)")
+ logger.info("馃殌 Initializing KGGenGraph (Knowledge Graph Generator)")
super().__init__(
node_schema=NodeSchema,
edge_schema=EdgeSchema,
@@ -173,7 +173,7 @@ class KG_Gen(AutoGraph[NodeSchema, EdgeSchema]):
nodes, edges = graph_data.nodes, graph_data.edges
if len(nodes) == 0:
- logger.warning("⚠️ No nodes to deduplicate; skipping deduplication.")
+ logger.warning("鈿狅笍 No nodes to deduplicate; skipping deduplication.")
return graph_data
# 1. Prepare data and run SemHash
@@ -182,7 +182,7 @@ class KG_Gen(AutoGraph[NodeSchema, EdgeSchema]):
try:
embeddings = self.embedder.embed_documents(node_names)
except Exception as e:
- logger.error(f"❌ Failed to generate embeddings: {e}")
+ logger.error(f"鉂?Failed to generate embeddings: {e}")
return graph_data
semhash = SemHash.from_records(
@@ -226,7 +226,7 @@ class KG_Gen(AutoGraph[NodeSchema, EdgeSchema]):
Returns:
A new, deduplicated KG_Gen instance.
"""
- logger.info(f"📋 Creating deduplicated copy (threshold={threshold})...")
+ logger.info(f"馃搵 Creating deduplicated copy (threshold={threshold})...")
# 1. Deep copy current data
graph_data = self.data.model_copy(deep=True)
@@ -241,7 +241,7 @@ class KG_Gen(AutoGraph[NodeSchema, EdgeSchema]):
new_instance._set_data_state(graph_data)
logger.info(
- f"✅ Deduplication Complete: "
+ f"鉁?Deduplication Complete: "
f"Nodes {original_node_count} -> {len(new_instance.nodes)}, "
f"Edges {original_edge_count} -> {len(new_instance.edges)}"
)
@@ -261,7 +261,7 @@ class KG_Gen(AutoGraph[NodeSchema, EdgeSchema]):
self (modified in-place)
"""
logger.info(
- f"🔄 Starting in-place SemHash deduplication (threshold={threshold})..."
+ f"馃攧 Starting in-place SemHash deduplication (threshold={threshold})..."
)
graph_data = self.data.model_copy()
@@ -276,8 +276,9 @@ class KG_Gen(AutoGraph[NodeSchema, EdgeSchema]):
self._set_data_state(graph_data)
logger.info(
- f"✅ In-place deduplication complete: "
+ f"鉁?In-place deduplication complete: "
f"Nodes {original_node_count} -> {len(self.nodes)}, "
f"Edges {original_edge_count} -> {len(self.edges)}"
)
return self
+
diff --git a/hyperextract/templates/en/agriculture/crop_cycle.py b/hyperextract/templates/en/agriculture/crop_cycle.py
index bc7f4c1..c51a51d 100644
--- a/hyperextract/templates/en/agriculture/crop_cycle.py
+++ b/hyperextract/templates/en/agriculture/crop_cycle.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any
+from typing import Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs import AutoGraph
+from hyperextract.types import AutoGraph
# ==============================================================================
# 1. Schema Definitions
diff --git a/hyperextract/templates/en/agriculture/livestock.py b/hyperextract/templates/en/agriculture/livestock.py
index fbd71fd..996f14e 100644
--- a/hyperextract/templates/en/agriculture/livestock.py
+++ b/hyperextract/templates/en/agriculture/livestock.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any
+from typing import Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs import AutoGraph
+from hyperextract.types import AutoGraph
# ==============================================================================
# 1. Schema Definitions
diff --git a/hyperextract/templates/en/agriculture/supply_chain.py b/hyperextract/templates/en/agriculture/supply_chain.py
index e9cb0a1..c615bef 100644
--- a/hyperextract/templates/en/agriculture/supply_chain.py
+++ b/hyperextract/templates/en/agriculture/supply_chain.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any
+from typing import Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs import AutoGraph
+from hyperextract.types import AutoGraph
# ==============================================================================
# 1. Schema Definitions
diff --git a/hyperextract/templates/en/art/exhibition.py b/hyperextract/templates/en/art/exhibition.py
index 588e31a..8a1f522 100644
--- a/hyperextract/templates/en/art/exhibition.py
+++ b/hyperextract/templates/en/art/exhibition.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any
+from typing import Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs import AutoGraph
+from hyperextract.types import AutoGraph
# ==============================================================================
# 1. Schema Definitions
diff --git a/hyperextract/templates/en/art/movement.py b/hyperextract/templates/en/art/movement.py
index 83cf41b..e479a90 100644
--- a/hyperextract/templates/en/art/movement.py
+++ b/hyperextract/templates/en/art/movement.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any
+from typing import Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs import AutoGraph
+from hyperextract.types import AutoGraph
# ==============================================================================
# 1. Schema Definitions
diff --git a/hyperextract/templates/en/art/provenance.py b/hyperextract/templates/en/art/provenance.py
index 212fa98..d7271fa 100644
--- a/hyperextract/templates/en/art/provenance.py
+++ b/hyperextract/templates/en/art/provenance.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any
+from typing import Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs import AutoGraph
+from hyperextract.types import AutoGraph
# ==============================================================================
# 1. Schema Definitions
diff --git a/hyperextract/templates/en/automotive/car_spec.py b/hyperextract/templates/en/automotive/car_spec.py
index 158e68d..e9fd603 100644
--- a/hyperextract/templates/en/automotive/car_spec.py
+++ b/hyperextract/templates/en/automotive/car_spec.py
@@ -2,7 +2,7 @@ from typing import Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs import AutoGraph
+from hyperextract.types import AutoGraph
# ==============================================================================
# 1. Schema Definitions
diff --git a/hyperextract/templates/en/automotive/maintenance.py b/hyperextract/templates/en/automotive/maintenance.py
index dc25ac1..4a63d24 100644
--- a/hyperextract/templates/en/automotive/maintenance.py
+++ b/hyperextract/templates/en/automotive/maintenance.py
@@ -2,7 +2,7 @@ from typing import Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs import AutoGraph
+from hyperextract.types import AutoGraph
# ==============================================================================
# 1. Schema Definitions
diff --git a/hyperextract/templates/en/automotive/manufacturing.py b/hyperextract/templates/en/automotive/manufacturing.py
index 7030b0b..6f332a7 100644
--- a/hyperextract/templates/en/automotive/manufacturing.py
+++ b/hyperextract/templates/en/automotive/manufacturing.py
@@ -2,7 +2,7 @@ from typing import Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs import AutoGraph
+from hyperextract.types import AutoGraph
# ==============================================================================
# 1. Schema Definitions
diff --git a/hyperextract/templates/en/biology/metabolic.py b/hyperextract/templates/en/biology/metabolic.py
index c79153b..9a4a75f 100644
--- a/hyperextract/templates/en/biology/metabolic.py
+++ b/hyperextract/templates/en/biology/metabolic.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any, Tuple
+from typing import List, Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.hypergraphs.base import AutoHypergraph
+from hyperextract.types import AutoHypergraph
# ==============================================================================
# 1. Schema Definitions
diff --git a/hyperextract/templates/en/biology/network.py b/hyperextract/templates/en/biology/network.py
index f09303e..a052f84 100644
--- a/hyperextract/templates/en/biology/network.py
+++ b/hyperextract/templates/en/biology/network.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any, Tuple
+from typing import Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs.base import AutoGraph
+from hyperextract.types import AutoGraph
# ==============================================================================
# 1. Schema Definitions
diff --git a/hyperextract/templates/en/biology/taxonomy.py b/hyperextract/templates/en/biology/taxonomy.py
index d8a2459..cd15fda 100644
--- a/hyperextract/templates/en/biology/taxonomy.py
+++ b/hyperextract/templates/en/biology/taxonomy.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any, Tuple
+from typing import Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs.base import AutoGraph
+from hyperextract.types import AutoGraph
# ==============================================================================
# 1. Schema Definitions
diff --git a/hyperextract/templates/en/business/ecosystem.py b/hyperextract/templates/en/business/ecosystem.py
index 09b8eb2..ae0fd99 100644
--- a/hyperextract/templates/en/business/ecosystem.py
+++ b/hyperextract/templates/en/business/ecosystem.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any, Tuple
+from typing import List, Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.hypergraphs.base import AutoHypergraph
+from hyperextract.types import AutoHypergraph
# ==============================================================================
# 1. Schema Definitions
diff --git a/hyperextract/templates/en/business/equity.py b/hyperextract/templates/en/business/equity.py
index 7b496dc..d1b24e8 100644
--- a/hyperextract/templates/en/business/equity.py
+++ b/hyperextract/templates/en/business/equity.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any, Tuple
+from typing import Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs.base import AutoGraph
+from hyperextract.types import AutoGraph
# ==============================================================================
# 1. Schema Definitions
diff --git a/hyperextract/templates/en/business/strategy.py b/hyperextract/templates/en/business/strategy.py
index 520bc80..3398327 100644
--- a/hyperextract/templates/en/business/strategy.py
+++ b/hyperextract/templates/en/business/strategy.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any, Tuple
+from typing import Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs.temporal_graph import AutoTemporalGraph
+from hyperextract.types import AutoTemporalGraph
# ==============================================================================
# 1. Schema Definitions
diff --git a/hyperextract/templates/en/chemistry/molecular.py b/hyperextract/templates/en/chemistry/molecular.py
index 27344a7..7117d3b 100644
--- a/hyperextract/templates/en/chemistry/molecular.py
+++ b/hyperextract/templates/en/chemistry/molecular.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any, Tuple
+from typing import Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs.spatial_graph import AutoSpatialGraph
+from hyperextract.types import AutoSpatialGraph
# ==============================================================================
# 1. Schema Definitions
diff --git a/hyperextract/templates/en/chemistry/protocol.py b/hyperextract/templates/en/chemistry/protocol.py
index f0fc98a..85185fc 100644
--- a/hyperextract/templates/en/chemistry/protocol.py
+++ b/hyperextract/templates/en/chemistry/protocol.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any, Tuple
+from typing import List, Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs.temporal_graph import AutoTemporalGraph
+from hyperextract.types import AutoTemporalGraph
# ==============================================================================
# 1. Schema Definitions
diff --git a/hyperextract/templates/en/chemistry/reaction.py b/hyperextract/templates/en/chemistry/reaction.py
index 5ac119f..4c2e956 100644
--- a/hyperextract/templates/en/chemistry/reaction.py
+++ b/hyperextract/templates/en/chemistry/reaction.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any, Tuple
+from typing import List, Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.hypergraphs.base import AutoHypergraph
+from hyperextract.types import AutoHypergraph
# ==============================================================================
# 1. Schema Definitions
diff --git a/hyperextract/templates/en/general/concept_map.py b/hyperextract/templates/en/general/concept_map.py
index d19fee9..dbc9c78 100644
--- a/hyperextract/templates/en/general/concept_map.py
+++ b/hyperextract/templates/en/general/concept_map.py
@@ -2,7 +2,7 @@ from typing import List, Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs import AutoGraph
+from hyperextract.types import AutoGraph
# ==============================================================================
# 1. Schema Definitions
diff --git a/hyperextract/templates/en/general/knowledge_graph.py b/hyperextract/templates/en/general/knowledge_graph.py
index 6b6880c..5f76954 100644
--- a/hyperextract/templates/en/general/knowledge_graph.py
+++ b/hyperextract/templates/en/general/knowledge_graph.py
@@ -2,7 +2,7 @@ from typing import List, Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs import AutoGraph
+from hyperextract.types import AutoGraph
# ==============================================================================
# 1. Schema Definitions
diff --git a/hyperextract/templates/en/general/logic_graph.py b/hyperextract/templates/en/general/logic_graph.py
index def0289..e15ea60 100644
--- a/hyperextract/templates/en/general/logic_graph.py
+++ b/hyperextract/templates/en/general/logic_graph.py
@@ -2,7 +2,7 @@ from typing import List, Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs import AutoGraph
+from hyperextract.types import AutoGraph
# ==============================================================================
# 1. Schema Definitions
diff --git a/hyperextract/templates/zh/agriculture/crop_cycle.py b/hyperextract/templates/zh/agriculture/crop_cycle.py
index 17e71b4..2fe6546 100644
--- a/hyperextract/templates/zh/agriculture/crop_cycle.py
+++ b/hyperextract/templates/zh/agriculture/crop_cycle.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any
+from typing import Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs import AutoGraph
+from hyperextract.types import AutoGraph
# ==============================================================================
# 1. Schema 定义 (Schema Definitions)
diff --git a/hyperextract/templates/zh/agriculture/livestock.py b/hyperextract/templates/zh/agriculture/livestock.py
index 51b2d30..ebf9ae3 100644
--- a/hyperextract/templates/zh/agriculture/livestock.py
+++ b/hyperextract/templates/zh/agriculture/livestock.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any
+from typing import Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs import AutoGraph
+from hyperextract.types import AutoGraph
# ==============================================================================
# 1. Schema 定义 (Schema Definitions)
diff --git a/hyperextract/templates/zh/agriculture/supply_chain.py b/hyperextract/templates/zh/agriculture/supply_chain.py
index e1cdf9c..3377645 100644
--- a/hyperextract/templates/zh/agriculture/supply_chain.py
+++ b/hyperextract/templates/zh/agriculture/supply_chain.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any
+from typing import Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs import AutoGraph
+from hyperextract.types import AutoGraph
# ==============================================================================
# 1. Schema 定义 (Schema Definitions)
diff --git a/hyperextract/templates/zh/art/exhibition.py b/hyperextract/templates/zh/art/exhibition.py
index 1fc04e7..e2dfaa0 100644
--- a/hyperextract/templates/zh/art/exhibition.py
+++ b/hyperextract/templates/zh/art/exhibition.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any
+from typing import Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs import AutoGraph
+from hyperextract.types import AutoGraph
# ==============================================================================
# 1. 模式定义 (Schema)
diff --git a/hyperextract/templates/zh/art/movement.py b/hyperextract/templates/zh/art/movement.py
index bd00990..a00b594 100644
--- a/hyperextract/templates/zh/art/movement.py
+++ b/hyperextract/templates/zh/art/movement.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any
+from typing import Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs import AutoGraph
+from hyperextract.types import AutoGraph
# ==============================================================================
# 1. 模式定义 (Schema)
diff --git a/hyperextract/templates/zh/art/provenance.py b/hyperextract/templates/zh/art/provenance.py
index 542d710..6337f88 100644
--- a/hyperextract/templates/zh/art/provenance.py
+++ b/hyperextract/templates/zh/art/provenance.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any
+from typing import Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs import AutoGraph
+from hyperextract.types import AutoGraph
# ==============================================================================
# 1. 模式定义 (Schema)
diff --git a/hyperextract/templates/zh/automotive/car_spec.py b/hyperextract/templates/zh/automotive/car_spec.py
index 34b18a3..8b2bdba 100644
--- a/hyperextract/templates/zh/automotive/car_spec.py
+++ b/hyperextract/templates/zh/automotive/car_spec.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any
+from typing import Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs import AutoGraph
+from hyperextract.types import AutoGraph
# ==============================================================================
# 1. 模式定义 (Schema)
diff --git a/hyperextract/templates/zh/automotive/maintenance.py b/hyperextract/templates/zh/automotive/maintenance.py
index ae1fb0f..df98ffd 100644
--- a/hyperextract/templates/zh/automotive/maintenance.py
+++ b/hyperextract/templates/zh/automotive/maintenance.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any
+from typing import Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs import AutoGraph
+from hyperextract.types import AutoGraph
# ==============================================================================
# 1. 模式定义 (Schema)
diff --git a/hyperextract/templates/zh/automotive/manufacturing.py b/hyperextract/templates/zh/automotive/manufacturing.py
index 38bf846..fb0f851 100644
--- a/hyperextract/templates/zh/automotive/manufacturing.py
+++ b/hyperextract/templates/zh/automotive/manufacturing.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any
+from typing import Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs import AutoGraph
+from hyperextract.types import AutoGraph
# ==============================================================================
# 1. 模式定义 (Schema)
diff --git a/hyperextract/templates/zh/biology/metabolic.py b/hyperextract/templates/zh/biology/metabolic.py
index 01a5cf2..dcf9101 100644
--- a/hyperextract/templates/zh/biology/metabolic.py
+++ b/hyperextract/templates/zh/biology/metabolic.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any, Tuple
+from typing import List, Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.hypergraphs.base import AutoHypergraph
+from hyperextract.types import AutoHypergraph
# ==============================================================================
# 1. Schema Definitions
diff --git a/hyperextract/templates/zh/biology/network.py b/hyperextract/templates/zh/biology/network.py
index 9e19f38..932b2ab 100644
--- a/hyperextract/templates/zh/biology/network.py
+++ b/hyperextract/templates/zh/biology/network.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any, Tuple
+from typing import Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs.base import AutoGraph
+from hyperextract.types import AutoGraph
# ==============================================================================
# 1. Schema Definitions
diff --git a/hyperextract/templates/zh/biology/taxonomy.py b/hyperextract/templates/zh/biology/taxonomy.py
index a4894cb..39e340d 100644
--- a/hyperextract/templates/zh/biology/taxonomy.py
+++ b/hyperextract/templates/zh/biology/taxonomy.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any, Tuple
+from typing import Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs.base import AutoGraph
+from hyperextract.types import AutoGraph
# ==============================================================================
# 1. Schema Definitions
diff --git a/hyperextract/templates/zh/business/ecosystem.py b/hyperextract/templates/zh/business/ecosystem.py
index 759d8e7..1a3375c 100644
--- a/hyperextract/templates/zh/business/ecosystem.py
+++ b/hyperextract/templates/zh/business/ecosystem.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any, Tuple
+from typing import List, Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.hypergraphs.base import AutoHypergraph
+from hyperextract.types import AutoHypergraph
# ==============================================================================
# 1. Schema Definitions
diff --git a/hyperextract/templates/zh/business/equity.py b/hyperextract/templates/zh/business/equity.py
index 814a940..ea3973e 100644
--- a/hyperextract/templates/zh/business/equity.py
+++ b/hyperextract/templates/zh/business/equity.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any, Tuple
+from typing import Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs.base import AutoGraph
+from hyperextract.types import AutoGraph
# ==============================================================================
# 1. Schema Definitions
diff --git a/hyperextract/templates/zh/business/strategy.py b/hyperextract/templates/zh/business/strategy.py
index 78100ba..504a2c7 100644
--- a/hyperextract/templates/zh/business/strategy.py
+++ b/hyperextract/templates/zh/business/strategy.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any, Tuple
+from typing import Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs.temporal_graph import AutoTemporalGraph
+from hyperextract.types import AutoTemporalGraph
# ==============================================================================
# 1. Schema Definitions
diff --git a/hyperextract/templates/zh/chemistry/molecular.py b/hyperextract/templates/zh/chemistry/molecular.py
index 62b9fb3..c4840b0 100644
--- a/hyperextract/templates/zh/chemistry/molecular.py
+++ b/hyperextract/templates/zh/chemistry/molecular.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any, Tuple
+from typing import Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs.spatial_graph import AutoSpatialGraph
+from hyperextract.types import AutoSpatialGraph
# ==============================================================================
# 1. Schema Definitions
diff --git a/hyperextract/templates/zh/chemistry/protocol.py b/hyperextract/templates/zh/chemistry/protocol.py
index d8478b8..cea1003 100644
--- a/hyperextract/templates/zh/chemistry/protocol.py
+++ b/hyperextract/templates/zh/chemistry/protocol.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any, Tuple
+from typing import List, Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs.temporal_graph import AutoTemporalGraph
+from hyperextract.types import AutoTemporalGraph
# ==============================================================================
# 1. Schema Definitions
diff --git a/hyperextract/templates/zh/chemistry/reaction.py b/hyperextract/templates/zh/chemistry/reaction.py
index ecf77f7..3738684 100644
--- a/hyperextract/templates/zh/chemistry/reaction.py
+++ b/hyperextract/templates/zh/chemistry/reaction.py
@@ -1,8 +1,8 @@
-from typing import List, Optional, Any, Tuple
+from typing import List, Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.hypergraphs.base import AutoHypergraph
+from hyperextract.types import AutoHypergraph
# ==============================================================================
# 1. Schema Definitions
diff --git a/hyperextract/templates/zh/general/concept_map.py b/hyperextract/templates/zh/general/concept_map.py
index 80209c7..0e43f6d 100644
--- a/hyperextract/templates/zh/general/concept_map.py
+++ b/hyperextract/templates/zh/general/concept_map.py
@@ -2,7 +2,7 @@ from typing import List, Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs import AutoGraph
+from hyperextract.types import AutoGraph
# ==============================================================================
# 1. Schema 定义 (Schema Definitions)
diff --git a/hyperextract/templates/zh/general/knowledge_graph.py b/hyperextract/templates/zh/general/knowledge_graph.py
index 32742b5..39e626f 100644
--- a/hyperextract/templates/zh/general/knowledge_graph.py
+++ b/hyperextract/templates/zh/general/knowledge_graph.py
@@ -2,7 +2,7 @@ from typing import List, Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs import AutoGraph
+from hyperextract.types import AutoGraph
# ==============================================================================
# 1. Schema 定义 (Schema Definitions)
diff --git a/hyperextract/templates/zh/general/logic_graph.py b/hyperextract/templates/zh/general/logic_graph.py
index c992d4c..c7873d5 100644
--- a/hyperextract/templates/zh/general/logic_graph.py
+++ b/hyperextract/templates/zh/general/logic_graph.py
@@ -2,7 +2,7 @@ from typing import List, Optional, Any
from pydantic import BaseModel, Field
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
-from hyperextract.graphs import AutoGraph
+from hyperextract.types import AutoGraph
# ==============================================================================
# 1. Schema 定义 (Schema Definitions)
diff --git a/hyperextract/types/__init__.py b/hyperextract/types/__init__.py
new file mode 100644
index 0000000..d985fc0
--- /dev/null
+++ b/hyperextract/types/__init__.py
@@ -0,0 +1,35 @@
+"""Types - Core data structures for automatic knowledge extraction.
+
+This module contains the fundamental, reusable data structure primitives that can
+automatically extract knowledge from text. These are the "building blocks" of the
+Hyper-Extract framework.
+"""
+
+from .base import BaseAutoType
+from .model import AutoModel
+from .list import AutoList, AutoListSchema
+from .set import AutoSet, AutoSetSchema
+from .graph import AutoGraph, AutoGraphSchema
+from .hypergraph import AutoHypergraph, AutoHypergraphSchema
+from .temporal_graph import AutoTemporalGraph
+from .spatial_graph import AutoSpatialGraph
+from .spatio_temporal_graph import AutoSpatioTemporalGraph
+
+__all__ = [
+ # Base class
+ "BaseAutoType",
+ # Scalar types
+ "AutoModel",
+ "AutoList",
+ "AutoListSchema",
+ "AutoSet",
+ "AutoSetSchema",
+ # Graph types
+ "AutoGraph",
+ "AutoGraphSchema",
+ "AutoHypergraph",
+ "AutoHypergraphSchema",
+ "AutoTemporalGraph",
+ "AutoSpatialGraph",
+ "AutoSpatioTemporalGraph",
+]
diff --git a/hyperextract/core/base.py b/hyperextract/types/base.py
similarity index 100%
rename from hyperextract/core/base.py
rename to hyperextract/types/base.py
diff --git a/hyperextract/graphs/base.py b/hyperextract/types/graph.py
similarity index 99%
rename from hyperextract/graphs/base.py
rename to hyperextract/types/graph.py
index 260ce56..40f7ffa 100644
--- a/hyperextract/graphs/base.py
+++ b/hyperextract/types/graph.py
@@ -24,7 +24,7 @@ from ontomem import OMem
from ontomem.merger import MergeStrategy, create_merger, BaseMerger
from ontosight import view_graph
-from hyperextract.core import BaseAutoType
+from .base import BaseAutoType
from hyperextract.utils.logging import logger
diff --git a/hyperextract/hypergraphs/base.py b/hyperextract/types/hypergraph.py
similarity index 99%
rename from hyperextract/hypergraphs/base.py
rename to hyperextract/types/hypergraph.py
index e7e3902..fd924c5 100644
--- a/hyperextract/hypergraphs/base.py
+++ b/hyperextract/types/hypergraph.py
@@ -25,7 +25,7 @@ from ontomem import OMem
from ontomem.merger import MergeStrategy, create_merger, BaseMerger
from ontosight import view_hypergraph
-from hyperextract.core import BaseAutoType
+from .base import BaseAutoType
from hyperextract.utils.logging import logger
diff --git a/hyperextract/core/list.py b/hyperextract/types/list.py
similarity index 100%
rename from hyperextract/core/list.py
rename to hyperextract/types/list.py
diff --git a/hyperextract/core/model.py b/hyperextract/types/model.py
similarity index 100%
rename from hyperextract/core/model.py
rename to hyperextract/types/model.py
diff --git a/hyperextract/core/set.py b/hyperextract/types/set.py
similarity index 100%
rename from hyperextract/core/set.py
rename to hyperextract/types/set.py
diff --git a/hyperextract/graphs/spatial_graph.py b/hyperextract/types/spatial_graph.py
similarity index 99%
rename from hyperextract/graphs/spatial_graph.py
rename to hyperextract/types/spatial_graph.py
index 8e03160..6d33e82 100644
--- a/hyperextract/graphs/spatial_graph.py
+++ b/hyperextract/types/spatial_graph.py
@@ -6,7 +6,7 @@ from langchain_core.prompts import ChatPromptTemplate
from langchain_core.embeddings import Embeddings
from ontomem.merger import MergeStrategy, BaseMerger
-from hyperextract.graphs.base import (
+from .graph import (
AutoGraph,
NodeSchema,
EdgeSchema,
diff --git a/hyperextract/graphs/spatio_temporal_graph.py b/hyperextract/types/spatio_temporal_graph.py
similarity index 99%
rename from hyperextract/graphs/spatio_temporal_graph.py
rename to hyperextract/types/spatio_temporal_graph.py
index c591f1b..8831534 100644
--- a/hyperextract/graphs/spatio_temporal_graph.py
+++ b/hyperextract/types/spatio_temporal_graph.py
@@ -7,7 +7,7 @@ from langchain_core.prompts import ChatPromptTemplate
from langchain_core.embeddings import Embeddings
from ontomem.merger import MergeStrategy, BaseMerger
-from hyperextract.graphs.base import (
+from .graph import (
AutoGraph,
NodeSchema,
EdgeSchema,
diff --git a/hyperextract/graphs/temporal_graph.py b/hyperextract/types/temporal_graph.py
similarity index 99%
rename from hyperextract/graphs/temporal_graph.py
rename to hyperextract/types/temporal_graph.py
index 076d53f..a898746 100644
--- a/hyperextract/graphs/temporal_graph.py
+++ b/hyperextract/types/temporal_graph.py
@@ -7,7 +7,7 @@ from langchain_core.prompts import ChatPromptTemplate
from langchain_core.embeddings import Embeddings
from ontomem.merger import MergeStrategy, BaseMerger
-from hyperextract.graphs.base import (
+from .graph import (
AutoGraph,
NodeSchema,
EdgeSchema,