TsgcAIOpenAIEmbeddingsMethods › CreateEmbeddings

CreateEmbeddings Method

Splits the input text into chunks and generates an embedding for each chunk.

Syntax

procedure CreateEmbeddings(const aInput: string);

Parameters

NameTypeDescription
aInputconst stringText from which the embeddings will be generated.

Remarks

Walks the input string in steps of EmbeddingsOptions.ChunkSize characters and, for each chunk, performs a call to the OpenAI embeddings endpoint using the model configured in EmbeddingsOptions. The batch is bracketed by OnCreateEmbeddingsStart and OnCreateEmbeddingsStop, and each individual chunk fires OnBeforeCreateEmbedding, OnAfterCreateEmbedding and OnCreateEmbeddingsProgress. When Database is assigned the resulting vectors are stored automatically. If WaitStoringData is greater than zero, the call sleeps for that many milliseconds between chunks.

Example

oEmbeddings.OpenAIOptions.ApiKey := 'sk-...';
oEmbeddings.EmbeddingsOptions.Model := 'text-embedding-3-small';
oEmbeddings.EmbeddingsOptions.ChunkSize := 2048;
oEmbeddings.Database := oFileDB;
oEmbeddings.CreateEmbeddings('The quick brown fox jumps over the lazy dog.');

Back to Methods