Draws a Knowledge Graph as Holoviews/Bokeh interactive plot.
We first convert the entity collection to a NetworkX Graph, and then convert it to a Holoviews Graph via their API.
The default layout chosen is the spring_layout.
This maximizes the distance between nodes. As our entities have a type field,
however, another good layout choice might be
layout=nx.multipartite_layout, nx_opts["subset_key"]= "type"
as multipartite layout positions nodes in straight lines by subset key.
NOTE: Requires optional-dependency "viz", i.e. pip install "langchain-mongodb[viz]".
You can save the view as any HoloViews object with .save.
The type will be inferred from the filename's suffix,
(e.g., hv.save(graph, "graph.html")) or by clicking the download widget
on the Bokeh plot from a Jupyter notebook.
view(
self,
layout: Optional[Callable] = None,
nx_opts: Optional[dict] = None,
json_opts: Optional[dict] = None,
edge_opts: Optional[dict] = None,
node_opts: Optional[dict] = None,
**kwargs: Any = {}
) -> holoviews.GraphReturns: holoviews.Graph <https://holoviews.org/user_guide/Network_Graphs.html>_
| Name | Type | Description |
|---|---|---|
layout | Optional[Callable] | Default: None
|
nx_opts | Optional[dict] | Default: NoneKeyword arguments for to_networkx function. |
json_opts | Optional[dict] | Default: NoneKeyword arguments for printing of node attributes and types. |
edge_opts | Optional[dict] | Default: NoneKeyword arguments to draw edges. |
node_opts | Optional[dict] | Default: NoneKeyword arguments to draw nodes. |
**kwargs | Any | Default: {}Keyword arguments available for compatibility. |