Skip to content

Commit 5101575

Browse files
authored
Use the right interface in SimpleKGPipeline annotations (neo4j#275)
* Use the right interface in SimpleKGPipeline annotations * Fix UT
1 parent 439b4b9 commit 5101575

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/neo4j_graphrag/experimental/pipeline/kg_builder.py

+17-12
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@
1515

1616
from __future__ import annotations
1717

18-
from typing import Any, List, Optional, Sequence, Union
18+
from typing import List, Optional, Sequence, Union
1919

2020
import neo4j
2121
from pydantic import ValidationError
2222

2323
from neo4j_graphrag.embeddings import Embedder
24+
from neo4j_graphrag.experimental.components.entity_relation_extractor import OnError
25+
from neo4j_graphrag.experimental.components.kg_writer import KGWriter
26+
from neo4j_graphrag.experimental.components.pdf_loader import DataLoader
27+
from neo4j_graphrag.experimental.components.text_splitters.base import TextSplitter
2428
from neo4j_graphrag.experimental.components.types import LexicalGraphConfig
29+
from neo4j_graphrag.experimental.pipeline.config.object_config import ComponentType
2530
from neo4j_graphrag.experimental.pipeline.config.runner import PipelineRunner
2631
from neo4j_graphrag.experimental.pipeline.config.template_pipeline import (
2732
SimpleKGPipelineConfig,
@@ -59,9 +64,9 @@ class SimpleKGPipeline:
5964
from_pdf (bool): Determines whether to include the PdfLoader in the pipeline.
6065
If True, expects `file_path` input in `run` methods.
6166
If False, expects `text` input in `run` methods.
62-
text_splitter (Optional[Any]): A text splitter component. Defaults to FixedSizeSplitter().
63-
pdf_loader (Optional[Any]): A PDF loader component. Defaults to PdfLoader().
64-
kg_writer (Optional[Any]): A knowledge graph writer component. Defaults to Neo4jWriter().
67+
text_splitter (Optional[TextSplitter]): A text splitter component. Defaults to FixedSizeSplitter().
68+
pdf_loader (Optional[DataLoader]): A PDF loader component. Defaults to PdfLoader().
69+
kg_writer (Optional[KGWriter]): A knowledge graph writer component. Defaults to Neo4jWriter().
6570
on_error (str): Error handling strategy for the Entity and relation extractor. Defaults to "IGNORE", where chunk will be ignored if extraction fails. Possible values: "RAISE" or "IGNORE".
6671
perform_entity_resolution (bool): Merge entities with same label and name. Default: True
6772
prompt_template (str): A custom prompt template to use for extraction.
@@ -77,9 +82,9 @@ def __init__(
7782
relations: Optional[Sequence[RelationInputType]] = None,
7883
potential_schema: Optional[List[tuple[str, str, str]]] = None,
7984
from_pdf: bool = True,
80-
text_splitter: Optional[Any] = None,
81-
pdf_loader: Optional[Any] = None,
82-
kg_writer: Optional[Any] = None,
85+
text_splitter: Optional[TextSplitter] = None,
86+
pdf_loader: Optional[DataLoader] = None,
87+
kg_writer: Optional[KGWriter] = None,
8388
on_error: str = "IGNORE",
8489
prompt_template: Union[ERExtractionTemplate, str] = ERExtractionTemplate(),
8590
perform_entity_resolution: bool = True,
@@ -96,16 +101,16 @@ def __init__(
96101
relations=relations or [],
97102
potential_schema=potential_schema,
98103
from_pdf=from_pdf,
99-
pdf_loader=pdf_loader,
100-
kg_writer=kg_writer,
101-
text_splitter=text_splitter,
102-
on_error=on_error, # type: ignore[arg-type]
104+
pdf_loader=ComponentType(pdf_loader) if pdf_loader else None,
105+
kg_writer=ComponentType(kg_writer) if kg_writer else None,
106+
text_splitter=ComponentType(text_splitter) if text_splitter else None,
107+
on_error=OnError(on_error),
103108
prompt_template=prompt_template,
104109
perform_entity_resolution=perform_entity_resolution,
105110
lexical_graph_config=lexical_graph_config,
106111
neo4j_database=neo4j_database,
107112
)
108-
except ValidationError as e:
113+
except (ValidationError, ValueError) as e:
109114
raise PipelineDefinitionError() from e
110115

111116
self.runner = PipelineRunner.from_config(config)

0 commit comments

Comments
 (0)