Repository navigation
Optional prompt-embedding prefix input for chat completions #5831
NikolayGusev-astra
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Problem
Long-running agents re-send a large, mostly stable prefix on every request: system prompt, tool
schemas, and skill/instruction text. When that prefix is cold — a different skill, a different
ordering, a new worker, or a cache that was invalidated — the server pays full prefill for it again.
The API currently accepts only text/token ids for
messages. There is no way for a client that hasa pre-computed prefix representation to hand it over, so every such prefix must be re-encoded from
scratch even when the caller already knows exactly what it is.
What already exists in the tree
engine_core.add_request()already carriesvlm_inputs_embeds— "pre-computed vision+textembeddings for VLM" — through
Requestinto the scheduler, and the DeepSeek V4.1 path exercises itin tests. So the machinery for feeding embeddings instead of token ids is present; what is missing is
a text-only, non-VLM entry point at the HTTP layer.
Proposal (small, opt-in, no behaviour change by default)
Add an optional field to
POST /v1/chat/completions:Semantics:
prompt_embedsis a prefix, not a replacement. The server tokenizesmessagesas usual,embeds them, concatenates
[prompt_embeds; text_embeds], and prefills that single sequence.shape[1]must equal the model's hidden size,kbounded by a configurable limit, payload size bounded by the existing body limit. On anymismatch —
400with the expected shape, never a silent truncation.400 unsupportedrather than falling back.Optionally, a second form for callers that cannot compute embeddings themselves:
where the server keeps a registry of pre-computed prefixes keyed by model + revision, and refuses a
gist_idrecorded against a different checkpoint.Why this is worth a slot
does. This is the case a prefix cache cannot cover.
to on every decode step — that benefit applies even when the cache is warm.
Prompts with Gist Tokens) produces exactly this object: a handful of trained embeddings that
stand in for a long instruction. Today such work cannot reach this server at all through the
chat API.
Parity test that needs no training
Embed a known text with the model's own
embed_tokens, send the result asprompt_embedswith anempty message list, and assert the completion matches a normal request carrying the same text —
same logits, same sampled tokens under a fixed seed. That proves the protocol end-to-end without any
trained gist artifact, and it is the test I would ship with the change.
Non-goals
vlm_inputs_embeds.Ask
Is this shape acceptable — an optional
prompt_embedsfield on chat completions — or would youprefer it confined to a separate endpoint, or to the registry form only (
gist_id) so arbitrarytensors never cross the API boundary?
Happy to send the change as a PR against
mainonce the shape is settled; I'd rather ask first thanadd a third variant of an embeddings path that a maintainer has already ruled on.
All reactions