Skip to content

Commit 7814c21

Browse files
authored
Replace pygraphviz with neo4j-viz for graph visualization (neo4j#306)
1 parent 85eaa5b commit 7814c21

File tree

13 files changed

+1397
-1006
lines changed

13 files changed

+1397
-1006
lines changed

.github/workflows/pr-e2e-tests.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ jobs:
4949
- 6333:6333
5050

5151
steps:
52-
- name: Install graphviz package
53-
run: sudo apt install graphviz graphviz-dev
5452
- name: Check out repository code
5553
uses: actions/checkout@v4
5654
- name: Docker Prune

.github/workflows/pr.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ jobs:
88
matrix:
99
python-version: [ '3.9', '3.10', '3.11', '3.12' ]
1010
steps:
11-
- name: Install graphviz package
12-
run: sudo apt install graphviz graphviz-dev
1311
- name: Check out repository code
1412
uses: actions/checkout@v4
1513
- name: Set up Python ${{ matrix.python-version }}

.github/workflows/scheduled-e2e-tests.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ jobs:
5757
- 6333:6333
5858

5959
steps:
60-
- name: Install graphviz package
61-
run: sudo apt install graphviz graphviz-dev
6260
- name: Check out repository code
6361
uses: actions/checkout@v4
6462
- name: Docker Prune

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
### Changed
1414

1515
- Improved log output readability in Retrievers and GraphRAG and added embedded vector to retriever result metadata for debugging.
16+
- Switched from pygraphviz to neo4j-viz
17+
- Renders interactive graph now on HTML instead of PNG
18+
- Removed `get_pygraphviz_graph` method
1619

1720
### Fixed
1821

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ the extra dependencies described below:
5959
- **pinecone**: store vectors in Pinecone
6060
- **qdrant**: store vectors in Qdrant
6161
- **experimental**: experimental features mainly related to the Knowledge Graph creation pipelines.
62-
- Warning: this dependency group requires `pygraphviz`. See below for installation instructions.
6362

6463

6564
Install package with optional dependencies with (for instance):
@@ -68,11 +67,6 @@ Install package with optional dependencies with (for instance):
6867
pip install "neo4j-graphrag[openai]"
6968
```
7069

71-
#### pygraphviz
72-
73-
`pygraphviz` is used for visualizing pipelines.
74-
Installation instructions can be found [here](https://pygraphviz.github.io/documentation/stable/install.html).
75-
7670
## 💻 Example Usage
7771

7872
The scripts below demonstrate how to get started with the package and make use of its key features.

docs/source/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ List of extra dependencies:
9898
- **pinecone**: store vectors in Pinecone
9999
- **qdrant**: store vectors in Qdrant
100100
- **experimental**: experimental features mainly from the Knowledge Graph creation pipelines.
101-
- Warning: this requires `pygraphviz`. Installation instructions can be found `here <https://pygraphviz.github.io/documentation/stable/install.html>`_.
102101
- nlp:
103102
- **spaCy**: load spaCy trained models for nlp pipelines, used by `SpaCySemanticMatchResolver` component from the Knowledge Graph creation pipelines.
104103
- fuzzy-matching:

docs/source/user_guide_pipeline.rst

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,25 +111,26 @@ Pipelines can be visualized using the `draw` method:
111111
pipe = Pipeline()
112112
# ... define components and connections
113113
114-
pipe.draw("pipeline.png")
114+
pipe.draw("pipeline.html")
115115
116-
Here is an example pipeline rendering:
116+
Here is an example pipeline rendering as an interactive HTML visualization:
117117

118-
.. image:: images/pipeline_no_unused_outputs.png
119-
:alt: Pipeline visualisation with hidden outputs if unused
118+
.. code:: python
120119
120+
# To view the visualization in a browser
121+
import webbrowser
122+
webbrowser.open("pipeline.html")
121123
122124
By default, output fields which are not mapped to any component are hidden. They
123-
can be added to the canvas by setting `hide_unused_outputs` to `False`:
125+
can be added to the visualization by setting `hide_unused_outputs` to `False`:
124126

125127
.. code:: python
126128
127-
pipe.draw("pipeline.png", hide_unused_outputs=False)
128-
129-
Here is an example of final result:
130-
131-
.. image:: images/pipeline_full.png
132-
:alt: Pipeline visualisation
129+
pipe.draw("pipeline_full.html", hide_unused_outputs=False)
130+
131+
# To view the full visualization in a browser
132+
import webbrowser
133+
webbrowser.open("pipeline_full.html")
133134
134135
135136
************************

examples/customize/build_graph/pipeline/visualization.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,5 @@ async def run(self, number: IntDataModel) -> IntDataModel:
5454
pipe.connect("times_two", "addition", {"a": "times_two.value"})
5555
pipe.connect("times_ten", "addition", {"b": "times_ten.value"})
5656
pipe.connect("addition", "save", {"number": "addition"})
57-
pipe.draw("graph.png")
58-
pipe.draw("graph_full.png", hide_unused_outputs=False)
57+
pipe.draw("graph.html")
58+
pipe.draw("graph_full.html", hide_unused_outputs=False)

poetry.lock

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

pyproject.toml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +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-
pygraphviz = [
42-
{version = "^1.13.0", python = ">=3.10,<4.0.0", optional = true},
43-
{version = "^1.0.0", python = "<3.10", optional = true}
44-
]
41+
neo4j-viz = {version = "^0.2.2", optional = true }
4542
weaviate-client = {version = "^4.6.1", optional = true }
4643
pinecone-client = {version = "^4.1.0", optional = true }
4744
google-cloud-aiplatform = {version = "^1.66.0", optional = true }
@@ -68,6 +65,7 @@ sphinx = { version = "^7.2.6", python = "^3.9" }
6865
langchain-openai = {version = "^0.2.2", optional = true }
6966
langchain-huggingface = {version = "^0.1.0", optional = true }
7067
enum-tools = {extras = ["sphinx"], version = "^0.12.0"}
68+
neo4j-viz = "^0.2.2"
7169

7270
[tool.poetry.extras]
7371
weaviate = ["weaviate-client"]
@@ -79,9 +77,9 @@ ollama = ["ollama"]
7977
openai = ["openai"]
8078
mistralai = ["mistralai"]
8179
qdrant = ["qdrant-client"]
82-
kg_creation_tools = ["pygraphviz"]
80+
kg_creation_tools = ["neo4j-viz"]
8381
sentence-transformers = ["sentence-transformers"]
84-
experimental = ["langchain-text-splitters", "pygraphviz", "llama-index"]
82+
experimental = ["langchain-text-splitters", "neo4j-viz", "llama-index"]
8583
examples = ["langchain-openai", "langchain-huggingface"]
8684
nlp = ["spacy"]
8785
fuzzy-matching = ["rapidfuzz"]

0 commit comments

Comments
 (0)