Skip to content

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

fix: 更新互动双方映射规则的注释,优化代码可读性

yifanfeng9713cd54e66ada
diff --git a/examples/auto_graph_demo.py b/examples/auto_graph_demo.py
index df55785..397cc2a 100644
--- a/examples/auto_graph_demo.py
+++ b/examples/auto_graph_demo.py
@@ -284,7 +284,7 @@ def run_demo():
node_key_extractor=lambda x: x.name,
# 2. 互动唯一性规则
edge_key_extractor=lambda x: f"{x.source}_{x.action_type}_{x.target}",
- # 3. 验证规则
+ # 3. 互动双方映射规则
nodes_in_edge_extractor=lambda x: (x.source, x.target),
llm_client=llm,
embedder=embedder,
diff --git a/hyperextract/graphs/base.py b/hyperextract/graphs/base.py
index c5687a3..aa1148e 100644
--- a/hyperextract/graphs/base.py
+++ b/hyperextract/graphs/base.py
@@ -13,7 +13,6 @@ from typing import (
TypeVar,
Generic,
TYPE_CHECKING,
- Union,
)
from pathlib import Path
from pydantic import BaseModel, Field, create_model
@@ -584,16 +583,17 @@ class AutoGraph(BaseAutoType[AutoGraphSchema[Node, Edge]], Generic[Node, Edge]):
def merge_batch_data(
self,
- data_list_or_tuple: List[Union[AutoGraphSchema, Tuple[List[Node], List[Edge]]]],
+ data_list_or_tuple: List[AutoGraphSchema] | Tuple[List[List[Node]], List[List[Edge]]],
) -> AutoGraphSchema:
"""Merge multiple graphs or node/edge tuples into one.
Supports two input formats:
- - AutoGraphSchema objects (standard format)
- - Tuples of (List[Node], List[Edge]) (optimization for batch processing)
+ - List of AutoGraphSchema objects (standard format)
+ - Tuple of (List[List[Node]], List[List[Edge]]) (optimization for batch processing)
Args:
- data_list_or_tuple: List of AutoGraphSchema or (nodes, edges) tuples.
+ data_list_or_tuple: Either a list of AutoGraphSchema objects or a tuple of
+ (nodes_lists, edges_lists) where each list contains items from multiple chunks.
Returns:
Merged graph.
@@ -657,7 +657,7 @@ class AutoGraph(BaseAutoType[AutoGraphSchema[Node, Edge]], Generic[Node, Edge]):
top_k: int = 3,
search_nodes: bool = True,
search_edges: bool = False,
- ) -> Union[List[Node], List[Edge], Tuple[List[Node], List[Edge]]]:
+ ) -> List[Node] | List[Edge] | Tuple[List[Node], List[Edge]]:
"""Unified graph search interface.
Supports searching nodes only, edges only, or both simultaneously.