Vanguard AI

Embeddings

POST /v1/embeddings turns text into vectors: lists of 768 numbers in which texts that mean similar things sit close together. Use them to:

  • search by meaning: find the listings that match what someone typed, even when they share no words with it;
  • match: rank freelancers for a job, or jobs for a freelancer;
  • find duplicates: catch the same listing posted twice in different words.

The model is a multilingual embedding model at 768 dimensions, the same model and size the platform’s own knowledge index uses; the model field names it, and stays the same for as long as vectors from it stay comparable. It is multilingual, so Lao and English texts can go in the same request. The call is synchronous: JSON in, vectors out.

Authorization

Call it with an API key that carries the embeddings scope, or from a dashboard session. Add the scope to a key on the API keys page; you can change an existing key’s scopes without issuing a new one. A key without it gets 403 SCOPE_FORBIDDEN.

Create embeddings

POST /v1/embeddings API key

JSON body

texts *
string[]
1 to 100 texts, each 1 to 8,000 characters and not blank.
taskType *
string
RETRIEVAL_DOCUMENT, RETRIEVAL_QUERY or SEMANTIC_SIMILARITY. Pick it by what the text is; see below.
dimensions
integer
Optional, and 768 is the only value accepted. Send it so that a change would be refused loudly instead of reaching your vector column.
200 One vector per text, in the order you sent them.
{
  "status": "success",
  "model": "<embedding model id>",
  "dimensions": 768,
  "embeddings": [
    [0.0123, -0.0456, 0.0089, ...],
    [-0.0211, 0.0337, 0.0154, ...]
  ],
  "credits": 1,
  "latencyMs": 412
}

embeddings[i] always belongs to texts[i]. credits is what the request cost.

Choosing a task type

Pick taskType by what the text is, not by what you will do with it.

taskTypeForExample
RETRIEVAL_DOCUMENTWhat you store and search overGig and job listings, profiles, help articles
RETRIEVAL_QUERYWhat someone types into a search box“logo for my coffee shop”
SEMANTIC_SIMILARITYComparing two things of the same kindIs this new listing a copy of an existing one?

Index your catalogue with RETRIEVAL_DOCUMENT and embed searches with RETRIEVAL_QUERY. Mixing them up still returns vectors; they just retrieve worse.

Using the vectors

  • Compare with cosine similarity. The vectors come back as the model produces them, not scaled to length 1, so a raw dot product is skewed by their length. In Postgres with pgvector, store them in a vector(768) column and order by the <=> operator, or normalize them yourself before using an index that ranks by inner product.
  • Chunk long text yourself. The model reads at most 2,048 tokens of each text, roughly 8,000 characters of English and well under that of Lao, and ignores the rest. The platform’s own index uses chunks of about 1,500 characters.
  • Batch when you index. Up to 100 texts fit in one request, and the price is set by the total characters, so 100 short listings in one request cost 1 credit where 100 separate requests cost 100.
  • Debounce a search box. Every request costs at least 1 credit, so embed when the person stops typing, not on every keystroke.
  • Re-embed when the text changes, and store the vector next to the id of what it came from.

Pricing

1 credit per started 50,000 characters, counted across every text in the request, with a minimum of 1 credit per request.

RequestCharactersCredits
One search query401
100 listings of 400 characters each40,0001
100 texts of 8,000 characters (the largest request)800,00016

The full price is reserved before the call and refunded in full if it fails.

Limits

LimitValue
Texts per request1 to 100
Characters per text1 to 8,000, not blank
dimensions768 only
Tokens the model reads per text2,048
Time per request25 seconds, then 504 TIMEOUT and a refund

Your plan’s per-minute rate limit applies as it does everywhere else.

Errors

HTTPCodeWhen
400INVALID_REQUESTThe body is not JSON or breaks the shape above. The message names the field, for example texts.3: must not be blank
402QUOTA_EXCEEDEDNot enough credits
403SCOPE_FORBIDDENThe key does not carry embeddings
403SERVICE_DISABLEDEmbeddings are switched off for now
403VERIFICATION_REQUIREDYour organization has to complete identity verification first
429RATE_LIMITEDToo many requests this minute
429USAGE_LIMIT_REACHEDYour daily or monthly credit cap is reached
502GENERATION_FAILEDThe model failed. Refunded
503EMBEDDINGS_UNAVAILABLEEmbeddings are not configured on this deployment
504TIMEOUTNo answer within 25 seconds. Refunded

See Errors for the shared envelope.