From e078ab7103d10b982895d4347e8581875971b16a Mon Sep 17 00:00:00 2001 From: yangdx Date: Wed, 10 Sep 2025 11:31:48 +0800 Subject: [PATCH] Fix cache handling and context return logic for query parameters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Skip cache when only_need_prompt is set • Update only_need_context condition logic • Prevent cache bypass in prompt-only mode --- lightrag/operate.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lightrag/operate.py b/lightrag/operate.py index 6635ef94..808c1c15 100644 --- a/lightrag/operate.py +++ b/lightrag/operate.py @@ -2137,7 +2137,8 @@ async def kg_query( hashing_kv, args_hash, query, query_param.mode, cache_type="query" ) if cached_response is not None: - return cached_response + if not query_param.only_need_context and not query_param.only_need_prompt: + return cached_response hl_keywords, ll_keywords = await get_keywords_from_query( query, query_param, global_config, hashing_kv @@ -2174,7 +2175,7 @@ async def kg_query( chunks_vdb, ) - if query_param.only_need_context: + if query_param.only_need_context and not query_param.only_need_prompt: return context if context is not None else PROMPTS["fail_response"] if context is None: return PROMPTS["fail_response"] @@ -3944,7 +3945,8 @@ async def naive_query( hashing_kv, args_hash, query, query_param.mode, cache_type="query" ) if cached_response is not None: - return cached_response + if not query_param.only_need_context and not query_param.only_need_prompt: + return cached_response tokenizer: Tokenizer = global_config["tokenizer"] @@ -4028,8 +4030,8 @@ async def naive_query( } ) - text_units_str = json.dumps(text_units_context, ensure_ascii=False) - if query_param.only_need_context: + + if query_param.only_need_context and not query_param.only_need_prompt: return f""" ---Document Chunks(DC)---