TsgcHTTP_API_OpenAIMethods › CreateEmbeddings

CreateEmbeddings Method

Creates vector embeddings for one or more input strings using an OpenAI embedding model

Syntax

function CreateEmbeddings(const aRequest : TsgcOpenAIClass_Request_Embeddings) : TsgcOpenAIClass_Response_Embeddings;

Parameters

NameTypeDescription
aRequestconst TsgcOpenAIClass_Request_EmbeddingsEmbeddings request specifying the model, input text(s) and optional encoding format

Return Value

Embeddings response containing the generated vectors and token usage (TsgcOpenAIClass_Response_Embeddings)

Remarks

Calls the POST /v1/embeddings endpoint. Embeddings are dense vector representations of text that can be used for semantic search, clustering, classification and retrieval-augmented generation. Recommended models include text-embedding-3-small and text-embedding-3-large. The response contains one vector per input string, in the same order as provided.

Example

oRequest := TsgcOpenAIClass_Request_Embeddings.Create;
oRequest.Model := 'text-embedding-3-small';
oRequest.Input.Add('The quick brown fox jumps over the lazy dog');
oResponse := oAPI.CreateEmbeddings(oRequest);
ShowMessage(IntToStr(Length(oResponse.Data[0].Embedding)));

Back to Methods