Refa: add more logs to KG. (#8889)

### What problem does this PR solve?


### Type of change

- [x] Refactoring
This commit is contained in:
Kevin Hu
2025-07-17 14:43:08 +08:00
committed by GitHub
parent a422367a40
commit 729e6098f9
3 changed files with 35 additions and 9 deletions

View File

@ -39,6 +39,14 @@ from rag.nlp import rag_tokenizer, search
from rag.utils.redis_conn import RedisDistributedLock
@timeout(30, 2)
async def _is_strong_enough(chat_model, embedding_model):
_ = await trio.to_thread.run_sync(lambda: embedding_model.encode(["Are you strong enough!?"]))
res = await trio.to_thread.run_sync(lambda: chat_model.chat("Nothing special.", [{"role":"user", "content": "Are you strong enough!?"}]))
if res.find("**ERROR**") >= 0:
raise Exception(res)
async def run_graphrag(
row: dict,
language,
@ -48,6 +56,11 @@ async def run_graphrag(
embedding_model,
callback,
):
# Pressure test for GraphRAG task
async with trio.open_nursery() as nursery:
for _ in range(12):
nursery.start_soon(_is_strong_enough, chat_model, embedding_model)
start = trio.current_time()
tenant_id, kb_id, doc_id = row["tenant_id"], str(row["kb_id"]), row["doc_id"]
chunks = []
@ -65,7 +78,7 @@ async def run_graphrag(
doc_id,
chunks,
language,
row["kb_parser_config"]["graphrag"]["entity_types"],
row["kb_parser_config"]["graphrag"].get("entity_types", []),
chat_model,
embedding_model,
callback,