Skip to content

Commit 5f2673b

Browse files
author
Snehit Gajjar
committed
Clean up
1 parent 4d54074 commit 5f2673b

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

graphrag/api/index.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"""
1010

1111
import logging
12+
from typing import Any
1213

1314
from graphrag.callbacks.noop_workflow_callbacks import NoopWorkflowCallbacks
1415
from graphrag.callbacks.workflow_callbacks import WorkflowCallbacks
@@ -30,7 +31,7 @@ async def build_index(
3031
is_update_run: bool = False,
3132
memory_profile: bool = False,
3233
callbacks: list[WorkflowCallbacks] | None = None,
33-
additional_context: dict | None = None,
34+
additional_context: dict[str, Any] | None = None,
3435
) -> list[PipelineRunResult]:
3536
"""Run the pipeline with the given configuration.
3637
@@ -44,6 +45,8 @@ async def build_index(
4445
Whether to enable memory profiling.
4546
callbacks : list[WorkflowCallbacks] | None default=None
4647
A list of callbacks to register.
48+
additional_context : dict[str, Any] | None default=None
49+
Additional context to pass to the pipeline run. This can be accessed using PipelineState.
4750
4851
Returns
4952
-------

graphrag/index/run/run_pipeline.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import time
1010
from collections.abc import AsyncIterable
1111
from dataclasses import asdict
12+
from typing import Any
1213

1314
from graphrag.callbacks.workflow_callbacks import WorkflowCallbacks
1415
from graphrag.config.models.graph_rag_config import GraphRagConfig
@@ -28,7 +29,7 @@ async def run_pipeline(
2829
config: GraphRagConfig,
2930
callbacks: WorkflowCallbacks,
3031
is_update_run: bool = False,
31-
additional_context: dict | None = None,
32+
additional_context: dict[str, Any] | None = None,
3233
) -> AsyncIterable[PipelineRunResult]:
3334
"""Run all workflows using a simplified pipeline."""
3435
root_dir = config.root_dir
@@ -41,8 +42,13 @@ async def run_pipeline(
4142
state_json = await output_storage.get("context.json")
4243
state = json.loads(state_json) if state_json else {}
4344

44-
for key, value in (additional_context or {}).items():
45-
state["additional_context"][key] = value
45+
if additional_context is not None:
46+
if "additional_context" not in state:
47+
state["additional_context"] = {}
48+
49+
# add additional context to the state
50+
for key, value in (additional_context or {}).items():
51+
state["additional_context"][key] = value
4652

4753
if is_update_run:
4854
logger.info("Running incremental indexing.")

0 commit comments

Comments
 (0)