错误一:
LightRAG无法回答错误:
INFO:lightrag:kw_prompt result:
{{
"high_level_keywords": ["xxx", "xxx"],
"low_level_keywords": ["xxx", "xxx", "xxx"]
}}
JSON parsing error: Expecting property name enclosed in double quotes: line 1 column 2 (char 1) {{
"high_level_keywords": ["xxx", "xxx"],
"low_level_keywords": ["xxx", "xxx", "xxx"]
}}
Sorry, I'm not able to provide an answer to that question.
是因为LLM响应的格式错误:
{{
"high_level_keywords": ["xxx", "xxx"],
"low_level_keywords": ["xxx", "xxx", ]
}}
正确格式:
{
"high_level_keywords": ["xxx", "xxx"],
"low_level_keywords": ["xxx", "xxx"]
}
解决方法:修改\lightrag\operate.py 477行代码。
python
result = await use_model_func(kw_prompt, keyword_extraction=True)
logger.info("kw_prompt result:")
print("original result:", result)
result = result.replace('{{', '{').replace('}}', '}')
print("rewrite result", result)
错误二:
新环境测试LightRAG时突然出现错误:KeyError: 'Could not automatically map gpt-4o-mini to a tokeniser. Please use `tiktok.get_encoding` to explicitly get the tokeniser you expect.'
解决方法:搜索发现可能跟tiktoken版本问题有关,发现新环境中的tiktoken库版本是0.3.0,而旧环境是0.7.0,重新安装后即可正常运行。
pip install tiktoken==0.7.0
生成的知识图谱中带有很多英文节点:
将\lightrag\prompt.py中PROMPTS["DEFAULT_LANGUAGE"] 的值修改成 "Chinese"。
错误三:
使用API插入文本出错
官方测试curl命令(错误):curl -X POST "http://127.0.0.1:8020/insert_file" -H "Content-Type: application/json" -d '{"file_path": "path/to/your/file.txt"}'
返回错误:{"detail":[{"type":"missing","loc":["body","file"],"msg":"Field required","input":null}]}
正确curl命令:curl -X POST "http://127.0.0.1:8020/insert_file" -H "Content-Type: multipart/form-data" -F "file=@path/to/your/file.txt"
返回成功:{"status":"success","data":null,"message":"File content from test.txt inserted successfully"}