From 5fd7682f1633a9ffe60c9bdf2aa92ed7063873f3 Mon Sep 17 00:00:00 2001 From: yangdx Date: Mon, 1 Sep 2025 01:22:27 +0800 Subject: [PATCH 1/2] Fix LLM output instability for <|> tuple delimiter - Replace <||> with <|> - Replace < | > with <|> - Apply fix in both functions - Handle delimiter variations - Improve parsing reliability --- lightrag/operate.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lightrag/operate.py b/lightrag/operate.py index 1a4b9266..88bb7349 100644 --- a/lightrag/operate.py +++ b/lightrag/operate.py @@ -822,6 +822,13 @@ async def _parse_extraction_result( maybe_nodes = defaultdict(list) maybe_edges = defaultdict(list) + # Preventive fix: when tuple_delimiter is <|>, fix LLM output instability issues + if context_base["tuple_delimiter"] == "<|>": + # 1. Convert <||> to <|> + extraction_result = extraction_result.replace("<||>", "<|>") + # 2. Convert < | > to <|> + extraction_result = extraction_result.replace("< | >", "<|>") + # Parse the extraction result using the same logic as in extract_entities records = split_string_by_multi_markers( extraction_result, @@ -1729,6 +1736,13 @@ async def extract_entities( maybe_nodes = defaultdict(list) maybe_edges = defaultdict(list) + # Preventive fix: when tuple_delimiter is <|>, fix LLM output instability issues + if context_base["tuple_delimiter"] == "<|>": + # 1. Convert <||> to <|> + result = result.replace("<||>", "<|>") + # 2. Convert < | > to <|> + result = result.replace("< | >", "<|>") + records = split_string_by_multi_markers( result, [context_base["record_delimiter"], context_base["completion_delimiter"]], From 30be70991db6567f2525d3f48431c9c33e4d70c8 Mon Sep 17 00:00:00 2001 From: yangdx Date: Mon, 1 Sep 2025 01:23:22 +0800 Subject: [PATCH 2/2] Bump API version to 0211 --- lightrag/api/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lightrag/api/__init__.py b/lightrag/api/__init__.py index 5ae0d6ba..d33fbb77 100644 --- a/lightrag/api/__init__.py +++ b/lightrag/api/__init__.py @@ -1 +1 @@ -__api_version__ = "0210" +__api_version__ = "0211"