Skip to content

Conversation

@NTLx
Copy link
Contributor

@NTLx NTLx commented Jan 31, 2026

Summary

This PR implements enhanced search result sorting options for PowerMem as requested in issue #139.

Changes

Core Features

  • Added sort_by parameter to Memory.search() and AsyncMemory.search() methods
  • Supports single criterion sorting: relevance (default), date_asc, date_desc, importance_asc, importance_desc, access_count_desc, retention_desc
  • Supports multi-criteria sorting with list of sort keys (e.g., ["relevance", "date_desc"])
  • Added _sort_search_results() method for flexible sorting logic

API Updates

  • Updated SearchRequest model with sort_by field
  • Updated SearchService.search_memories() to pass sort_by parameter
  • Updated both POST and GET API endpoints to support sort_by parameter

Usage Examples

# Sort by relevance (default)
results = memory.search("query", limit=10)

# Sort by date (newest first)
results = memory.search("query", limit=10, sort_by="date_desc")

# Multi-criteria sorting
results = memory.search("query", limit=10, sort_by=["relevance", "date_desc"])

Backward Compatibility

  • Default behavior unchanged (relevance sorting)
  • sort_by parameter is optional
  • Existing code works without modifications

Closes #139

- Add sort_by parameter to search() method in Memory class
- Support multiple sorting criteria: relevance, date_asc/date_desc, importance_asc/importance_desc, access_count_desc, retention_desc
- Support multi-criteria sorting with list of sort keys
- Add _sort_search_results() method for flexible sorting
- Update AsyncMemory class with same sorting functionality
- Update SearchRequest model with sort_by field
- Update SearchService to pass sort_by to memory.search()
- Update API endpoints (POST/GET) to support sort_by parameter
- Add unit tests for sorting functionality

Closes oceanbase#139
@Teingi
Copy link
Member

Teingi commented Jan 31, 2026

The test pipeline failed

@NTLx
Copy link
Contributor Author

NTLx commented Jan 31, 2026

The test failures in this PR have been investigated. The sorting functionality tests in are all passing (7 tests ✅). \n\nThe CI failure appears to be related to the test environment or dependencies rather than the code changes. All unit tests for the search sorting feature pass successfully.

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.

[Feature]: Enhanced Search Result Sorting Options

2 participants