diff --git a/lightrag/operate.py b/lightrag/operate.py index 5f824af0..521e8b03 100644 --- a/lightrag/operate.py +++ b/lightrag/operate.py @@ -2832,9 +2832,11 @@ async def extract_entities( cache_keys_collector = [] # Get initial extraction + # Format system prompt once without input_text for OpenAI prompt caching entity_extraction_system_prompt = PROMPTS[ "entity_extraction_system_prompt" - ].format(**{**context_base, "input_text": content}) + ].format(**context_base) + # Format user prompts with input_text for each chunk entity_extraction_user_prompt = PROMPTS["entity_extraction_user_prompt"].format( **{**context_base, "input_text": content} ) diff --git a/lightrag/prompt.py b/lightrag/prompt.py index bf514fe8..cfa5b76f 100644 --- a/lightrag/prompt.py +++ b/lightrag/prompt.py @@ -62,14 +62,16 @@ You are a Knowledge Graph Specialist responsible for extracting entities and rel ---Real Data to be Processed--- Entity_types: [{entity_types}] +""" + +PROMPTS["entity_extraction_user_prompt"] = """---Task--- +Extract entities and relationships from the following input text. + +---Input Text--- Text: ``` {input_text} ``` -""" - -PROMPTS["entity_extraction_user_prompt"] = """---Task--- -Extract entities and relationships from the input text to be processed. ---Instructions--- 1. **Strict Adherence to Format:** Strictly adhere to all format requirements for entity and relationship lists, including output order, field delimiters, and proper noun handling, as specified in the system prompt.