Skip to content

Commit 63a34bb

Browse files
committed
allow setting the engine
1 parent 6a96892 commit 63a34bb

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

libs/community/langchain_community/graph_vectorstores/visualize.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ def _split_prefix(s: str, max_chars: int = 50) -> str:
3636

3737
def render_graphviz(
3838
documents: Iterable[Document],
39+
engine: Optional[str] = None,
3940
node_color: Optional[str] = None,
4041
node_colors: Optional[Dict[str, Optional[str]]] = {},
4142
) -> "graphviz.Digraph":
4243
"""Render a collection of GraphVectorStore documents to GraphViz format.
4344
4445
Args:
4546
documents: The documents to render.
47+
engine: GraphViz layout engine to use. `None` uses the default.
4648
node_color: General node color. Defaults to `white`.
4749
node_colors: Dictionary specifying colors of specific nodes. Useful for
4850
emphasizing nodes that were selected by MMR, or differ from other
@@ -78,7 +80,7 @@ def render_graphviz(
7880

7981
tags = set()
8082

81-
graph = graphviz.Digraph()
83+
graph = graphviz.Digraph(engine=engine)
8284
graph.attr(rankdir="LR")
8385
graph.attr("node", style="filled")
8486
for document in documents:

libs/community/tests/unit_tests/graph_vectorstores/test_visualize.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def test_visualize_simple_graph():
4949
"}\n"
5050
)
5151

52+
assert render_graphviz([doc1, doc2], engine="fdp").engine == "fdp"
53+
5254
assert render_graphviz([doc1, doc2], node_colors={"a": "gold"}).source == (
5355
"digraph {\n"
5456
"\trankdir=LR\n"

0 commit comments

Comments
 (0)