diff --git a/dsLightRag/Math/kv_store_llm_response_cache.json b/dsLightRag/Math/kv_store_llm_response_cache.json new file mode 100644 index 00000000..40d24ae5 --- /dev/null +++ b/dsLightRag/Math/kv_store_llm_response_cache.json @@ -0,0 +1,14 @@ +{ + "hybrid": { + "6a2a99a3bd4688b079a45fedbd1cd493": { + "return": "{\"high_level_keywords\": [\"\\u5c0f\\u5b66\\u6570\\u5b66\", \"\\u6559\\u80b2\\u6a21\\u578b\", \"\\u6570\\u5b66\\u6982\\u5ff5\"], \"low_level_keywords\": [\"\\u52a0\\u51cf\\u6cd5\\u6a21\\u578b\", \"\\u51e0\\u4f55\\u56fe\\u5f62\", \"\\u5206\\u6570\\u6a21\\u578b\", \"\\u5e94\\u7528\\u9898\", \"\\u6570\\u8f74\"]}", + "cache_type": "keywords", + "chunk_id": null, + "embedding": null, + "embedding_shape": null, + "embedding_min": null, + "embedding_max": null, + "original_prompt": "小学数学中有哪些模型?" + } + } +} \ No newline at end of file diff --git a/dsLightRag/Start.py b/dsLightRag/Start.py index e05af5e5..2f925b2f 100644 --- a/dsLightRag/Start.py +++ b/dsLightRag/Start.py @@ -55,22 +55,29 @@ app.mount("/static", StaticFiles(directory="Static"), name="static") async def rag(request: fastapi.Request): data = await request.json() query = data.get('query', '') - working_dir = "./Math" # 使用与T2_Query.py相同的目录 + working_dir = "./Test/Math" # 使用与T2_Query.py相同的目录 async def generate_response_stream(): rag = None try: + logger.info(f"Initializing RAG with working_dir: {working_dir}") rag = await initialize_rag(working_dir) + logger.info("RAG initialized successfully") + resp = await rag.aquery( query, param=QueryParam(mode="hybrid", stream=True), ) + logger.info("Query execution started") - if inspect.isasyncgen(resp): - async for chunk in resp: + async for chunk in resp: + if not chunk: # Skip empty chunks + continue + try: yield f"data: {json.dumps({'reply': chunk}, ensure_ascii=False)}\n\n" - else: - yield f"data: {json.dumps({'reply': resp}, ensure_ascii=False)}\n\n" + except Exception as e: + logger.error(f"Error processing chunk: {e}") + yield f"data: {json.dumps({'error': str(e)})}\n\n" except Exception as e: yield f"data: {json.dumps({'error': str(e)})}\n\n" finally: diff --git a/dsLightRag/Test/Math/kv_store_llm_response_cache.json b/dsLightRag/Test/Math/kv_store_llm_response_cache.json index b32487e6..8e17dbe3 100644 --- a/dsLightRag/Test/Math/kv_store_llm_response_cache.json +++ b/dsLightRag/Test/Math/kv_store_llm_response_cache.json @@ -2531,6 +2531,16 @@ "embedding_min": null, "embedding_max": null, "original_prompt": "小学数学中常用的公式有哪些?" + }, + "6a2a99a3bd4688b079a45fedbd1cd493": { + "return": "{\"high_level_keywords\": [\"\\u5c0f\\u5b66\\u6570\\u5b66\", \"\\u6570\\u5b66\\u6a21\\u578b\", \"\\u6559\\u80b2\\u65b9\\u6cd5\"], \"low_level_keywords\": [\"\\u52a0\\u51cf\\u6cd5\\u6a21\\u578b\", \"\\u51e0\\u4f55\\u56fe\\u5f62\", \"\\u5206\\u6570\\u6a21\\u578b\", \"\\u5e94\\u7528\\u9898\", \"\\u6570\\u8f74\"]}", + "cache_type": "keywords", + "chunk_id": null, + "embedding": null, + "embedding_shape": null, + "embedding_min": null, + "embedding_max": null, + "original_prompt": "小学数学中有哪些模型?" } } } \ No newline at end of file