Skip to content

Commit 4791786

Browse files
authored
Merge branch 'main' into main
2 parents f304fb7 + 4db2c45 commit 4791786

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22

33
## Next
44

5+
## 1.6.1
6+
57
### Added
68

79
- Added the `run_with_context` method to `Component`. This method includes a `context_` parameter, which provides information about the pipeline from which the component is executed (e.g., the `run_id`). It also enables the component to send events to the pipeline's callback function.
810

11+
### Fixed
12+
13+
- Added `enforce_schema` parameter to `SimpleKGPipeline` for optional schema enforcement.
914

1015
## 1.6.0
1116

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
[tool.poetry]
1717
name = "neo4j-graphrag"
18-
version = "1.6.0"
18+
version = "1.6.1"
1919
description = "Python package to allow easy integration to Neo4j's GraphRAG features"
2020
authors = ["Neo4j, Inc <team-gen-ai@neo4j.com>"]
2121
license = "Apache License, Version 2.0"

src/neo4j_graphrag/experimental/pipeline/kg_builder.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
from neo4j_graphrag.experimental.components.kg_writer import KGWriter
2626
from neo4j_graphrag.experimental.components.pdf_loader import DataLoader
2727
from neo4j_graphrag.experimental.components.text_splitters.base import TextSplitter
28-
from neo4j_graphrag.experimental.components.types import LexicalGraphConfig
28+
from neo4j_graphrag.experimental.components.types import (
29+
LexicalGraphConfig,
30+
SchemaEnforcementMode,
31+
)
2932
from neo4j_graphrag.experimental.pipeline.config.object_config import ComponentType
3033
from neo4j_graphrag.experimental.pipeline.config.runner import PipelineRunner
3134
from neo4j_graphrag.experimental.pipeline.config.template_pipeline import (
@@ -61,6 +64,7 @@ class SimpleKGPipeline:
6164
- dict: following the SchemaRelation schema, ie with label, description and properties keys
6265
6366
potential_schema (Optional[List[tuple]]): A list of potential schema relationships.
67+
enforce_schema (str): Validation of the extracted entities/rels against the provided schema. Defaults to "NONE", where schema enforcement will be ignored even if the schema is provided. Possible values "None" or "STRICT".
6468
from_pdf (bool): Determines whether to include the PdfLoader in the pipeline.
6569
If True, expects `file_path` input in `run` methods.
6670
If False, expects `text` input in `run` methods.
@@ -81,6 +85,7 @@ def __init__(
8185
entities: Optional[Sequence[EntityInputType]] = None,
8286
relations: Optional[Sequence[RelationInputType]] = None,
8387
potential_schema: Optional[List[tuple[str, str, str]]] = None,
88+
enforce_schema: str = "NONE",
8489
from_pdf: bool = True,
8590
text_splitter: Optional[TextSplitter] = None,
8691
pdf_loader: Optional[DataLoader] = None,
@@ -100,6 +105,7 @@ def __init__(
100105
entities=entities or [],
101106
relations=relations or [],
102107
potential_schema=potential_schema,
108+
enforce_schema=SchemaEnforcementMode(enforce_schema),
103109
from_pdf=from_pdf,
104110
pdf_loader=ComponentType(pdf_loader) if pdf_loader else None,
105111
kg_writer=ComponentType(kg_writer) if kg_writer else None,

tests/unit/experimental/pipeline/test_kg_builder.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,20 @@ def test_simple_kg_pipeline_on_error_invalid_value() -> None:
151151
)
152152

153153

154+
def test_simple_kg_pipeline_enforce_schema_invalid_value() -> None:
155+
llm = MagicMock(spec=LLMInterface)
156+
driver = MagicMock(spec=neo4j.Driver)
157+
embedder = MagicMock(spec=Embedder)
158+
159+
with pytest.raises(PipelineDefinitionError):
160+
SimpleKGPipeline(
161+
llm=llm,
162+
driver=driver,
163+
embedder=embedder,
164+
enforce_schema="INVALID_VALUE",
165+
)
166+
167+
154168
@mock.patch(
155169
"neo4j_graphrag.experimental.components.kg_writer.get_version",
156170
return_value=((5, 23, 0), False, False),

0 commit comments

Comments
 (0)