From 2f06f851c33a0403ffba22c0d61d3e7afe39a38f Mon Sep 17 00:00:00 2001 From: yangdx Date: Sun, 21 Sep 2025 22:48:48 +0800 Subject: [PATCH] Enhance citation format with merged references and clearer guidelines MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Increase max references from 5 to 8 - Merge citations by file_path - Remove inline citations from body - Add reference section examples - Update citation prefixes (KG→EN, RE) --- lightrag/prompt.py | 51 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/lightrag/prompt.py b/lightrag/prompt.py index 75585553..9dd7d279 100644 --- a/lightrag/prompt.py +++ b/lightrag/prompt.py @@ -225,6 +225,7 @@ Consider the conversation history if provided to maintain conversational flow an - Scrutinize the `Source Data`(both Knowledge Graph and Document Chunks). Identify and extract all pieces of information that are directly relevant to answering the user query. - Weave the extracted facts into a coherent and logical response. Your own knowledge must ONLY be used to formulate fluent sentences and connect ideas, NOT to introduce any external information. - Review the draft to ensure it strictly adheres to all `Formatting & Language` rules below before generating the final response. + - Append a reference section at the end of the response; merge citations that share the same file_path into one reference item. 2. **Content & Grounding:** - Strictly adhere to the provided context from the `Source Data`; DO NOT invent, assume, or infer any information not explicitly stated. @@ -234,16 +235,31 @@ Consider the conversation history if provided to maintain conversational flow an - The response MUST be in the same language as the user query. - Use Markdown for clear formatting (e.g., headings, bold, lists). - Target format and length: {response_type} + - Append a reference section at the end of the response. + Generate a Only output citation information in the references section + The main body of the response should exclude inline citations; all references should be listed exclusively in the references section at the end. -4. **Citation Format:** - - All citations should be consolidated in the References section at the end of the response. Do not include citation information within the main body of the answer. +4. **Reference/Citation Format:** + - Append a reference section at the end of the response. + - Provide a maximum of 8 unique and most relevant references, and list each citation on a separate line. + - Merge citations that share the same file_path into one reference item, disregarding their distinct IDs. + - Preserve the original file_path language in citation - The References section should be under a `### References` heading. - Output the citation in the following formats: - - For a Knowledge Graph Entity: `[KG] ` - - For a Knowledge Graph Relationship: `[KG] ~ ` - - For a Document Chunk: `[DC] ` - - List each citation on a separate new line. - - Provide a maximum of 5 unique and most relevant references. Each entity, relationship, or document name must appear only once in the "References" section. + - For a Knowledge Graph Entity: `[EN] ` + - For a Knowledge Graph Relationship: `RE] ~ ` + - For a Document Chunk: `[DC] ` + +5. **Example of Section:** +``` +### References +- [EN] LightRAG +- [EN] Dual-Level Retrieval System +- [RE] LightRAG ~ GraphRAG +- [DC1] Simple and Fast RAG.pdf +- [DC2] LightRAG Simple and Fast Alternative to GraphRAG for Legal Doc Analysis.md +- [DC3] Microsoft GraphRAG Technology Summary.md +``` ---Source Data--- Knowledge Graph and Document Chunks: @@ -266,6 +282,7 @@ Consider the conversation history if provided to maintain conversational flow an - Scrutinize the `Source Data`(Document Chunks). Identify and extract all pieces of information that are directly relevant to answering the user query. - Weave the extracted facts into a coherent and logical response. Your own knowledge must ONLY be used to formulate fluent sentences and connect ideas, NOT to introduce any external information. - Review the draft to ensure it strictly adheres to all `Formatting & Language` rules below before generating the final response. + - Append a reference section at the end of the response; merge citations that share the same file_path into one reference item. 2. **Content & Grounding:** - Strictly adhere to the provided context from the `Source Data`; DO NOT invent, assume, or infer any information not explicitly stated. @@ -275,13 +292,23 @@ Consider the conversation history if provided to maintain conversational flow an - The response MUST be in the same language as the user query. - Use Markdown for clear formatting (e.g., headings, bold, lists). - Target format and length: {response_type} + - The main body of the response should exclude inline citations; all references should be listed exclusively in the references section at the end. -4. **Citation Format:** - - All citations should be consolidated in the References section at the end of the response. Do not include citation information within the main body of the answer. +4. **Reference/Citation Format:** + - Append a reference section at the end of the response. + - Provide a maximum of 8 unique and most relevant references, and list each citation on a separate line. + - Merge citations that share the same file_path into one reference item, disregarding their distinct IDs. + - Preserve the original file_path language in citation - The References section should be under a `### References` heading. - - Output the citation in the following format: `[DC] ` - - List each citation on a separate new line. - - Provide a maximum of 5 unique and most relevant references. Each entity, relationship, or document name must appear only once in the "References" section. + - Output the citation in the following format: `[DC] ` + +5. **Example of Section:** +``` +### References +- [DC1] Simple and Fast RAG.pdf +- [DC2] LightRAG Simple and Fast Alternative to GraphRAG for Legal Doc Analysis.md +- [DC3] Microsoft GraphRAG Technology Summary.md +``` ---Source Data--- Document Chunks: