auto-append /v1 to vllm base_url, matching ollama behavior

This commit is contained in:
Yiorgis Gozadinos 2026-05-05 16:08:14 +03:00
parent 4478b7ce2b
commit 1ccb5b5fad
No known key found for this signature in database
2 changed files with 39 additions and 0 deletions

View file

@ -200,6 +200,8 @@ def get_embedder(config: AppConfig = Config) -> EmbedderWrapper:
from haiku.rag.embeddings.vllm import VLLMMultimodalEmbedder
base_url = embedding_model.base_url or "http://localhost:8000/v1"
if not base_url.rstrip("/").endswith("/v1"):
base_url = base_url.rstrip("/") + "/v1"
return VLLMMultimodalEmbedder(model_name, vector_dim, base_url=base_url)
raise ValueError(f"Unsupported embedding provider: {provider}")

View file

@ -111,3 +111,40 @@ def test_ollama_embedder_does_not_double_append_v1():
url = str(pa_model.base_url).rstrip("/") # type: ignore[union-attr] # ty: ignore[unresolved-attribute]
assert url.endswith("/v1")
assert not url.endswith("/v1/v1")
def test_vllm_embedder_appends_v1_when_missing():
"""vLLM's chat-completions endpoint also lives under /v1. A user who
forgets the suffix would otherwise POST to <host>/embeddings and get
a 404 match the Ollama behavior and append it."""
config = AppConfig(
embeddings=EmbeddingsConfig(
model=EmbeddingModelConfig(
provider="vllm",
name="Qwen/Qwen3-VL-Embedding-8B",
vector_dim=4096,
base_url="http://my-vllm:8000",
),
),
)
embedder = get_embedder(config)
base_url = embedder._base_url # type: ignore[attr-defined] # ty: ignore[unresolved-attribute]
assert base_url.endswith("/v1")
def test_vllm_embedder_does_not_double_append_v1():
"""If the user already includes /v1 we leave it alone."""
config = AppConfig(
embeddings=EmbeddingsConfig(
model=EmbeddingModelConfig(
provider="vllm",
name="Qwen/Qwen3-VL-Embedding-8B",
vector_dim=4096,
base_url="http://my-vllm:8000/v1",
),
),
)
embedder = get_embedder(config)
base_url = embedder._base_url.rstrip("/") # type: ignore[attr-defined] # ty: ignore[unresolved-attribute]
assert base_url.endswith("/v1")
assert not base_url.endswith("/v1/v1")