[docs]@beta()defrender_graphviz(documents:Iterable[Document],engine:Optional[str]=None,node_color:Optional[str]=None,node_colors:Optional[Dict[str,Optional[str]]]=None,skip_tags:Iterable[Tuple[str,str]]=(),)->"graphviz.Digraph":"""Render a collection of GraphVectorStore documents to GraphViz format. Args: documents: The documents to render. engine: GraphViz layout engine to use. `None` uses the default. node_color: Default node color. node_colors: Dictionary specifying colors of specific nodes. Useful for emphasizing nodes that were selected by MMR, or differ from other results. skip_tags: Set of tags to skip when rendering the graph. Specified as tuples containing the kind and tag. Returns: The "graphviz.Digraph" representing the nodes. May be printed to source, or rendered using `dot`. Note: To render the generated DOT source code, you also need to install Graphviz_ (`download page <https://www.graphviz.org/download/>`_, `archived versions <https://www2.graphviz.org/Archive/stable/>`_, `installation procedure for Windows <https://forum.graphviz.org/t/new-simplified-installation-procedure-on-windows/224>`_). """ifnode_colorsisNone:node_colors={}try:importgraphvizexcept(ImportError,ModuleNotFoundError):raiseImportError("Could not import graphviz python package. ""Please install it with `pip install graphviz`.")graph=graphviz.Digraph(engine=engine)graph.attr(rankdir="LR")graph.attr("node",style="filled")skip_tags=set(skip_tags)tags:dict[Tuple[str,str],str]={}fordocumentindocuments:id=document.idifidisNone:raiseValueError(f"Illegal graph document without ID: {document}")escaped_id=_escape_id(id)color=node_colors[id]ifidinnode_colorselsenode_colornode_label="\n".join([graphviz.escape(id),graphviz.escape(_split_prefix(document.page_content)),])graph.node(escaped_id,label=node_label,shape="note",fillcolor=color,tooltip=graphviz.escape(document.page_content),)forlinkinget_links(document):tag_key=(link.kind,link.tag)iftag_keyinskip_tags:continuetag_id=tags.get(tag_key)iftag_idisNone:tag_id=f"tag_{len(tags)}"tags[tag_key]=tag_idgraph.node(tag_id,label=graphviz.escape(f"{link.kind}:{link.tag}"))graph.edge(escaped_id,tag_id,dir=_EDGE_DIRECTION[link.direction])returngraph