Skip to content

Add RunContext to doc and improve protocol description #320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/source/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,16 @@ EventCallbackProtocol

.. autoclass:: neo4j_graphrag.experimental.pipeline.notification.EventCallbackProtocol
:members: __call__


TaskProgressCallbackProtocol
============================

.. autoclass:: neo4j_graphrag.experimental.pipeline.types.context.TaskProgressCallbackProtocol
:members: __call__


RunContext
==========

.. autoclass:: neo4j_graphrag.experimental.pipeline.types.context.RunContext
5 changes: 5 additions & 0 deletions src/neo4j_graphrag/experimental/pipeline/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ class TaskEvent(Event):


class EventCallbackProtocol(Protocol):
"""This protocol is used to send events about pipeline progress
from the pipeline itself. It will receive either PipelineEvent or
TaskEvent depending on the event type.
"""

def __call__(self, event: Event) -> Awaitable[None]: ...


Expand Down
10 changes: 8 additions & 2 deletions src/neo4j_graphrag/experimental/pipeline/types/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@


@runtime_checkable
class TaskProgressCallbackProtocol(Protocol):
class TaskProgressNotifierProtocol(Protocol):
"""This protocol is used to send events from the component to the
Pipeline callback protocol.
The event sent to the callback will be of type :ref:`TaskEvent`,
with `event_type=TASK_PROGRESS`.
"""

def __call__(self, message: str, data: dict[str, Any]) -> Awaitable[None]: ...


Expand All @@ -28,7 +34,7 @@ class RunContext(BaseModel):

run_id: str
task_name: str
notifier: Optional[TaskProgressCallbackProtocol] = None
notifier: Optional[TaskProgressNotifierProtocol] = None

model_config = ConfigDict(arbitrary_types_allowed=True)

Expand Down