feat: generate_embedding routes non-default models through client.embed (T112.3)
When model != DEFAULT_EMBEDDING_MODEL, generate_embedding now calls client.embed(text, model=model) and wraps the returned vector in an EmbeddingResult tagged with the requested model. On any exception (NotImplementedError from providers without an embeddings endpoint, transient network errors, etc.), the existing T107 warning fires and the function falls back to the zero-vector sentinel — callers detect model == 'fallback' and skip indexing. Adds: - MockLLMClient accepts a canned_embeddings queue mirroring the existing canned pattern. embed() pops from the front; empty queue raises IndexError so misconfigured tests fail loudly. - Settings.embedding_model defaults to "pseudo-sha256-384" so existing zero-config installs keep Phase 4 behavior. The app lifespan now passes this through to EmbeddingWorker.model. The public signature of generate_embedding is unchanged: (client, *, text, model=DEFAULT_EMBEDDING_MODEL, dim=..., timeout_s=...).
This commit is contained in:
@@ -24,3 +24,25 @@ def test_chat_db_path_env_overrides_default(tmp_path, monkeypatch):
|
||||
(tmp_path / "config.toml").write_text('featherless_api_key = "x"\n')
|
||||
s = load_settings()
|
||||
assert s.db_path == tmp_path / "alt.db"
|
||||
|
||||
|
||||
def test_embedding_model_defaults_to_pseudo(tmp_path, monkeypatch):
|
||||
"""T112: ``embedding_model`` defaults to the deterministic pseudo
|
||||
so existing zero-config installs keep the Phase 4 behavior."""
|
||||
monkeypatch.setenv("CHAT_CONFIG_PATH", str(tmp_path / "config.toml"))
|
||||
(tmp_path / "config.toml").write_text('featherless_api_key = "x"\n')
|
||||
s = load_settings()
|
||||
assert s.embedding_model == "pseudo-sha256-384"
|
||||
|
||||
|
||||
def test_embedding_model_overridable_via_toml(tmp_path, monkeypatch):
|
||||
"""T112: operators swap the embedding model by editing config.toml.
|
||||
The new value flows through to the embedding worker at startup."""
|
||||
cfg = tmp_path / "config.toml"
|
||||
cfg.write_text(
|
||||
'featherless_api_key = "x"\n'
|
||||
'embedding_model = "bge-small-en-v1.5"\n'
|
||||
)
|
||||
monkeypatch.setenv("CHAT_CONFIG_PATH", str(cfg))
|
||||
s = load_settings()
|
||||
assert s.embedding_model == "bge-small-en-v1.5"
|
||||
|
||||
Reference in New Issue
Block a user