graphragzen.prompt_tuning.entities.create_entity_extraction_prompt

graphragzen.prompt_tuning.entities.create_entity_extraction_prompt(llm, entity_categories, entity_relationship_examples, prompt_template='\nYou are an intelligent assistant that helps a human to analyze the information in a text document and extract a knowledg graph from it. A knowledge graph consists of nodes and their edges (relationships between the nodes in the graph).\n\n-Goal-\nGiven a text document that is potentially relevant to this activity and a list of categories, identify all nodes of those categories from the text and all edges among the identified nodes.\n\n-Steps-\n1. Identify all nodes. For each identified node, extract the following information:\n- name: Name of the node, capitalized\n- category: One of the following categories: [{entity_categories}]\n- description: Comprehensive description of the node\'s attributes and activities\nFormat each node as a JSON with the following format:\n{{"type": "node", "name": <name>, "category": <category>, "description": <description>}}\n\n2. From the nodes identified in step 1, identify all pairs of (source_node, target_node) that are *clearly related* to each other.\nFor each edge, extract the following information:\n- source: name of the source node, as identified in step 1\n- target: name of the target node, as identified in step 1\n- description: explanation as to why you think the source node and the target node are related to each other\n- weight: a numeric score indicating strength of the edge between the source node and target node\nFormat each edge as a JSON with the following format:\n{{"type": "edge", "source": <source>, "target": <target>, "description": <description>, "weight": <weight>}}\n\n3. Return output in English as a single list of all JSON entities and relationships identified in steps 1 and 2.\n\n######################\n-Examples-\n######################\n{examples}\n\n#############################\n-Real Data-\n######################\nentity_categories: [{entity_categories}]\ntext: {{input_text}}\n######################\noutput:', prompt_max_tokens=3000)[source]

Create a prompt for entity extraction.

This does not use an LLM but simply formats a string using the inputs and makes sure the resulting prompt is not too large.

Parameters:
  • llm (LLM)

  • entity_categories (List[str]) – The categories of entities to extract (e.g. [‘person’, ‘profession’, ‘location’])

  • entity_relationship_examples (List[str]) – Generated by generate_entity_relationship_examples

  • prompt_template (str, optional) – The template that will be formatted to the final prompt. Defaults to graphragzen.prompts.prompt_tuning.entity_extraction.ENTITY_EXTRACTION_PROMPT

  • prompt_max_tokens (int, optional) – Maximum number of tokens the final prompt is allowed to be. Defaults to 3000

Returns:

Prompt to use for entity extraction

Return type:

str