To use the embeddings, first we must convert our data to vectors.
Example
If you have a pdf file, first convert the pdf file to text and then use the method CreateEmbeddingsFromFile to get the vector data. Due to the OpenAI Embeddings size limitation, if the file is too big, the data will be splitted automatically in chunks, so from 1 file you can get 1 or multiple vectors.
Find below a code sample.
procedure ConvertFileToVector;
var
oDialog: TOpenDialog;
oEmbeddings: TsgcAIOpenAIEmbeddings;
oFile: TsgcAIDatabaseVectorFile;
begin
oDialog := TOpenDialog.Create(nil);
Try
oDialog.Filter := 'TXT Files|*.txt';
if oDialog.Execute then
begin
oEmbeddings := TsgcAIOpenAIEmbeddings.Create(nil);
Try
oFile := TsgcAIDatabaseVectorFile.Create(nil);
Try
oEmbeddings.Database := oFile;
oEmbeddings.OpenAIOptions.ApiKey := '<your api key>';
oEmbeddings.CreateEmbeddingsFromFile(oDialog.FileName);
Finally
oFile.Free;
End;
Finally
oEmbeddings.Free;
End;
end;
Finally
FreeAndNil(oDialog);
End;
end;