Skip to content

Commit 8905956

Browse files
Update docs
1 parent 4fd298d commit 8905956

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

docs/source/types.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ RelationshipType
9595

9696
.. autoclass:: neo4j_graphrag.experimental.components.schema.RelationshipType
9797

98+
Pattern
99+
=======
100+
101+
.. autoclass:: neo4j_graphrag.experimental.components.schema.Pattern
102+
98103
GraphSchema
99104
===========
100105

docs/source/user_guide_kg_builder.rst

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,49 @@ You can also save and reload the extracted schema:
867867
restored_schema = GraphSchema.from_file("my_schema.json") # or my_schema.yaml
868868
869869
870+
Using Structured Output with Schema Extraction
871+
-----------------------------------------------
872+
873+
For improved reliability with :ref:`OpenAILLM <openaillm>` or :ref:`VertexAILLM <vertexaillm>`, enable structured output mode. When ``use_structured_output=True``, the extractor passes the ``GraphSchema`` Pydantic model as ``response_format`` to the LLM, ensuring responses conform to the expected schema structure with automatic validation:
874+
875+
.. code:: python
876+
877+
from neo4j_graphrag.experimental.components.schema import SchemaFromTextExtractor
878+
from neo4j_graphrag.llm import OpenAILLM
879+
880+
llm = OpenAILLM(model_name="gpt-4o-mini", model_params={"temperature": 0})
881+
schema_extractor = SchemaFromTextExtractor(
882+
llm=llm,
883+
use_structured_output=True
884+
)
885+
886+
extracted_schema = await schema_extractor.run(text="Some text")
887+
888+
.. note::
889+
890+
Using ``use_structured_output=True`` with other LLM providers will raise a ``ValueError``. Do not pass ``response_format`` in constructor parameters; the extractor automatically sets it when calling ``invoke()``.
891+
892+
893+
Schema Validation and Node Properties
894+
--------------------------------------
895+
896+
**Important:** All node types must have at least one property defined. When using string shorthand for node types (e.g., ``"Person"``), a default ``"name"`` property is automatically added with ``additional_properties=True`` to allow flexible LLM extraction:
897+
898+
.. code:: python
899+
900+
# String shorthand - automatically gets default property
901+
NodeType("Person") # Becomes: properties=[{"name": "name", "type": "STRING"}], additional_properties=True
902+
903+
# Explicit definition - must include at least one property
904+
NodeType(
905+
label="Person",
906+
properties=[PropertyType(name="name", type="STRING")],
907+
additional_properties=True # Allow LLM to extract additional properties
908+
)
909+
910+
**Relationship types** with no properties automatically set ``additional_properties=True`` to preserve LLM-extracted properties during graph construction.
911+
912+
870913
Schema Visualization
871914
--------------------
872915

@@ -949,7 +992,7 @@ For improved reliability and type safety with :ref:`OpenAILLM <openaillm>` or :r
949992
950993
.. note::
951994

952-
Using `use_structured_output=True` with other LLM providers will raise a `ValueError`. Do not pass `response_format` in constructor parameters (`model_params` or `generation_config`); the extractor automatically sets it when calling `invoke()`.
995+
Structured output is only available for LLMs with ``supports_structured_output=True`` (currently :ref:`OpenAILLM <openaillm>` and :ref:`VertexAILLM <vertexaillm>`). Using ``use_structured_output=True`` with other providers will raise a ``ValueError``. Do not pass ``response_format`` in constructor parameters (``model_params`` or ``generation_config``); the extractor automatically sets it when calling ``invoke()``.
953996

954997

955998
Error Behaviour

0 commit comments

Comments
 (0)