Repository navigation
Studio: serve /v1/embeddings from the configured embedding model when the loaded GGUF cannot - #10315
Conversation
… the loaded GGUF cannot
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
GitHub Actions reproductionReproduced the defect and verified the fix on real
Probe result lines, verbatim: Review findings fixed on this branchEach was reproduced before it was fixed, and each carries a regression test that fails before the change and passes after:
Notes
Update for the review fixesSame harness, staged on fresh upstream
The 510 is the GGUF's 512 context minus the two special tokens the server adds, read from the model instead of assumed. |
…ee the preview guard
…mit on the GGUF embedder
…ning context and default prompt, hide local model paths
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4354283699
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…ed name and hide Windows-shaped model paths
…disconnect, match aliases without probing and keep redacted local names unique
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d6efec00bf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # encode: a 2xx would otherwise claim the llama slot, block a preview swap for the whole | ||
| # encode, and stamp the idle-unload TTL for a model that did no work. | ||
| _scope = getattr(request, "scope", None) | ||
| untrack_current_request(_scope) |
There was a problem hiding this comment.
Keep fallback embeddings visible to training admission
When the configured embedder is GPU-backed and an API-key client starts training during a fallback embedding request, this call removes the request from _inflight for the entire encode, including while a cancellation leaves its worker thread running. Both training entrypoints use other_inference_request_count(current_request_counted = False) as their active-inference guard (routes/training.py:1184-1189 and 2714-2719), while their VRAM cleanup does not unload or wait for core.rag.embeddings, so training can begin allocating the GPU concurrently with the embedder and fail the request or training run with an OOM. Keep this work counted until the worker finishes and use a separate scope marker to suppress only the llama-slot claim.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not taking this one. The mechanism is described correctly - the untrack does drop the request from _inflight, and other_inference_request_count(current_request_counted = False) is what both training entrypoints read - but the OOM it is aimed at does not depend on that window.
Neither embedder holds its VRAM only for the duration of an encode. The llama-server backend runs in a subprocess that lives until process exit (atexit.register(self._shutdown), embed_llama_server.py:168); its VRAM is resident before the request arrives and after it returns. The in-process torch backend defaults to CPU (_device(), embeddings.py:58, and the auto note at config.py:226), and under RAG_EMBED_DEVICE=gpu its first allocation creates a CUDA primary context that, per that same docstring, no amount of unloading returns. So keeping the request counted for the worker's lifetime would gate training on a window that does not determine whether the embedder is on the GPU.
It also would not close the gap it names. core/rag/ingestion.py:121, conversation_archive.py:413, web_rank.py:100 and retrieval.py:63 drive the same embedder from background work that has never been in _inflight, on main as much as here - a folder sync is far heavier than one memory-search batch and stays invisible to training admission either way.
Against that, keeping it counted has a real cost: the guard 409s training-over-API whenever any inference request is in flight, and an agent that runs memory search each turn would make training effectively unstartable.
The broader point that GPU-resident embedder VRAM is not represented to training admission is fair, but it is pre-existing, it covers every embedder caller rather than this one route, and the fix belongs where the embedder acquires the GPU, not in this request's tracking scope.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 158f51e527
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if prompt and tokenizer is not None: | ||
| reserved += len(tokenizer.encode(prompt, add_special_tokens = False)) | ||
| return max(1, int(limit) - reserved) |
There was a problem hiding this comment.
Count the default prompt and input in one tokenization
For SentenceTransformer models with a default prompt and a boundary-sensitive tokenizer such as BPE, token counts are not additive across concatenation: encode() tokenizes prompt + text, while this computes a fixed prompt reservation and the route separately tokenizes text. Near max_seq_length, boundary merges can therefore make the endpoint reject a valid input or, worse, admit an input that encode() silently truncates. Count each prompted input as the model actually tokenizes it rather than subtracting the independently tokenized prompt.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The tokenizer semantics are right, but this does not clear the bar for a change here.
The branch only fires when the model declares a non-null default_prompt_name; per the sentence-transformers docs, if it is not set no prompt is applied at all. Surveying the models this setting realistically holds, every one has default_prompt_name: null - bge-small-en-v1.5 (the default, and WordPiece), bge-m3, nomic-embed-text-v1.5, mxbai-embed-large-v1, snowflake-arctic-embed-m-v2.0 and Qwen3-Embedding-0.6B all ship prompts at most as named entries a caller must select.
I measured the non-additivity rather than assuming it. Over 8000 random inputs per model, comparing len(enc(p + t)) against len(enc(p)) + len(enc(t)): Qwen3-Embedding-0.6B (BPE) ranges -1 to +1; snowflake-arctic-embed-m-v2.0 (Unigram) and bge-small-en-v1.5 (WordPiece) are exactly 0 in every case. So the boundary effect is real on BPE but bounded at one token, and the reservation already subtracts num_special_tokens_to_add() on top, which is the larger term.
The remedy also has a cost outside this route. token_counter is the same callable chunking holds for a whole document, where the passage side is not what a default query prompt would be prepended to; folding a prompt into it would resize chunks everywhere to buy back one token at the limit.
Leaving it as a conservative reservation.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 270e7c405d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # setting, mixing one model's limit and dimension with another's vectors. | ||
| limit = rag_embeddings.max_tokens(model_name) | ||
| count = rag_embeddings.token_counter(model_name) | ||
| token_counts = [count(text) for text in texts] |
There was a problem hiding this comment.
Avoid one tokenize request per batch item
When the configured fallback uses LlamaServerBackend and the input contains many distinct strings, this comprehension invokes the counter's synchronous /tokenize POST once per item; those calls are serialized by the backend's serve lock before embedding begins. A valid maximum-size batch therefore makes 2,048 local HTTP round trips versus roughly 32 embedding requests at the default batch size, causing severe latency and likely client timeouts. Count the batch in one operation or impose a substantially smaller limit for this backend.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The per-item round trip is real - _post takes _serve_lock, so the counts are serialized - but I do not think it clears the bar, and the suggested remedy is not available.
llama.cpp's /tokenize takes a single content string; the documented options are content, add_special and parse_special, with no array form. There is no way to count a batch in one operation against this server.
I measured the transport rather than guess at it: 2048 sequential localhost POSTs through the same httpx client take 2.10s, about 1.0ms each. That is against embedding the same 2048 texts, which on the CPU path this backend defaults to runs at roughly 445 chunks/s - about 4.6s. So the counting adds well under half of a request that was already seconds long, and the counter is lru_cache(maxsize = 4096), so repeat text within and across batches is free.
A smaller cap for this backend would be a real behavior change - the same 2048 is what the ST path serves - to buy back a fraction of a request nobody has reported timing out. If a batch that size does turn out to be a problem in practice it is the embedding, not the tokenizing, that has to get cheaper.
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |

/v1/embeddings only ever talked to the model in the chat slot. With nothing loaded it returned 503, and with a chat model loaded llama-server returned 501. Meanwhile Studio's own embedding model from Settings was already running next to the chat model for document search, and the API had no way to reach it.
Now, if an embedding GGUF is loaded it is used exactly as before. Otherwise the request goes to the Settings embedding model. Chat and embeddings work at the same time, which is what #8535 asked for and what #9128 reported as broken.
Naming the Settings embedding model in the request works too, by its name, its GGUF repo, or the identity the response reports. Any other model name goes through the normal auto-switch logic first, as on every other route.
The fallback returns the normal OpenAI response shape and supports float and base64. Input longer than the model allows gets a 400 instead of being cut short. The limit comes from the model itself on both embedder backends, the sentence-transformers max length or the GGUF context length, minus the special tokens the tokenizer adds. It runs under a small concurrency limit and never touches the chat model or its unload gate, so nothing that works today changes.
The response reports the embedding model that actually produced the vectors, including which backend ran it, so a client can tell if the space changed.
Tested on a real Studio: the same requests that return 503 and 501 on main return 200 here, with chat completions still working while embeddings are served. Boundary checked on the GGUF embedder: 510 tokens pass, 511 is rejected.