Embeddings and recordings
The full rules for ai.embed, ai.embed_all and recorded answers. The
common case is under Asking for an embedding
and Recorded answers.
embedding_dimensions:is a whole number from 1 to 16,000, pgvector's most, written out (ai.settings_invalidotherwise). Everyai.embedandai.embed_allcall needs it: an app that embeds without it issemantic.ai_dimensions_mismatchat the call'sas:, as one whose type has another length is. The built-in driver doesn't send it, because a local model makes vectors of its own length and servers differ on thedimensionsparameter. Instead, each vector the model answers with is read asV, so one of another length ismisconfigured. A package whose provider can shorten its vectors sends it, through its mapping'sembed:.- What
ai.embedtakes. The text is a value built onText, or aMarkdown, never one that may benone;embed_alltakes aListof them (type.mismatchotherwise).as:is a type written out built onVectorwithdimensions:(type.mismatchfor a plainVector, anEmbeddingor anything else). The options aremodel:, a nameai: { models: }gives (semantic.unknown_name), defaulting toembedding, whichai:must then name (ai.settings_invalidat the call), andtimeout:,1sto10m, 5 seconds unless written. Any other istype.named_argument_unknown. Each oftimed_out,over_budgetandtoo_longneeds an arm naming anunavailablefailure, asai.generate's conditions do. Only an action calls it. - The built-in driver sends OpenAI's embeddings request,
POST <url>/embeddingswithmodelandinput, every text in one request, and readsdata[i].embeddinginindexorder. A400whoseerror.codeiscontext_length_exceededistoo_long; no answer withintimeout:istimed_out; the rest is read asai.generatereads it (misconfigured,unavailable, sent again withintimeout:). More than 100 texts in oneembed_allistoo_long, with nothing sent; no texts gives no vectors without asking. The call is logged and recorded as the operationembedof the model connection, and its answer reused on a rerun and kept as a step of a record, asai.generate's is. - The fake's embedding of a text is
dimensionsnumbers drawn from SHA-256 over the text's own SHA-256, the test's seed and a counter, each the top 24 bits of four bytes scaled to -1 to 1, then divided by the vector's length, so the same text under one seed always gives the same unit vector, and two texts give vectors far apart.fakes: { ai.embed: [...] }scripts only the three failures, each one call ofai.embedorai.embed_allin the order made (ai.embed_allis scripted asai.embed): a vector written out in a test would be as long as the model's, and embedding the same text gives the same vector anyway. A prompt calledembedis scripted as the operation. - A recording is
recordings/<prompt>/<name>.jsonin the prompt's ownprompts/folder: one JSON object withanswer, a value of the type the prompt is asked for as written asjson.writewrites it, andversion, the prompt's version it answered,answer_question@864ad76b. The answer keeps plain texts and numbers as placeholders naming their type, as a package's recordings do, so no personal data a prompt carried is committed; booleans, enum spellings, lists' lengths andnullare kept as given. A placeholder is filled with a generated value of its type, at its place, each time the recording is read. recorded("<name>")infakes: { ai.<prompt>: }names one of the prompt's recordings, written out (semantic.fake_invalidwith the nearest otherwise), and is one attempt answered with its answer, sent as the model sends one, so a strict mode'svaluewrapping and aTextanswer's plain text are as a live answer's, and decoded by the call's own type.- Every recording is decoded by
jadpo test, the build the gate runs. Each is a test of therecordingkind, as a package's recordings are, named<prompt>'s <name> recording decodes, through each type anai.generatecall asks its prompt for as. A recording fails it astest.recording_undecodablewhen it doesn't decode, isn't one JSON object with ananswerand aversion, sits where no prompt of its folder's name is, or records a prompt no call asks. - A changed prompt's recordings are an alert,
▲ alert, onjadpo test's report, and in its--jsonasdata.alerts(kind: recording_stale). The one hint after the footer points atjadpo ai show. Jadpo has no warning severity, and a stale recording still decodes, so neitherchecknor the run fails on it.
Markdown for agents: /docs/embeddings-and-recordings.md.Built from Jadpo main at a707efb.