graphragzen.merge.merge_nodes.merge_similar_graph_nodes
- graphragzen.merge.merge_nodes.merge_similar_graph_nodes(graph, embedding_model, merge_report=None, extra_features_to_compare=['description'], min_similarity=0.95, filter_functions=[<function contain_date>, <function isempty>], feature_delimiter='\n', dry_run=False)[source]
Merge nodes in a graph that are very similar to each other, using text embeddings of the node names and selected features.
- Parameters:
graph (nx.Graph) – The graph to check for similar nodes.
embedding_model (BaseEmbedder) – The model to embed text features of the nodes.
merge_report (Optional[pd.DataFrame], optional) – If dry_run is set to True this function returns a report stating which nodes would me merged. When supplying this report it will be used to merge nodes, no new similar nodes will be searched. This is usefull if you want to check what nodes will be merges beforehand and make adjustments if necessary. Defaults to None.
extra_features_to_compare (list, optional) – Other than the name of the nodes, which features should be text embedded and compared for similarity. Defaults to [“description”].
min_similarity (float, optional) – The minimum similarity to consider two nodes similar. Defaults to 0.95.
filter_functions (list, optional) – These function determine per node, per feature, if it should be concidered for comparing to other nodes for similarity. When any of these functions, supplied with the node feature, returns True, the feature for this node will not be used to find similar nodes. Defaults to [contain_date, isempty].
feature_delimiter (str, optional) – When nodes are merged features are concatenated using this delimiter. Defaults to ‘n’.
dry_run (bool, optional) – If True, will return the original, unmodified graph, with a report stating which nodes would me merged if dry_run was False. Defaults to False.
- Returns:
(graph, report stating which nodes were merged)
- Return type:
Tuple[nx.graph, pd.DataFrame]