graphrag icon indicating copy to clipboard operation
graphrag copied to clipboard

[bug fix] improved json mode in global search

Open jaigouk opened this issue 1 year ago • 1 comments

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

Screenshot 2024-07-15 at 11 02 25

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

jaigouk avatar Jul 14 '24 01:07 jaigouk

@microsoft-github-policy-service agree

jaigouk avatar Jul 14 '24 01:07 jaigouk