TsgcAIOpenAIEmbeddingsEvents › OnAfterCreateEmbedding

OnAfterCreateEmbedding Event

Fired after each chunk is processed, exposing the OpenAI request and response.

Syntax

property OnAfterCreateEmbedding: TsgcOpenAIAfterCreateEmbedding;
// TsgcOpenAIAfterCreateEmbedding = procedure(Sender: TObject; const aRequest: TsgcOpenAIClass_Request_Embeddings; const aResponse: TsgcOpenAIClass_Response_Embeddings) of object

Default Value

Remarks

Raised once per chunk, right after the OpenAI endpoint returns a successful response and before the vector is persisted into Database. aRequest contains the original Input and Model; aResponse.Data contains the embedding vector, which can be read as a float array or as a comma-separated string through EmbeddingAsString. Use this event to log the embedding, inspect token usage or store additional metadata.

Example

procedure TForm1.oEmbeddingsAfterCreateEmbedding(Sender: TObject;
  const aRequest: TsgcOpenAIClass_Request_Embeddings;
  const aResponse: TsgcOpenAIClass_Response_Embeddings);
begin
  if Length(aResponse.Data) > 0 then
    Memo1.Lines.Add('Vector: ' + aResponse.Data[0].EmbeddingAsString);
end;

Back to Events