fix: handle empty SPOKE API response in get_context_using_spoke_api#47
Open
octo-patch wants to merge 1 commit intoBaranziniLab:mainfrom
Open
fix: handle empty SPOKE API response in get_context_using_spoke_api#47octo-patch wants to merge 1 commit intoBaranziniLab:mainfrom
octo-patch wants to merge 1 commit intoBaranziniLab:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #42
Problem
When the SPOKE Knowledge Graph API returns an empty list for a node (e.g.
neurofibromatosis 2which may have been removed in a KG update),get_context_using_spoke_apiraises anIndexErrorat line 128:This crashes because
node_context[0]is accessed without checking whethernode_contextis empty.Solution
Wrap the identifier-appending line in a guard that only executes when
node_contextis non-empty:When the API returns no results for a node, the function now gracefully returns an empty context string and an empty DataFrame instead of crashing.
Testing
Added unit tests in
kg_rag/test/test_spoke_api_empty_response.pythat mock the SPOKE API:test_empty_node_context_does_not_raise— verifies that an empty API response no longer raisesIndexError, and that the function returns an empty context and empty DataFrame.test_non_empty_node_context_includes_identifier— verifies that normal (non-empty) API responses still include the identifier information in the returned context.Both tests pass with the fix applied.