refactor(embedding_compute): extract providers into adapter pattern#373
Open
luojiyin1987 wants to merge 2 commits into
Open
refactor(embedding_compute): extract providers into adapter pattern#373luojiyin1987 wants to merge 2 commits into
luojiyin1987 wants to merge 2 commits into
Conversation
- Split embedding_compute.py (1444→403 lines) into registry + dispatch - New providers/ package with one module per backend: - sentence_transformers.py (487 lines) — ST models + hardware optimizations - openai.py (136 lines) — OpenAI-compatible API - mlx.py (82 lines) — Apple Silicon MLX - ollama.py (335 lines) — Ollama local server - gemini.py (89 lines) — Google Gemini API - Add _init_providers() lazy-import + _providers registry dict - Add register_provider(name, fn) for third-party backends - Full backward compat: old function names (compute_embeddings_sentence_transformers etc.) kept as module-level aliases replaced at provider init - Shared utilities (_model_cache, get_model_token_limit, truncate_to_token_limit, _query_ollama_context_limit, _query_lmstudio_context_limit) stay in main module - Adding a new provider now requires only a new file + 1 registry line
- Remove unused imports: subprocess, time, cast, json, etc. - Add missing imports: _model_cache (mlx), token limit helpers (ollama), Protocol (st) - Apply ruff format to satisfy CI pre-commit checks
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.
Closes #372
Summary
Split the 1444-line
embedding_compute.pymonolith into a registry-backed adapter pattern.New structure
Design
Benefits
register_provider()