graphrag
graphrag copied to clipboard
[bug fix] improved json mode in global search
Description
This pull request adds comprehensive unit tests for the GlobalSearch class, enhancing the overall test coverage and reliability of the structured search functionality.
json mode needs "JSON" text in the system prompt
- https://community.openai.com/t/how-do-i-use-the-new-json-mode/475890/50?page=3
- https://platform.openai.com/docs/guides/text-generation/json-mode
So I added
if self.json_mode:
search_prompt += "\nYour response should be in JSON format."
Related Issues
https://github.com/microsoft/graphrag/issues/471
Proposed Changes
- Implement mock classes for LLM and ContextBuilder to isolate tests
- Add tests for parse_search_response method covering various scenarios:
- Valid JSON responses
- Invalid JSON input
- Missing 'points' key
- Invalid point format
- Responses with text prefix
- Non-integer scores
- Include tests for internal methods _map_response_single_batch and _reduce_response
- Add test for the main asearch method
- Ensure proper handling of asynchronous methods in tests
Checklist
- [x] I have tested these changes locally.
- [x] I have reviewed the code changes.
- [ ] I have updated the documentation (if necessary).
- [x] I have added appropriate unit tests.
Additional Notes
Added more tests for search.py
@microsoft-github-policy-service agree