Skip to content

Commit ae08316

Browse files
authored
Add await for each component run example to make it explicit that it's an async method (#143)
1 parent d1cef28 commit ae08316

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

docs/source/user_guide_kg_builder.rst

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ This package currently supports text extraction from PDFs:
7676
from neo4j_graphrag.experimental.components.pdf_loader import PdfLoader
7777
7878
loader = PdfLoader()
79-
loader.run(path=Path("my_file.pdf"))
79+
await loader.run(path=Path("my_file.pdf"))
8080
8181
To implement your own loader, use the `DataLoader` interface:
8282

@@ -115,7 +115,7 @@ Wrappers for LangChain and LlamaIndex text splitters are included in this packag
115115
splitter = LangChainTextSplitterAdapter(
116116
CharacterTextSplitter(chunk_size=4000, chunk_overlap=200, separator=".")
117117
)
118-
splitter.run(text="Hello World. Life is beautiful.")
118+
await splitter.run(text="Hello World. Life is beautiful.")
119119
120120
121121
Also see :ref:`langchaintextsplitteradapter` and :ref:`llamaindextextsplitteradapter`.
@@ -155,7 +155,7 @@ Example usage:
155155
from neo4j_graphrag.experimental.components.embedder import TextChunkEmbedder
156156
from neo4j_graphrag.embeddings.openai import OpenAIEmbeddings
157157
text_chunk_embedder = TextChunkEmbedder(embedder=OpenAIEmbeddings())
158-
text_chunk_embedder.run(text_chunks=TextChunks(chunks=[TextChunk(text="my_text")]))
158+
await text_chunk_embedder.run(text_chunks=TextChunks(chunks=[TextChunk(text="my_text")]))
159159
160160
.. note::
161161

@@ -257,6 +257,8 @@ It can be used in this way:
257257
},
258258
)
259259
)
260+
await extractor.run(chunks=TextChunks(chunks=[TextChunk(text="some text")]))
261+
260262
261263
.. warning::
262264

@@ -322,12 +324,12 @@ The default prompt uses the :ref:`erextractiontemplate`. It is possible to provi
322324
323325
extractor = LLMEntityRelationExtractor(
324326
llm=....,
325-
prompt="this is my prompt",
327+
prompt="Extract entities from {text}",
326328
)
327329
328330
The following variables can be used in the prompt:
329331

330-
- `text` (str): the text to be analyzed.
332+
- `text` (str): the text to be analyzed (mandatory).
331333
- `schema` (str): the graph schema to be used.
332334
- `examples` (str): examples for few-shot learning.
333335

@@ -351,17 +353,17 @@ If more customization is needed, it is possible to subclass the `EntityRelationE
351353
352354
class MyExtractor(EntityRelationExtractor):
353355
354-
@validate_call
355-
async def run(self, chunks: TextChunks, **kwargs: Any) -> Neo4jGraph:
356-
return Neo4jGraph(
357-
nodes=[
358-
Neo4jNode(id="0", label="Person", properties={"name": "A. Einstein"}),
359-
Neo4jNode(id="1", label="Concept", properties={"name": "Theory of relativity"}),
360-
],
361-
relationships=[
362-
Neo4jRelationship(type="PROPOSED_BY", start_node_id="1", end_node_id="0", properties={"year": 1915})
363-
],
364-
)
356+
@validate_call
357+
async def run(self, chunks: TextChunks, **kwargs: Any) -> Neo4jGraph:
358+
return Neo4jGraph(
359+
nodes=[
360+
Neo4jNode(id="0", label="Person", properties={"name": "A. Einstein"}),
361+
Neo4jNode(id="1", label="Concept", properties={"name": "Theory of relativity"}),
362+
],
363+
relationships=[
364+
Neo4jRelationship(type="PROPOSED_BY", start_node_id="1", end_node_id="0", properties={"year": 1915})
365+
],
366+
)
365367
366368
367369
See :ref:`entityrelationextractor`.
@@ -385,7 +387,7 @@ to a Neo4j database:
385387
) as driver:
386388
writer = Neo4jWriter(driver)
387389
graph = Neo4jGraph(nodes=[], relationships=[])
388-
asyncio.run(writer.run())
390+
await writer.run(graph)
389391
390392
See :ref:`neo4jgraph` for the description of the input type.
391393

0 commit comments

Comments
 (0)