OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.
Python
fix: embed through the gateway for every provider, not just aliased ones (#2443)
Rico Furtado4872034590e4
diff --git a/src/config/settings.py b/src/config/settings.pyindex e5c39494b..b7509ecea 100644--- a/src/config/settings.py+++ b/src/config/settings.py@@ -1455,11 +1455,6 @@ class AppClients:"""Alias for patched_async_client - for backward compatibility with code expecting separate clients."""return self.patched_async_client- @property- def patched_embedding_client(self):- """Alias for patched_async_client - for backward compatibility with code expecting separate clients."""- return self.patched_async_client-async def refresh_patched_client(self):"""Reset patched client so next use picks up updated provider credentials."""if self._patched_async_client is not None:diff --git a/src/models/processors.py b/src/models/processors.pyindex 250e90aef..2fca67024 100644--- a/src/models/processors.py+++ b/src/models/processors.py@@ -637,23 +637,21 @@ class TaskProcessor:text_batches = chunk_texts_for_embeddings(texts, max_tokens=max_tokens)embeddings = []- from services.model_catalog import litellm_provider_key, public_model_id-- gateway_model = None- if litellm_provider_key(embedding_provider) != embedding_provider:- from services.llm_gateway import embeddings as gateway_embeddings-- gateway_model = public_model_id(embedding_provider, embedding_model)+ # Every provider goes through the gateway, not just the aliased ones.+ # The gateway resolves credentials per call from config; the direct+ # client resolved them from process-global environment written once per+ # process, which is never unset when a provider is deconfigured and is+ # shared by every provider in the process. Gating on "is this provider+ # aliased?" also meant the correctness of ingestion depended on an+ # unrelated routing detail.+ from services.llm_gateway import embeddings as gateway_embeddings+ from services.llm_gateway import qualified_model_id++ gateway_model = qualified_model_id(embedding_provider, embedding_model)for batch in text_batches:- if gateway_model is not None:- response = await gateway_embeddings({"model": gateway_model, "input": batch})- data = response.get("data", [])- else:- response = await clients.patched_embedding_client.embeddings.create(- model=litellm_embedding_model, input=batch- )- data = response.data+ response = await gateway_embeddings({"model": gateway_model, "input": batch})+ data = response.get("data", [])embeddings.extend([item["embedding"] if isinstance(item, dict) else item.embedding for item in data])diff --git a/src/services/langflow_file_service.py b/src/services/langflow_file_service.pyindex a530c377c..a8fea9709 100644--- a/src/services/langflow_file_service.py+++ b/src/services/langflow_file_service.py@@ -131,25 +131,30 @@ class LangflowFileService:embedding_provider: str | None,) -> int:"""Generate one probe embedding so mapping dimensions match the provider."""- from services.models_service import ModelsServicecache_key = f"{embedding_provider or ''}:{embedding_model}"cached = self._embedding_dimension_cache.get(cache_key)if cached:return cached- litellm_model_name = await ModelsService().get_litellm_model_name(- embedding_model,- provider=embedding_provider,+ # Through the gateway, like ingestion: the probe decides the index+ # mapping's vector width, so it has to reach the same endpoint the real+ # embedding call will. The direct client resolved credentials from+ # process-global environment instead of from config.+ from services.llm_gateway import embeddings as gateway_embeddings+ from services.llm_gateway import qualified_model_id++ response = await gateway_embeddings(+ {+ "model": qualified_model_id(embedding_provider, embedding_model),+ "input": ["dimension probe"],+ })- response = await clients.patched_embedding_client.embeddings.create(- model=litellm_model_name,- input=["dimension probe"],- )- if not response.data:+ data = response.get("data") or []+ if not data:raise RuntimeError("Embedding provider returned no data for dimension probe")- first = response.data[0]+ first = data[0]embedding = first["embedding"] if isinstance(first, dict) else first.embeddingdimensions = len(embedding)if dimensions <= 0:diff --git a/src/services/llm_gateway.py b/src/services/llm_gateway.pyindex f545c9de1..2bf1f3215 100644--- a/src/services/llm_gateway.py+++ b/src/services/llm_gateway.py@@ -124,6 +124,47 @@ def split_model_id(model: str) -> tuple[str | None, str]:return None, raw+def qualified_model_id(provider: str | None, model: str) -> str:+ """`provider:model` for an internal caller that already knows the provider.++ The inverse of `model_catalog.public_model_id`, which *strips* the tag for+ OpenAI because that is what an OpenAI-compatible client expects to see on+ `/v1/models`. An internal caller needs the opposite guarantee: an untagged+ id is resolved against whichever provider happens to be configured as the+ default (`resolve_call` -> `default_provider`), so ingesting with a model+ whose provider is *not* the default would silently call the wrong one.++ An explicit `provider` always wins, including over a slash-shaped prefix in+ `model` itself: watsonx serves `openai/gpt-oss-120b`, and leaving that+ untagged resolves it to OpenAI — with OpenAI's credentials, for a model+ OpenAI does not serve. `watsonx:openai/gpt-oss-120b` says which is meant.++ An id already tagged for this provider is returned as it is, in either+ form. The legacy `provider/` spelling matters: ids stored before the switch+ to `provider:` are still in saved configuration, and re-tagging one gives+ `azure:azure/prod-embed`, which `split_model_id` reduces to the model name+ `azure/prod-embed` — so LiteLLM is asked for `azure/azure/prod-embed`.++ Only the explicit provider's own prefix is removed. A slash elsewhere in+ the name is part of the name: watsonx serves `openai/gpt-oss-120b`, and+ `ibm/slate-125m` is one model, not a tag and a model.++ With no `provider`, the id is returned unchanged so the gateway falls back+ to the configured default, which is what an untagged call has always done.+ """+ name = (model or "").strip()+ key = (provider or "").strip().lower()+ if not name or not key:+ return name+ canonical = f"{key}{PROVIDER_SEPARATOR}"+ if name.lower().startswith(canonical):+ return name+ legacy = f"{key}/"+ if name.lower().startswith(legacy):+ name = name[len(legacy) :]+ return f"{canonical}{name}"++def default_provider(kind: Literal["chat", "embedding"], config=None) -> str:cfg = config or _get_config()if kind == "embedding":diff --git a/src/services/model_catalog.py b/src/services/model_catalog.pyindex 8dc743c35..4c542cc79 100644--- a/src/services/model_catalog.py+++ b/src/services/model_catalog.py@@ -592,10 +592,14 @@ def public_model_id(provider: str, model: str) -> str:The tag uses `provider:model`, not `provider/model`: watsonx serves`openai/gpt-oss-120b`, so a slash-joined id is indistinguishable from thatmodel's own name.++ Delegates the tagging itself, so the rules for what counts as an existing+ tag — including the legacy `provider/` spelling — live in one place rather+ than drifting between two modules that differ only in this OpenAI case."""- from services.llm_gateway import PROVIDER_SEPARATOR+ from services.llm_gateway import qualified_model_id- return model if provider == "openai" else f"{provider}{PROVIDER_SEPARATOR}{model}"+ return model if provider == "openai" else qualified_model_id(provider, model)def openai_models_list(today: datetime.date | None = None) -> dict[str, Any]:diff --git a/tests/unit/services/test_embedding_calls_use_the_gateway.py b/tests/unit/services/test_embedding_calls_use_the_gateway.pynew file mode 100644index 000000000..3ebd8b30a--- /dev/null+++ b/tests/unit/services/test_embedding_calls_use_the_gateway.py@@ -0,0 +1,272 @@+"""Ingestion and the dimension probe embed through the LLM gateway.++Both call sites used to reach `clients.patched_embedding_client` — a LiteLLM-+patched `AsyncOpenAI` whose provider credentials come from process-global+environment written once per process. That environment is shared by every+provider, is set but never unset when a provider is deconfigured, and is+populated lazily on first client use.++Ingestion did have a gateway path, but it was gated on+`litellm_provider_key(provider) != provider` — true only for providers that+route under a *different* LiteLLM key (`watsonx_onprem`, `rhoai`). So whether+ingestion resolved credentials from config or from stale process environment+depended on an unrelated routing detail. The dimension probe had no gateway+path at all, which meant the vector width written into the index mapping could+be probed against a different endpoint than the one that later embedded the+documents.++These tests pin the fix: every provider goes through the gateway, and the id it+is given names the provider explicitly.+"""++import sys+from pathlib import Path+from types import SimpleNamespace+from unittest.mock import AsyncMock++import pytest++ROOT = Path(__file__).resolve().parent.parent.parent.parent+SRC = ROOT / "src"+if str(SRC) not in sys.path:+ sys.path.insert(0, str(SRC))++from services.llm_gateway import qualified_model_id # noqa: E402+++class TestQualifiedModelId:+ """The id handed to the gateway names the provider the caller resolved."""++ def test_an_untagged_model_gains_its_providers_tag(self) -> None:+ assert qualified_model_id("azure_ai", "my-deployment") == "azure_ai:my-deployment"++ def test_openai_is_tagged_too_unlike_the_public_id(self) -> None:+ """`public_model_id` strips the tag for OpenAI; this must not.++ An untagged id is resolved against the *configured default* provider.+ Ingesting with OpenAI while the default embedding provider is something+ else would then silently call that other provider.+ """+ assert qualified_model_id("openai", "text-embedding-3-small") == (+ "openai:text-embedding-3-small"+ )++ def test_an_explicit_provider_wins_over_a_slash_shaped_name(self) -> None:+ """watsonx serves `openai/gpt-oss-120b`, and the slash is part of the name.++ Left untagged it resolves to OpenAI — with OpenAI's credentials, for a+ model OpenAI does not serve.+ """+ assert qualified_model_id("watsonx", "openai/gpt-oss-120b") == (+ "watsonx:openai/gpt-oss-120b"+ )++ def test_an_already_tagged_id_is_not_tagged_twice(self) -> None:+ assert qualified_model_id("azure_ai", "azure_ai:my-deployment") == (+ "azure_ai:my-deployment"+ )++ @pytest.mark.parametrize(+ "provider, stored, expected",+ [+ ("azure", "azure/prod-embed", "azure:prod-embed"),+ (+ "watsonx_onprem",+ "watsonx_onprem/ibm/slate-125m",+ "watsonx_onprem:ibm/slate-125m",+ ),+ ("azure", "AZURE/prod-embed", "azure:prod-embed"),+ ],+ )+ def test_a_legacy_slash_tag_is_not_re_tagged(self, provider, stored, expected) -> None:+ """Ids stored before the switch to `provider:` are still in config.++ Re-tagging one gives `azure:azure/prod-embed`; `split_model_id` then+ strips the colon tag and leaves `azure/prod-embed` as the model name,+ so LiteLLM is asked for `azure/azure/prod-embed` and the call fails as+ a missing model.+ """+ assert qualified_model_id(provider, stored) == expected++ @pytest.mark.parametrize(+ "provider, model, expected",+ [+ # A slash in the name is part of the name, not a tag.+ ("watsonx", "ibm/slate-125m", "watsonx:ibm/slate-125m"),+ ("watsonx", "openai/gpt-oss-120b", "watsonx:openai/gpt-oss-120b"),+ # Another provider's tag is also just a name here.+ ("azure_ai", "openai/gpt-4o", "azure_ai:openai/gpt-4o"),+ ],+ )+ def test_only_this_providers_own_prefix_is_stripped(self, provider, model, expected) -> None:+ """watsonx genuinely serves `openai/gpt-oss-120b`."""+ assert qualified_model_id(provider, model) == expected++ @pytest.mark.parametrize(+ "provider, stored, expected_route",+ [+ ("azure", "azure/prod-embed", "azure/prod-embed"),+ ("watsonx", "ibm/slate-125m", "watsonx/ibm/slate-125m"),+ ],+ )+ def test_what_litellm_finally_receives(self, provider, stored, expected_route) -> None:+ """The bug is only visible after the round trip, so assert that too."""+ from services.llm_gateway import split_model_id++ resolved, name = split_model_id(qualified_model_id(provider, stored))+ assert f"{resolved}/{name}" == expected_route++ @pytest.mark.parametrize("provider", [None, "", " "])+ def test_without_a_provider_the_id_is_left_for_the_default(self, provider) -> None:+ """Unchanged, so the gateway falls back to the configured default.++ That is what an untagged call has always done, and the caller has+ nothing better to offer.+ """+ assert qualified_model_id(provider, "text-embedding-3-small") == ("text-embedding-3-small")++ def test_a_blank_model_stays_blank(self) -> None:+ assert qualified_model_id("openai", "") == ""++ def test_the_public_id_shares_these_rules(self) -> None:+ """`public_model_id` delegates, so de-duplication cannot drift apart.++ It had the same double-tagging defect: the two helpers differ only in+ the OpenAI case, and keeping the tagging rules in one place is what+ stops one being fixed and the other not.+ """+ from services.model_catalog import public_model_id++ assert public_model_id("azure", "azure/prod-embed") == "azure:prod-embed"+ assert public_model_id("azure", "azure:prod-embed") == "azure:prod-embed"+ # OpenAI still gets a bare id, which is the one difference.+ assert public_model_id("openai", "text-embedding-3-small") == ("text-embedding-3-small")+++def _processor(model: str):+ """A `TaskProcessor` whose every external dependency is a stub.++ `check_document_exists` is stubbed rather than driven through OpenSearch so+ the test exercises the embedding call and nothing else.+ """+ from models.processors import TaskProcessor++ class _Writer:+ async def index_chunks(self, context, chunks, *, final=False):+ return None++ document_service = SimpleNamespace(+ session_manager=SimpleNamespace(+ get_user_opensearch_client=lambda user_id, jwt_token: SimpleNamespace()+ ),+ document_index_writer=_Writer(),+ )+ docling_service = SimpleNamespace(+ convert_file=AsyncMock(+ return_value={+ "origin": {+ "binary_hash": "doc-hash",+ "filename": "scan.png",+ "mimetype": "image/png",+ },+ "texts": [],+ "tables": [],+ "pictures": [{"prov": [{"page_no": 1}], "annotations": []}],+ }+ )+ )+ processor = TaskProcessor(+ document_service,+ SimpleNamespace(get_litellm_model_name=AsyncMock(return_value=model)),+ docling_service,+ )+ processor.check_document_exists = AsyncMock(return_value=False)+ return processor+++ "provider, model, expected_id",+ [+ # Not aliased, so the old code took the direct-client path.+ ("azure_ai", "my-deployment", "azure_ai:my-deployment"),+ ("openai", "text-embedding-3-small", "openai:text-embedding-3-small"),+ ("azure", "prod-embed", "azure:prod-embed"),+ # Aliased: already used the gateway, and must keep doing so.+ ("watsonx_onprem", "ibm/slate-125m", "watsonx_onprem:ibm/slate-125m"),+ ],+)+async def test_ingestion_embeds_through_the_gateway_for_every_provider(+ monkeypatch, provider, model, expected_id+) -> None:+ """No provider reaches the direct client, aliased or not."""+ calls: list[dict] = []++ async def fake_embeddings(body, **_kwargs):+ calls.append(body)+ return {"data": [{"embedding": [0.1, 0.2, 0.3]} for _ in body["input"]]}++ monkeypatch.setattr("services.llm_gateway.embeddings", fake_embeddings)++ # `clients`, minus the direct embedding client: reaching for it is exactly+ # the regression this test exists to catch, so it raises rather than+ # quietly succeeding on a MagicMock.+ class _ClientsWithoutDirectEmbedding:+ opensearch = None++ def __getattr__(self, name):+ raise AssertionError(+ f"ingestion reached clients.{name}; embeddings must go through the gateway"+ )++ monkeypatch.setattr("models.processors.clients", _ClientsWithoutDirectEmbedding())+ monkeypatch.setattr(+ "models.processors.get_openrag_config",+ lambda: SimpleNamespace(+ knowledge=SimpleNamespace(+ embedding_model=model,+ embedding_provider=provider,+ chunk_size=None,+ chunk_overlap=None,+ )+ ),+ )+ monkeypatch.setattr(+ "services.document_service.chunk_texts_for_embeddings",+ lambda texts, max_tokens: [texts] if texts else [],+ )++ await _processor(model).process_document_standard(+ file_path="scan.png",+ file_hash="doc-hash",+ owner_user_id="user-1",+ jwt_token="Bearer token",+ ocr=False,+ picture_descriptions=False,+ )++ assert [body["model"] for body in calls] == [expected_id]+++async def test_the_dimension_probe_goes_through_the_gateway(monkeypatch) -> None:+ """The probe sets the index mapping's vector width.++ It has to reach the same endpoint the real embedding call will, or the+ mapping is sized against a different provider than the one that fills it.+ """+ from services import llm_gateway as gateway_mod+ from services.langflow_file_service import LangflowFileService++ calls: list[dict] = []++ async def fake_embeddings(body, **_kwargs):+ calls.append(body)+ return {"data": [{"embedding": [0.0] * 1024}]}++ monkeypatch.setattr(gateway_mod, "embeddings", fake_embeddings)++ service = LangflowFileService(docling_service=AsyncMock())++ assert await service._detect_embedding_dimensions("my-deployment", "azure_ai") == 1024+ assert calls == [{"model": "azure_ai:my-deployment", "input": ["dimension probe"]}]diff --git a/tests/unit/test_langflow_file_service_two_phase.py b/tests/unit/test_langflow_file_service_two_phase.pyindex 8e5ab5a59..4131072dd 100644--- a/tests/unit/test_langflow_file_service_two_phase.py+++ b/tests/unit/test_langflow_file_service_two_phase.py@@ -237,33 +237,27 @@ def test_processor_accepts_injected_polling_service():@pytest.mark.asyncioasync def test_langflow_preflight_detects_embedding_dimensions_with_probe(monkeypatch):- class FakeEmbeddings:- def __init__(self):- self.calls = []+ calls: list[tuple[str, list]] = []- async def create(self, model, input):- self.calls.append((model, input))- return SimpleNamespace(data=[SimpleNamespace(embedding=[0.1] * 7)])+ async def fake_embeddings(body, **_kwargs):+ calls.append((body["model"], body["input"]))+ return {"data": [{"embedding": [0.1] * 7}]}- fake_embeddings = FakeEmbeddings()- fake_client = SimpleNamespace(embeddings=fake_embeddings)-- async def fake_get_litellm_model_name(self, model_name, provider=None, strict=False):- assert model_name == "provider/model"- assert provider == "provider"- return "provider/provider/model"-- monkeypatch.setattr("config.settings.clients._patched_async_client", fake_client)- monkeypatch.setattr(- "services.models_service.ModelsService.get_litellm_model_name",- fake_get_litellm_model_name,- )+ monkeypatch.setattr("services.llm_gateway.embeddings", fake_embeddings)svc = LangflowFileService(docling_service=AsyncMock())assert await svc._detect_embedding_dimensions("provider/model", "provider") == 7assert await svc._detect_embedding_dimensions("provider/model", "provider") == 7- assert fake_embeddings.calls == [("provider/provider/model", ["dimension probe"])]+ # One call for two invocations: the probe is cached per provider+model.+ # The id is provider-tagged with `:` so the gateway routes it to the+ # provider the caller named rather than to the configured default.+ #+ # `provider/model` is the legacy tagged spelling of the same id, so the+ # tag is replaced rather than stacked. Asserting `provider:provider/model`+ # here, as this did, encoded the double-tagging bug: the gateway strips+ # the colon tag and would ask LiteLLM for `provider/provider/model`.+ assert calls == [("provider:model", ["dimension probe"])]@pytest.mark.asynciodiff --git a/tests/unit/test_processor_mapping_client.py b/tests/unit/test_processor_mapping_client.pyindex 4e690b38f..c4c566dde 100644--- a/tests/unit/test_processor_mapping_client.py+++ b/tests/unit/test_processor_mapping_client.py@@ -53,14 +53,13 @@ async def test_standard_processor_uses_shared_writer_for_embedding_mapping_and_wassert provider == "openai"return embedding_model- class EmbeddingClient:- class Embeddings:- async def create(self, model, input):- return SimpleNamespace(- data=[SimpleNamespace(embedding=[0.1, 0.2, 0.3]) for _ in input]- )-- embeddings = Embeddings()+ async def gateway_embeddings(body):+ return {+ "data": [+ {"embedding": [0.1, 0.2, 0.3], "index": index}+ for index, _ in enumerate(body["input"])+ ]+ }async def ensure_embedding_field_exists(client, model_name, index_name, dimensions):mapping_clients.append(client)@@ -69,20 +68,9 @@ async def test_standard_processor_uses_shared_writer_for_embedding_mapping_and_wassert dimensions == 3return "chunk_embedding_openai_text_embedding_3_small"- monkeypatch.setattr(- "config.settings.clients",- SimpleNamespace(- opensearch=admin_client,- patched_embedding_client=EmbeddingClient(),- ),- )- monkeypatch.setattr(- "models.processors.clients",- SimpleNamespace(- opensearch=admin_client,- patched_embedding_client=EmbeddingClient(),- ),- )+ monkeypatch.setattr("config.settings.clients", SimpleNamespace(opensearch=admin_client))+ monkeypatch.setattr("models.processors.clients", SimpleNamespace(opensearch=admin_client))+ monkeypatch.setattr("services.llm_gateway.embeddings", gateway_embeddings)monkeypatch.setattr("config.settings.get_index_name", lambda: "documents")monkeypatch.setattr("models.processors.get_index_name", lambda: "documents")monkeypatch.setattr(@@ -177,15 +165,6 @@ async def test_standard_processor_routes_onprem_embeddings_through_gateway(assert provider == "watsonx_onprem"return f"watsonx_onprem/{embedding_model}"- class FailingEmbeddingClient:- class Embeddings:- async def create(self, **kwargs):- raise AssertionError(- "watsonx.ai on-prem must not use the environment-backed embedding client"- )-- embeddings = Embeddings()-class Writer:async def index_chunks(self, context, chunks, *, final=False):indexed.append((context, chunks, final))@@ -201,10 +180,9 @@ async def test_standard_processor_routes_onprem_embeddings_through_gateway()),)- monkeypatch.setattr(- "models.processors.clients",- SimpleNamespace(opensearch=None, patched_embedding_client=FailingEmbeddingClient()),- )+ # No embedding client to stub: every provider embeds through the gateway,+ # and reaching for one is guarded in test_embedding_calls_use_the_gateway.+ monkeypatch.setattr("models.processors.clients", SimpleNamespace(opensearch=None))monkeypatch.setattr("services.llm_gateway.embeddings", gateway_embeddings)file_path = tmp_path / "doc.md"diff --git a/tests/unit/test_processors_clear_stale_chunks.py b/tests/unit/test_processors_clear_stale_chunks.pyindex d3170d962..d58112d4d 100644--- a/tests/unit/test_processors_clear_stale_chunks.py+++ b/tests/unit/test_processors_clear_stale_chunks.py@@ -87,19 +87,18 @@ def _patch_embedding_pipeline(monkeypatch, chunk_count: int, write_client=None):lambda texts, max_tokens=8000: [list(texts)],)- # patched_embedding_client.embeddings.create — return one embedding per text.+ # Embeddings go through the gateway for every provider, so stub it at its+ # source module — `process_document_standard` imports it lazily per call.+ from services import llm_gateway as gateway_mod++ async def _fake_embeddings(body, **_kwargs):+ return {"data": [{"embedding": [0.1, 0.2, 0.3]} for _ in body["input"]]}++ monkeypatch.setattr(gateway_mod, "embeddings", _fake_embeddings)+# `clients` is the singleton imported at module scope; replace it wholesale- # (the real one's `patched_embedding_client` is a read-only @property).- class _FakeEmbedResp:- def __init__(self, n):- self.data = [{"embedding": [0.1, 0.2, 0.3]} for _ in range(n)]-- fake_embed_client = MagicMock()- fake_embed_client.embeddings.create = AsyncMock(- side_effect=lambda model, input: _FakeEmbedResp(len(input))- )+ # so the OpenSearch write client is the test's.fake_clients = MagicMock()- fake_clients.patched_embedding_client = fake_embed_clientfake_clients.opensearch = write_clientmonkeypatch.setattr(processors_mod, "clients", fake_clients)diff --git a/tests/unit/test_processors_image_only.py b/tests/unit/test_processors_image_only.pyindex 72d437b59..8e758136f 100644--- a/tests/unit/test_processors_image_only.py+++ b/tests/unit/test_processors_image_only.py@@ -18,17 +18,18 @@ from models.processors import TaskProcessorasync def test_image_only_placeholder_succeeds_but_empty_document_fails(monkeypatch, pictures, chunk_size, expected_result):- embedding_create = AsyncMock(- return_value=SimpleNamespace(data=[{"embedding": [0.1, 0.2, 0.3]}])- )+ # Embeddings go through the gateway for every provider; it is imported+ # lazily inside the processor, so stub it at its source module.+ embedding_calls: list[dict] = []++ async def fake_embeddings(body, **_kwargs):+ embedding_calls.append(body)+ return {"data": [{"embedding": [0.1, 0.2, 0.3]} for _ in body["input"]]}++ monkeypatch.setattr("services.llm_gateway.embeddings", fake_embeddings)monkeypatch.setattr("models.processors.clients",- SimpleNamespace(- opensearch=None,- patched_embedding_client=SimpleNamespace(- embeddings=SimpleNamespace(create=embedding_create)- ),- ),+ SimpleNamespace(opensearch=None),)monkeypatch.setattr("models.processors.get_openrag_config",@@ -94,14 +95,16 @@ async def test_image_only_placeholder_succeeds_but_empty_document_fails("status": "error","error": "No text content could be extracted from document",}- embedding_create.assert_not_awaited()+ assert embedding_calls == []assert indexed == {}returnassert result == {"status": "indexed", "id": "image-hash"}- embedding_create.assert_awaited_once_with(- model="text-embedding-3-small", input=["<!-- image -->"]- )+ # Provider-tagged so the gateway routes to the provider the processor+ # resolved, not to whatever happens to be the configured default.+ assert embedding_calls == [+ {"model": "openai:text-embedding-3-small", "input": ["<!-- image -->"]}+ ]assert indexed["final"] is Trueassert len(indexed["chunks"]) == 1assert indexed["chunks"][0].text == "<!-- image -->"