prompt_embeds_caching_protocol
The prompt_embeds chat content part, as Output Protection extends it, and the errors a server answers it with.
This is the contract between a prompt-embeds client and an Output Protection server, and it lives here rather than on the server side
because both ends have to agree on it. A client builds these parts; the server reads them. Pair it with
compute_prompt_embeds_id, which produces the identifiers they
carry.
vLLM already defines a content part for uploading embeddings:
class ChatCompletionContentPartPromptEmbedsParam(TypedDict, total=False):
data: Required[str]
type: Required[Literal["prompt_embeds"]]
Output Protection adds one key, id, and with it two shapes vLLM's type cannot express.
Why these are siblings of vLLM's type rather than subclasses of it
A reference carries no embeddings, so its data is None, but vLLM declares data: Required[str], and a TypedDict subclass may not
change the type of an inherited item.
Type Aliases:
| Name | Description |
|---|---|
PromptEmbedsContentPart |
Any |
Classes:
| Name | Description |
|---|---|
ChatCompletionContentPartCachedPromptEmbedsParam |
Embeddings named rather than sent, for a server that already holds them. |
ChatCompletionContentPartUploadedPromptEmbedsParam |
Embeddings sent in full, labelled with the identifier the client computed for them. |
PromptEmbedsErrorBody |
Envelope the errors above arrive in, as |
PromptEmbedsNotCachedError |
Body of the |
Functions:
| Name | Description |
|---|---|
cached_prompt_embeds_part |
Build a part that references embeddings the server already holds. |
uploaded_prompt_embeds_part |
Build a part that uploads embeddings and labels them. |
Attributes:
| Name | Type | Description |
|---|---|---|
INVALID_PROMPT_EMBEDS_PART_CODE |
Final[str]
|
|
PROMPT_EMBEDS_ID_MISMATCH_CODE |
Final[str]
|
|
PROMPT_EMBEDS_NOT_CACHED_CODE |
Final[str]
|
|
PROMPT_EMBEDS_PART_TYPE |
Final[str]
|
Value of a content part's |
INVALID_PROMPT_EMBEDS_PART_CODE
module-attribute
¶
400. The part cannot be acted on: it carries neither data nor id, or an id that is not an identifier.
PROMPT_EMBEDS_ID_MISMATCH_CODE
module-attribute
¶
400. An upload's claimed id is not the one the server computed, so the two ends disagree and references would never hit.
PROMPT_EMBEDS_NOT_CACHED_CODE
module-attribute
¶
409. One or more referenced identifiers are not held. The client should re-upload them and retry.
PROMPT_EMBEDS_PART_TYPE
module-attribute
¶
Value of a content part's type that marks it as carrying prompt embeddings. Unchanged from vLLM's.
PromptEmbedsContentPart
¶
PromptEmbedsContentPart = (
ChatCompletionContentPartPromptEmbedsParam
| ChatCompletionContentPartUploadedPromptEmbedsParam
| ChatCompletionContentPartCachedPromptEmbedsParam
)
Any prompt_embeds content part an Output Protection server accepts.
ChatCompletionContentPartCachedPromptEmbedsParam
¶
Bases: TypedDict
Embeddings named rather than sent, for a server that already holds them.
Both forms are accepted:
{"type": "prompt_embeds", "id": "blake3:..."}
{"type": "prompt_embeds", "data": null, "id": "blake3:..."}
Attributes:
| Name | Type | Description |
|---|---|---|
data |
None
|
|
id |
Required[str]
|
Content identifier of the embeddings being referenced, as |
type |
Required[Literal['prompt_embeds']]
|
The type of the content part. |
ChatCompletionContentPartUploadedPromptEmbedsParam
¶
Bases: TypedDict
Embeddings sent in full, labelled with the identifier the client computed for them.
The first turn of a conversation, and every turn carrying a message the server has not seen. Identical to vLLM's part but for the id,
which a server without the cache ignores.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
Required[str]
|
Base64-encoded bytes of a serialized |
id |
Required[str]
|
Content identifier of those embeddings, as |
type |
Required[Literal['prompt_embeds']]
|
The type of the content part. |
PromptEmbedsNotCachedError
¶
Bases: TypedDict
Body of the 409 answering a reference the server cannot serve.
Attributes:
| Name | Type | Description |
|---|---|---|
missing_ids |
Required[list[str]]
|
Every identifier the request referenced that the server does not hold, so one retry can carry them all. |
cached_prompt_embeds_part
¶
cached_prompt_embeds_part(
identifier: str,
) -> ChatCompletionContentPartCachedPromptEmbedsParam
Build a part that references embeddings the server already holds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
What |
required |
Returns:
| Type | Description |
|---|---|
ChatCompletionContentPartCachedPromptEmbedsParam
|
The content part. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the identifier is not shaped like one, which would be rejected by the server. |
uploaded_prompt_embeds_part
¶
uploaded_prompt_embeds_part(
payload: str, identifier: str
) -> ChatCompletionContentPartUploadedPromptEmbedsParam
Build a part that uploads embeddings and labels them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Base64-encoded bytes of the serialized tensor. |
required |
|
str
|
What |
required |
Returns:
| Type | Description |
|---|---|
ChatCompletionContentPartUploadedPromptEmbedsParam
|
The content part. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the payload is empty, or the identifier is not shaped like one. Either would be rejected or, worse, silently misread by the server. |