refactor: (scheduler) modularize handlers and search pipelines#1004
Merged
tangg555 merged 15 commits intoMemTensor:dev-20260202-v2.0.5from Feb 6, 2026
Merged
Conversation
- extract scheduler handlers into dedicated modules - split retriever into pipelines (search/enhance/rerank/filter) - centralize text search logic for API and scheduler Refs MemTensor#1003
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the scheduler and retrieval stack to make handler logic modular, split retrieval into clearer pipelines, and centralize text-search behavior so that the API and scheduler share a single implementation.
Changes:
- Introduces a shared
search_servicemodule and updates API/scheduler callers to use centralized text-memory search. - Refactors
SchedulerRetrieverinto composable search/enhancement/rerank/filter pipeline classes and extracts corresponding mixins fromBaseScheduler. - Modularizes scheduler handlers into dedicated classes wired via a
SchedulerHandlerRegistryand DI-styleSchedulerHandlerContext.
Reviewed changes
Copilot reviewed 27 out of 27 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
src/memos/search/search_service.py |
Adds SearchContext and search_text_memories to centralize text-memory search arguments and behavior. |
src/memos/search/__init__.py |
Exposes the new search service types/functions as public API. |
src/memos/multi_mem_cube/single_cube.py |
Replaces inline text search logic with calls to search_text_memories for fast search. |
src/memos/mem_scheduler/optimized_scheduler.py |
Switches scheduler search paths to use centralized search functions and shared SearchContext. |
src/memos/mem_scheduler/memory_manage_modules/search_pipeline.py |
Extracts the search step of the scheduler retriever into a standalone SearchPipeline. |
src/memos/mem_scheduler/memory_manage_modules/retriever.py |
Refactors SchedulerRetriever into a façade composed of search/enhancement/rerank/filter pipelines. |
src/memos/mem_scheduler/memory_manage_modules/rerank_pipeline.py |
Encapsulates LLM-based memory reranking and combined memory post-processing in RerankPipeline. |
src/memos/mem_scheduler/memory_manage_modules/filter_pipeline.py |
Wraps MemoryFilter operations in a dedicated FilterPipeline. |
src/memos/mem_scheduler/memory_manage_modules/enhancement_pipeline.py |
Moves enhancement and recall logic into EnhancementPipeline, including batching and parallelization. |
src/memos/mem_scheduler/handlers/registry.py |
Adds SchedulerHandlerRegistry that instantiates handler classes and builds the label-to-handler dispatch map. |
src/memos/mem_scheduler/handlers/query_handler.py |
Implements QueryMessageHandler to log user queries and re-label them to memory-update tasks. |
src/memos/mem_scheduler/handlers/pref_add_handler.py |
Implements PrefAddMessageHandler to process preference-add messages concurrently and write to PreferenceTextMemory. |
src/memos/mem_scheduler/handlers/memory_update_handler.py |
Extracts long-memory update flow and retrieval triggering logic into MemoryUpdateHandler. |
src/memos/mem_scheduler/handlers/mem_reorganize_handler.py |
Adds MemReorganizeMessageHandler to process memory reorganization and emit merge logs. |
src/memos/mem_scheduler/handlers/mem_read_handler.py |
Adds MemReadMessageHandler to drive mem-reader processing and downstream knowledge-base logs. |
src/memos/mem_scheduler/handlers/feedback_handler.py |
Implements FeedbackMessageHandler to process feedback payloads and emit KB update logs in cloud environments. |
src/memos/mem_scheduler/handlers/context.py |
Defines SchedulerHandlerContext and SchedulerHandlerServices to inject scheduler dependencies into handlers. |
src/memos/mem_scheduler/handlers/base.py |
Introduces BaseSchedulerHandler to store the injected handler context. |
src/memos/mem_scheduler/handlers/answer_handler.py |
Implements AnswerMessageHandler to log assistant responses as messages. |
src/memos/mem_scheduler/handlers/add_handler.py |
Extracts add-memory logging (local vs cloud KB) into AddMessageHandler. |
src/memos/mem_scheduler/handlers/__init__.py |
Re-exports handler context and registry for use by the scheduler. |
src/memos/mem_scheduler/general_scheduler.py |
Simplifies GeneralScheduler to assemble handler context/registry and register handlers instead of inlined consumers; delegates memory ops to mixins. |
src/memos/mem_scheduler/base_scheduler.py |
Refactors core scheduler behavioral methods into separate mixins and updates BaseScheduler inheritance accordingly. |
src/memos/mem_scheduler/base_mixins/web_log_ops.py |
Moves web-log publishing and normalization logic into BaseSchedulerWebLogMixin. |
src/memos/mem_scheduler/base_mixins/queue_ops.py |
Moves message submission, dispatch, consumer loop, and queue monitoring into BaseSchedulerQueueMixin. |
src/memos/mem_scheduler/base_mixins/memory_ops.py |
Moves working/activation memory management and monitoring helpers into BaseSchedulerMemoryMixin. |
src/memos/mem_scheduler/base_mixins/__init__.py |
Re-exports the new scheduler base mixins. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/memos/mem_scheduler/task_schedule_modules/handlers/memory_update_handler.py
Show resolved
Hide resolved
src/memos/mem_scheduler/memory_manage_modules/search_pipeline.py
Outdated
Show resolved
Hide resolved
src/memos/mem_scheduler/memory_manage_modules/enhancement_pipeline.py
Outdated
Show resolved
Hide resolved
src/memos/mem_scheduler/memory_manage_modules/enhancement_pipeline.py
Outdated
Show resolved
Hide resolved
src/memos/mem_scheduler/memory_manage_modules/enhancement_pipeline.py
Outdated
Show resolved
Hide resolved
- Fix TC001/TC002/TC003: move type-only imports into TYPE_CHECKING blocks - Fix RUF059: prefix unused variables with underscore - Fix typos: "Memorires" -> "Memories", "exeption" -> "exception" - Remove self-assignment: `text_mem_base = text_mem_base` - Remove unused `user_context` param from `build_search_context` - Restore original `QUERY_TASK_LABEL` in activation memory update - Apply ruff format to all modified files
- json-encode list/dict fields for Redis XADD - decode chat_history safely when reading from streams
- avoid private _memory_update_consumer call - delegate mem update handler to built-in handler
Contributor
Author
|
更新说明(本次追加修复):
|
- apply X | Y form to satisfy UP038
- align datetime line breaks with ruff format
…r-stage2 This commit merges key modularization benefits and bug fixes from the refactor-scheduler-stage2 branch into fancy-scheduler: Modularize activation memory logic into ActivationMemoryManager Introduce SchedulerSearchService for unified memory search coordination Extract filtering and reranking logic into MemoryPostProcessor Maintain intentional search scope of LongTermMemory and UserMemory in SearchPipeline and SchedulerSearchService Update BaseScheduler to initialize and manage lifecycle of new modules Refactor BaseSchedulerMemoryMixin to delegate tasks to specialized managers
Rename abbreviation 'ctx' to 'scheduler_context' in GeneralScheduler and SchedulerHandlerRegistry to improve code readability and clarity.
- Sync orchestrator config removal when unregistering handlers in dispatcher - Fix missing TaskPriorityLevel import in dispatcher - Fix register_handlers signature in BaseSchedulerQueueMixin - Fix handler registry imports and initialization map - Fix relative imports in handlers package
- prefix unused unpacked vars with underscore - apply ruff format changes
- Update MemReadMessageHandler to extract user_context from message and pass it to _process_memories_with_reader and transfer_mem. - Update PrefAddMessageHandler to extract user_context from message and pass it to pref_mem.add. - This ensures user context information is available during memory reading and preference adding operations.
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.
Description
Summary:
Problem:
Approach:
Dependencies:
Related Issue (Required): Fixes #1003
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Test steps:
cd src && python -m uvicorn memos.api.server_api:app --host 0.0.0.0 --port 8001Test Results:
Checklist
Reviewer Checklist