graphragzen.query.get_context.source_texts

graphragzen.query.get_context.source_texts(source_documents, graph, entities, k, id_key='chunk_id', source_key='chunk', feature_delimiter='\n')[source]

Find the top source texts by frequency related to the specified entities.

Parameters:
  • source_documents (pd.DataFrame) – DataFrame containing the source documents with unique identifiers.

  • graph (nx.Graph) – A networkx graph containing nodes and edges.

  • entities (List[dict]) – A list of dictionaries representing entities, with each entity having ‘entity_type’: A string that is either ‘node’ or ‘edge’. ‘entity_name’: A string representing the name of the entity.

  • k (int) – The number of top source texts to return, based on their frequency of occurrence.

  • id_key (str) – The column name in source_documents that represents unique document IDs. Defaults to “chunk_id”.

  • source_key (str) – The column name in source_documents containing the source text. Defaults to “chunk”.

  • feature_delimiter (str) – The delimiter used to split the “source_id” values in the Graph metadata. Default is newline.

Returns:

A list of source texts corresponding to the top most frequent occurring sources.

Return type:

List[str]