Skip to content

Commit b2a750a

Browse files
committed
Update documentation
1 parent 6a55af4 commit b2a750a

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

docs/source/api.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@ API Documentation
99
Components
1010
**********
1111

12+
Component
13+
=========
14+
15+
.. autoclass:: neo4j_graphrag.experimental.pipeline.component.Component
16+
:members: run, run_with_context
17+
1218
DataLoader
1319
==========
1420

1521
.. autoclass:: neo4j_graphrag.experimental.components.pdf_loader.DataLoader
1622
:members: run, get_document_metadata
1723

18-
1924
PdfLoader
2025
=========
2126

@@ -59,7 +64,6 @@ LexicalGraphBuilder
5964
:members:
6065
:exclude-members: component_inputs, component_outputs
6166

62-
6367
Neo4jChunkReader
6468
================
6569

docs/source/types.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,22 +158,22 @@ ParamFromEnvConfig
158158
EventType
159159
=========
160160

161-
.. autoenum:: neo4j_graphrag.experimental.pipeline.types.EventType
161+
.. autoenum:: neo4j_graphrag.experimental.pipeline.notification.EventType
162162

163163

164164
PipelineEvent
165165
==============
166166

167-
.. autoclass:: neo4j_graphrag.experimental.pipeline.types.PipelineEvent
167+
.. autoclass:: neo4j_graphrag.experimental.pipeline.notification.PipelineEvent
168168

169169
TaskEvent
170170
==============
171171

172-
.. autoclass:: neo4j_graphrag.experimental.pipeline.types.TaskEvent
172+
.. autoclass:: neo4j_graphrag.experimental.pipeline.notification.TaskEvent
173173

174174

175175
EventCallbackProtocol
176176
=====================
177177

178-
.. autoclass:: neo4j_graphrag.experimental.pipeline.types.EventCallbackProtocol
178+
.. autoclass:: neo4j_graphrag.experimental.pipeline.notification.EventCallbackProtocol
179179
:members: __call__

docs/source/user_guide_pipeline.rst

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ their own by following these steps:
2222

2323
1. Create a subclass of the Pydantic `neo4j_graphrag.experimental.pipeline.DataModel` to represent the data being returned by the component
2424
2. Create a subclass of `neo4j_graphrag.experimental.pipeline.Component`
25-
3. Create a run method in this new class and specify the required inputs and output model using the just created `DataModel`
25+
3. Create a `run_with_context` method in this new class and specify the required inputs and output model using the just created `DataModel`
2626
4. Implement the run method: it's an `async` method, allowing tasks to be parallelized and awaited within this method.
2727

2828
An example is given below, where a `ComponentAdd` is created to add two numbers together and return
@@ -31,12 +31,13 @@ the resulting sum:
3131
.. code:: python
3232
3333
from neo4j_graphrag.experimental.pipeline import Component, DataModel
34+
from neo4j_graphrag.experimental.pipeline.types.context import RunContext
3435
3536
class IntResultModel(DataModel):
3637
result: int
3738
3839
class ComponentAdd(Component):
39-
async def run(self, number1: int, number2: int = 1) -> IntResultModel:
40+
async def run_with_context(self, context_: RunContext, number1: int, number2: int = 1) -> IntResultModel:
4041
return IntResultModel(result = number1 + number2)
4142
4243
Read more about :ref:`components-section` in the API Documentation.
@@ -141,6 +142,7 @@ It is possible to add a callback to receive notification about pipeline progress
141142
- `PIPELINE_STARTED`, when pipeline starts
142143
- `PIPELINE_FINISHED`, when pipeline ends
143144
- `TASK_STARTED`, when a task starts
145+
- `TASK_PROGRESS`, sent by each component (depends on component's implementation, see below)
144146
- `TASK_FINISHED`, when a task ends
145147

146148

@@ -172,3 +174,29 @@ See :ref:`pipelineevent` and :ref:`taskevent` to see what is sent in each event
172174
# ... add components, connect them as usual
173175
174176
await pipeline.run(...)
177+
178+
179+
Send Events from Components
180+
===========================
181+
182+
Components can send notifications about their progress using the `notify` function from
183+
the `context_`:
184+
185+
.. code:: python
186+
187+
from neo4j_graphrag.experimental.pipeline import Component, DataModel
188+
from neo4j_graphrag.experimental.pipeline.types.context import RunContext
189+
190+
class IntResultModel(DataModel):
191+
result: int
192+
193+
class ComponentAdd(Component):
194+
async def run_with_context(self, context_: RunContext, number1: int, number2: int = 1) -> IntResultModel:
195+
for fake_iteration in range(10):
196+
await context_.notify(
197+
message=f"Starting iteration {fake_iteration} out of 10",
198+
data={"iteration": fake_iteration, "total": 10}
199+
)
200+
return IntResultModel(result = number1 + number2)
201+
202+
This will send an `TASK_PROGRESS` event to the pipeline callback.

0 commit comments

Comments
 (0)