-
Notifications
You must be signed in to change notification settings - Fork 444
refactor(scheduler): modularize handlers and search pipelines #1004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
refactor(scheduler): modularize handlers and search pipelines #1004
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
There was a problem hiding this 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 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/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
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