.f0rge/wiki/docs/capabilities/embed.v1.md 3.4 KiB 108 lines Raw

embed.v1

Status: v1. A published shape is frozen by spec.md section 20.1. Capability key: embed Route: POST /embed

Parts in

One row for each part kind that this capability accepts. A kind that is not in this table is invalid_part.

kindrolerequiredmeaning
textanyyes, one or morethe text to embed. The role is not significant.

Parameters

The plugin validates these. A parameter that is not in this table is ignored, not an error (R26).

nametypedefaultmeaning
dimensionsuintcataloguethe length of every vector
normalizebooltruescale every vector to unit length

There is no encoding parameter. The payload is always application/cbor with float32 values.

Channels out

One row for each channel that this capability can emit.

channelmimepayload
embeddingapplication/cborone array of vectors. One vector per text part, in input order.

Terminal metadata

done.meta is vocabulary-defined. The core stores it and never reads it. done without meta means {}.

keytypemeaning
modelstringthe served name that ran the job
dimsuintthe length of every vector in this job

model and dims are present when outcome is completed. They are absent when the outcome is cancelled or expired.

Request

POST /embed
{
  "model": "<served-name>",
  "input": [
    {"kind": "text", "text": "A record of reserved bytes."},
    {"kind": "text", "text": "A ledger is a map of devices."},
    {"kind": "json", "role": "options", "json": {"intent": "lookup"}}
  ],
  "params": {"dimensions": 4096, "normalize": true},
  "stream": false
}

Response, no stream

{"job": "019...", "outcome": "completed",
 "embedding": {"mime": "application/cbor", "inline": "<cbor array of vectors>"},
 "usage": {"tokens_in": 2},
 "meta": {"model": "<served-name>", "dims": 4096}}

Stream

embed is not a streamed capability. stream = true still gives one artifact in one done frame. No event frame precedes it.

done   outcome=completed
       artifacts=[{"channel":"embedding","mime":"application/cbor","inline":"<cbor>"}]
       meta={"model": "<served-name>", "dims": 4096}

Rules

  1. At least one text part is required. A request with no text part is invalid_part.
  2. An image, audio, video, tokens, or json part is invalid_part.
  3. The embedding payload is one array. Its length equals the number of text parts.
  4. Vector i is the output of text part i. The plugin never reorders the array.
  5. Every vector is an array of float32 values. The length of every vector equals meta.dims.
  6. normalize = true scales every vector to unit length. normalize = false leaves the vector as the model gave it.
  7. dimensions is never larger than the catalogue value for the model. A larger value gives a refusal that names dimensions.
  8. One embedding payload carries the whole array. The plugin never splits one job into two payloads.
  9. usage.tokens_in is the number of prompt tokens. It is absent when the plugin cannot count them.
  10. No event follows a cancel. The terminal frame is done with outcome = cancelled.
  11. The plugin emits CBOR bytes on the embedding channel. It emits nothing else for this job.

view raw