graphragzen.merge.merge_features.merge_graph_features

graphragzen.merge.merge_features.merge_graph_features(graph, llm, feature, prompt=MergeFeaturesPromptConfig(prompt='\nYou are a helpful assistant responsible for generating a comprehensive summary of the data provided below.\nGiven one or two entities, and a list of descriptions, all related to the same entity or group of entities.\nPlease concatenate all of these into a single, comprehensive description. Make sure to include information collected from all the descriptions.\nIf the provided descriptions are contradictory, please resolve the contradictions and provide a single, coherent summary.\nMake sure it is written in third person, and include the entity names so we the have full context.\n\n#######\n-Data-\nEntities: {entity_name}\nDescription List: {description_list}\n#######\nOutput:\n', formatting=MergeFeaturesPromptFormatting(entity_name=None, description_list=None)), how='LLM', feature_delimiter='\n', max_input_tokens=4000, max_output_tokens=500)[source]

For each node and edge, the feature is extracted, presumed it’s a list, merged, and written back to the node or edge.

Parameters:
  • graph (nx.Graph) – With edges and nodes expected to have the feature ‘description’. The descriptions are expected to be delimited by Kwargs[“feature_delimiter”]

  • llm (LLM, optional) – Only used if how is set to ‘LLM’. Dedaults to None.

  • feature (str) – The feature attached to a graph entity (node or edge) to merge.

  • prompt (MergeFeaturesPromptConfig, optional) – Will be formatted with the feature to send to the LLM. Only used if how is set to ‘LLM’. See graphragzen.typing.MergeFeaturesPromptConfig. Defaults to MergeFeaturesPromptConfig.

  • how (Literal['LLM', 'count', 'mean'], optional) – ‘LLM’ summarizes the features. ‘count’ takes the feature that occurs most. ‘mean’ takes the mean of the feature. Defaults to ‘LLM’.

  • feature_delimiter (str, optional) – During entity extraction the same node or edge can be found multiple times, and features were concatenated using this delimiter. We will make a list of descriptions by splitting on this delimiter. Defaults to ‘n’.

  • max_input_tokens (int, optional) – Only used when how==’LLM’. Maximum input tokens until a summary is made. Remaining descriptions will be appended to the summary until max_input_tokens is reached again or no descriptions are left. Defaults to 4000.

  • max_output_tokens (int, optional) – Only used when how==’LLM’. Maximum number of tokens a summary can have. Defaults to 500.

Returns:

nx.Graph

Return type:

Graph