Skip to content

Commit

Permalink
Add await for each component run example to make it explicit that it'…
Browse files Browse the repository at this point in the history
…s an async method (#143)
  • Loading branch information
stellasia authored Sep 23, 2024
1 parent d1cef28 commit ae08316
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions docs/source/user_guide_kg_builder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ This package currently supports text extraction from PDFs:
from neo4j_graphrag.experimental.components.pdf_loader import PdfLoader
loader = PdfLoader()
loader.run(path=Path("my_file.pdf"))
await loader.run(path=Path("my_file.pdf"))
To implement your own loader, use the `DataLoader` interface:

Expand Down Expand Up @@ -115,7 +115,7 @@ Wrappers for LangChain and LlamaIndex text splitters are included in this packag
splitter = LangChainTextSplitterAdapter(
CharacterTextSplitter(chunk_size=4000, chunk_overlap=200, separator=".")
)
splitter.run(text="Hello World. Life is beautiful.")
await splitter.run(text="Hello World. Life is beautiful.")
Also see :ref:`langchaintextsplitteradapter` and :ref:`llamaindextextsplitteradapter`.
Expand Down Expand Up @@ -155,7 +155,7 @@ Example usage:
from neo4j_graphrag.experimental.components.embedder import TextChunkEmbedder
from neo4j_graphrag.embeddings.openai import OpenAIEmbeddings
text_chunk_embedder = TextChunkEmbedder(embedder=OpenAIEmbeddings())
text_chunk_embedder.run(text_chunks=TextChunks(chunks=[TextChunk(text="my_text")]))
await text_chunk_embedder.run(text_chunks=TextChunks(chunks=[TextChunk(text="my_text")]))
.. note::

Expand Down Expand Up @@ -257,6 +257,8 @@ It can be used in this way:
},
)
)
await extractor.run(chunks=TextChunks(chunks=[TextChunk(text="some text")]))
.. warning::

Expand Down Expand Up @@ -322,12 +324,12 @@ The default prompt uses the :ref:`erextractiontemplate`. It is possible to provi
extractor = LLMEntityRelationExtractor(
llm=....,
prompt="this is my prompt",
prompt="Extract entities from {text}",
)
The following variables can be used in the prompt:

- `text` (str): the text to be analyzed.
- `text` (str): the text to be analyzed (mandatory).
- `schema` (str): the graph schema to be used.
- `examples` (str): examples for few-shot learning.

Expand All @@ -351,17 +353,17 @@ If more customization is needed, it is possible to subclass the `EntityRelationE
class MyExtractor(EntityRelationExtractor):
@validate_call
async def run(self, chunks: TextChunks, **kwargs: Any) -> Neo4jGraph:
return Neo4jGraph(
nodes=[
Neo4jNode(id="0", label="Person", properties={"name": "A. Einstein"}),
Neo4jNode(id="1", label="Concept", properties={"name": "Theory of relativity"}),
],
relationships=[
Neo4jRelationship(type="PROPOSED_BY", start_node_id="1", end_node_id="0", properties={"year": 1915})
],
)
@validate_call
async def run(self, chunks: TextChunks, **kwargs: Any) -> Neo4jGraph:
return Neo4jGraph(
nodes=[
Neo4jNode(id="0", label="Person", properties={"name": "A. Einstein"}),
Neo4jNode(id="1", label="Concept", properties={"name": "Theory of relativity"}),
],
relationships=[
Neo4jRelationship(type="PROPOSED_BY", start_node_id="1", end_node_id="0", properties={"year": 1915})
],
)
See :ref:`entityrelationextractor`.
Expand All @@ -385,7 +387,7 @@ to a Neo4j database:
) as driver:
writer = Neo4jWriter(driver)
graph = Neo4jGraph(nodes=[], relationships=[])
asyncio.run(writer.run())
await writer.run(graph)
See :ref:`neo4jgraph` for the description of the input type.

Expand Down

0 comments on commit ae08316

Please sign in to comment.