mirror of
https://github.com/microsoft/graphrag.git
synced 2026-01-14 09:07:20 +08:00
fix json parsing logic and warning message (#833)
* fix json parsing logic and warning message * amended warning message --------- Co-authored-by: Alonso Guevara <alonsog@microsoft.com>
This commit is contained in:
parent
7b656af50c
commit
482246528d
@ -0,0 +1,4 @@
|
||||
{
|
||||
"type": "patch",
|
||||
"description": "Change json parsing error in the map step of global search to warning"
|
||||
}
|
||||
@ -192,7 +192,9 @@ class GlobalSearch(BaseSearch):
|
||||
# parse search response json
|
||||
processed_response = self.parse_search_response(search_response)
|
||||
except ValueError:
|
||||
log.exception("Error parsing search response json")
|
||||
log.warning(
|
||||
"Warning: Error parsing search response json - skipping this batch"
|
||||
)
|
||||
processed_response = []
|
||||
|
||||
return SearchResult(
|
||||
@ -230,15 +232,19 @@ class GlobalSearch(BaseSearch):
|
||||
"""
|
||||
search_response, _j = try_parse_json_object(search_response)
|
||||
if _j == {}:
|
||||
return [{"answer": "not avaliable", "score": 0}]
|
||||
return [{"answer": "", "score": 0}]
|
||||
|
||||
parsed_elements = json.loads(search_response).get("points")
|
||||
if not parsed_elements or not isinstance(parsed_elements, list):
|
||||
return [{"answer": "", "score": 0}]
|
||||
|
||||
parsed_elements = json.loads(search_response)["points"]
|
||||
return [
|
||||
{
|
||||
"answer": element["description"],
|
||||
"score": int(element["score"]),
|
||||
}
|
||||
for element in parsed_elements
|
||||
if "description" in element and "score" in element
|
||||
]
|
||||
|
||||
async def _reduce_response(
|
||||
@ -277,6 +283,9 @@ class GlobalSearch(BaseSearch):
|
||||
|
||||
if len(filtered_key_points) == 0 and not self.allow_general_knowledge:
|
||||
# return no data answer if no key points are found
|
||||
log.warning(
|
||||
"Warning: All map responses have score 0 (i.e., no relevant information found from the dataset), returning a canned 'I do not know' answer. You can try enabling `allow_general_knowledge` to encourage the LLM to incorporate relevant general knowledge, at the risk of increasing hallucinations."
|
||||
)
|
||||
return SearchResult(
|
||||
response=NO_DATA_ANSWER,
|
||||
context_data="",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user