Skip to content

Commit c77b559

Browse files
feat: configurable max_loop in build_kg (#133)
1 parent 714e959 commit c77b559

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

graphgen/operators/build_kg/build_kg_service.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@
1212

1313

1414
class BuildKGService(BaseOperator):
15-
def __init__(self, working_dir: str = "cache", graph_backend: str = "kuzu"):
15+
def __init__(
16+
self, working_dir: str = "cache", graph_backend: str = "kuzu", **build_kwargs
17+
):
1618
super().__init__(working_dir=working_dir, op_name="build_kg_service")
1719
self.llm_client: BaseLLMWrapper = init_llm("synthesizer")
1820
self.graph_storage: BaseGraphStorage = init_storage(
1921
backend=graph_backend, working_dir=working_dir, namespace="graph"
2022
)
23+
self.build_kwargs = build_kwargs
24+
self.max_loop: int = int(self.build_kwargs.get("max_loop", 3))
2125

2226
def process(self, batch: pd.DataFrame) -> pd.DataFrame:
2327
docs = batch.to_dict(orient="records")
@@ -46,6 +50,7 @@ def build_kg(self, chunks: List[Chunk]) -> None:
4650
llm_client=self.llm_client,
4751
kg_instance=self.graph_storage,
4852
chunks=text_chunks,
53+
max_loop=self.max_loop,
4954
)
5055
if len(mm_chunks) == 0:
5156
logger.info("All multi-modal chunks are already in the storage")

graphgen/operators/build_kg/build_text_kg.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ def build_text_kg(
1212
llm_client: BaseLLMWrapper,
1313
kg_instance: BaseGraphStorage,
1414
chunks: List[Chunk],
15+
max_loop: int = 3,
1516
):
1617
"""
1718
:param llm_client: Synthesizer LLM model to extract entities and relationships
1819
:param kg_instance
1920
:param chunks
21+
:param max_loop: Maximum number of loops for entity and relationship extraction
2022
:return:
2123
"""
2224

23-
kg_builder = LightRAGKGBuilder(llm_client=llm_client, max_loop=3)
25+
kg_builder = LightRAGKGBuilder(llm_client=llm_client, max_loop=max_loop)
2426

2527
results = run_concurrent(
2628
kg_builder.extract,

0 commit comments

Comments
 (0)