Skip to content

Dev#106

Merged
csmangum merged 2 commits intomainfrom
dev
May 9, 2025
Merged

Dev#106
csmangum merged 2 commits intomainfrom
dev

Conversation

@csmangum
Copy link
Contributor

@csmangum csmangum commented May 9, 2025

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:

  • Added _get_nested_value and _metadata_matches helper 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)
  • Updated _filter_memories to use the new _metadata_matches method for applying metadata filters, replacing the previous simplistic key-value matching logic. (memory/search/strategies/step.py, memory/search/strategies/step.pyL367-R435)
  • Enhanced _score_memories to 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:

  • Fixed formatting issues in expected_memory_ids lists by adding trailing commas for consistency. (validation/search/step/step_test_suite.py, [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]
  • Updated metadata filters in test cases to reflect more realistic scenarios, such as changing metadata types and tags. (validation/search/step/step_test_suite.py, [1] [2]
  • Added a new memory ID to the expected_memory_ids list in an edge case test to expand coverage. (validation/search/step/step_test_suite.py, validation/search/step/step_test_suite.pyL267-R272)

csmangum added 2 commits May 8, 2025 18:07
…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.
@csmangum csmangum requested a review from Copilot May 9, 2025 01:33
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")

@csmangum csmangum merged commit 8ec90ed into main May 9, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants