TsgcAIOpenAIEmbeddings › Events › OnAfterCreateEmbedding
Fired after each chunk is processed, exposing the OpenAI request and response.
property OnAfterCreateEmbedding: TsgcOpenAIAfterCreateEmbedding;
// TsgcOpenAIAfterCreateEmbedding = procedure(Sender: TObject; const aRequest: TsgcOpenAIClass_Request_Embeddings; const aResponse: TsgcOpenAIClass_Response_Embeddings) of object
—
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.
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;