Skip to content

Commit 1401f45

Browse files
authored
Function to visualize a GraphSchema object or dict (#398)
* Function to visualize a GraphSchema object or dict * Update lock file
1 parent 23c9ae3 commit 1401f45

File tree

9 files changed

+339
-45
lines changed

9 files changed

+339
-45
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66

77
- Added a `ToolsRetriever` retriever that uses an LLM to decide on what tools to use to find the relevant data.
88
- Added `convert_to_tool` method to the `Retriever` interface to convert a Retriever to a Tool so it can be used within the ToolsRetriever. This is useful when you might want to have both a VectorRetriever and a Text2CypherRetreiver as a fallback.
9+
- Added `schema_visualization` function to visualize a graph schema using neo4j-viz.
910

1011
### Fixed
1112

1213
- Fixed an edge case where the LLM can output a property with type 'map', which was causing errors during import as it is not a valid property type in Neo4j.
1314

15+
1416
## 1.9.1
1517

1618
### Fixed
@@ -30,7 +32,6 @@
3032

3133
- Added automatic rate limiting with retry logic and exponential backoff for all LLM providers using tenacity. The `RateLimitHandler` interface allows for custom rate limiting strategies, including the ability to disable rate limiting entirely.
3234

33-
3435
## 1.8.0
3536

3637
### Added

docs/source/api.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ SchemaFromTextExtractor
8383
.. autoclass:: neo4j_graphrag.experimental.components.schema.SchemaFromTextExtractor
8484
:members: run
8585

86+
schema_visualization
87+
--------------------
88+
89+
.. autofunction:: neo4j_graphrag.experimental.utils.schema.schema_visualization
90+
91+
8692
EntityRelationExtractor
8793
=======================
8894

docs/source/user_guide_kg_builder.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,28 @@ You can also save and reload the extracted schema:
852852
restored_schema = GraphSchema.from_file("my_schema.json") # or my_schema.yaml
853853
854854
855+
Schema Visualization
856+
--------------------
857+
858+
It is possible to visualize a validated schema or a schema dict using the `schema_visualization` function. This function
859+
returns a VisualizationGraph object (from the neo4j-viz package) that can visualized like this:
860+
861+
.. code:: python
862+
863+
from neo4j_graphrag.experimental.utils.schema import schema_visualization
864+
865+
VG = schema_visualization(schema)
866+
html = VG.render()
867+
868+
# in Jupyter:
869+
display(html)
870+
871+
# to save the generated HTML
872+
with open("my_schema.html", "w") as f:
873+
f.write(html.data)
874+
875+
876+
855877
Entity and Relation Extractor
856878
=============================
857879

poetry.lock

Lines changed: 58 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pyyaml = "^6.0.2"
3838
types-pyyaml = "^6.0.12.20240917"
3939
# optional deps
4040
langchain-text-splitters = {version = "^0.3.0", optional = true }
41-
neo4j-viz = {version = "^0.2.2", optional = true }
41+
neo4j-viz = {version = "^0.4.2", optional = true }
4242
weaviate-client = {version = "^4.6.1", optional = true }
4343
pinecone-client = {version = "^4.1.0", optional = true }
4444
google-cloud-aiplatform = {version = "^1.66.0", optional = true }
@@ -74,7 +74,6 @@ sphinx = { version = "^7.2.6", python = "^3.9" }
7474
langchain-openai = {version = "^0.2.2", optional = true }
7575
langchain-huggingface = {version = "^0.1.0", optional = true }
7676
enum-tools = {extras = ["sphinx"], version = "^0.12.0"}
77-
neo4j-viz = "^0.2.2"
7877

7978
[tool.poetry.extras]
8079
weaviate = ["weaviate-client"]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright (c) "Neo4j"
2+
# Neo4j Sweden AB [https://neo4j.com]
3+
# #
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# #
8+
# https://www.apache.org/licenses/LICENSE-2.0
9+
# #
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.

0 commit comments

Comments
 (0)