Conversation
…archStrategy This commit adds two new methods to the StepBasedSearchStrategy class: _get_nested_value for extracting values from nested dictionaries using a dot-separated path, and _metadata_matches for checking if a memory object matches a given metadata filter. Additionally, the filtering logic in _filter_memories is updated to utilize the new _metadata_matches method. The scoring calculations in the memory processing logic are also enhanced to avoid division by zero and improve step weight application. Test suite updates include adjustments to metadata filters for improved validation coverage.
…eadability and consistency This commit refactors the StepBasedSearchStrategy class by enhancing the formatting of method signatures and comments for better readability. It also updates the test suite to ensure consistent trailing commas in dictionary entries, improving code style and maintainability. These changes aim to streamline the codebase and enhance the clarity of both the strategy implementation and its associated tests.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the memory filtering and scoring logic by adding nested metadata matching utilities and robust scoring calculations, and it improves test coverage and formatting in the step search test suite.
- Introduces _get_nested_value and _metadata_matches helper methods to enable nested dictionary lookups and list comparisons for metadata filtering.
- Updates _filter_memories and _score_memories to improve accuracy and resiliency (e.g., division by zero checks).
- Fixes formatting issues in test cases (e.g., trailing commas) and refines metadata filter values for realistic scenarios.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| memory/search/strategies/step.py | Added helper methods for nested metadata matching and updated scoring logic with debug logging. |
| validation/search/step/step_test_suite.py | Adjusted test case formatting and updated metadata filters for improved test coverage. |
Comments suppressed due to low confidence (2)
memory/search/strategies/step.py:492
- Similar to the previous instance, 'logger' is used without qualification. To ensure proper debug logging, use 'self.logger' or confirm that 'logger' is defined within the appropriate scope.
logger.debug(f"Memory {memory.get('id', 'unknown')}: step={memory_step}, ref={reference_step}, distance={step_distance}, normalized_distance={normalized_distance}, score={step_score}")
memory/search/strategies/step.py:360
- The usage of 'logger' is not qualified and may be undefined in this scope. Consider using 'self.logger' or ensuring that 'logger' is defined in the module context.
logger.debug(f"No value found for key {key} in memory")
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.
This pull request enhances the memory filtering and scoring logic, improves test coverage, and fixes formatting issues in the test suite. The most significant changes include the addition of a nested metadata matching utility, improvements to the scoring mechanism, and updates to test cases for better validation.
Enhancements to memory filtering and scoring:
_get_nested_valueand_metadata_matcheshelper methods to improve metadata filtering by supporting nested dictionary paths and list comparisons. This ensures more flexible and accurate filtering of memory objects. (memory/search/strategies/step.py, memory/search/strategies/step.pyR317-R383)_filter_memoriesto use the new_metadata_matchesmethod for applying metadata filters, replacing the previous simplistic key-value matching logic. (memory/search/strategies/step.py, memory/search/strategies/step.pyL367-R435)_score_memoriesto handle edge cases (e.g., division by zero) and added debug logging for scoring calculations. This improves robustness and traceability of the scoring process. (memory/search/strategies/step.py, memory/search/strategies/step.pyR479-R496)Test suite improvements:
expected_memory_idslists by adding trailing commas for consistency. (validation/search/step/step_test_suite.py, [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]validation/search/step/step_test_suite.py, [1] [2]expected_memory_idslist in an edge case test to expand coverage. (validation/search/step/step_test_suite.py, validation/search/step/step_test_suite.pyL267-R272)