codex-lens: respect embedding config during warmup

This commit is contained in:
catlog22
2026-03-05 14:27:54 +08:00
parent 60218f6bf3
commit ed02874a99
2 changed files with 48 additions and 2 deletions

View File

@@ -3531,8 +3531,20 @@ class ChainSearchEngine:
self.logger.debug("Using single-threaded mode for vector search (GPU safety)")
# Pre-load embedder to avoid initialization overhead per-search
try:
from codexlens.semantic.embedder import get_embedder
get_embedder(profile="code", use_gpu=True)
from codexlens.semantic.factory import get_embedder as get_embedder_factory
embedding_backend = "fastembed"
embedding_model = "code"
use_gpu = True
if self._config is not None:
embedding_backend = getattr(self._config, "embedding_backend", embedding_backend) or embedding_backend
embedding_model = getattr(self._config, "embedding_model", embedding_model) or embedding_model
use_gpu = bool(getattr(self._config, "embedding_use_gpu", use_gpu))
if embedding_backend == "litellm":
get_embedder_factory(backend="litellm", model=embedding_model)
else:
get_embedder_factory(backend="fastembed", profile=embedding_model, use_gpu=use_gpu)
except Exception:
pass # Ignore pre-load failures

View File

@@ -155,3 +155,37 @@ def test_cascade_search_invalid_strategy(temp_paths: Path) -> None:
engine.cascade_search("query", source_path, strategy="invalid_strategy")
mock_binary.assert_called_once()
def test_vector_warmup_uses_embedding_config(monkeypatch: pytest.MonkeyPatch, temp_paths: Path) -> None:
calls: list[dict[str, object]] = []
def fake_get_embedder(**kwargs: object) -> object:
calls.append(dict(kwargs))
return object()
import codexlens.semantic.factory as factory
monkeypatch.setattr(factory, "get_embedder", fake_get_embedder)
registry = RegistryStore(db_path=temp_paths / "registry.db")
registry.initialize()
mapper = PathMapper(index_root=temp_paths / "indexes")
config = Config(
data_dir=temp_paths / "data",
embedding_backend="fastembed",
embedding_model="fast",
embedding_use_gpu=False,
)
engine = ChainSearchEngine(registry, mapper, config=config)
monkeypatch.setattr(engine, "_get_executor", lambda _workers: MagicMock())
engine._search_parallel([], "query", SearchOptions(enable_vector=True))
assert calls == [
{
"backend": "fastembed",
"profile": "fast",
"use_gpu": False,
}
]