Vector Database (Pinecone)
TsgcAIDatabaseVectorPinecone 把您的嵌入向量放进托管的 Pinecone 索引。导入过程会把所有向量合并为一次 upsert,查询则返回最接近匹配项背后所存储的文本,因此语料库可以在多台机器和多个用户之间共享。
TsgcAIDatabaseVectorPinecone 把您的嵌入向量放进托管的 Pinecone 索引。导入过程会把所有向量合并为一次 upsert,查询则返回最接近匹配项背后所存储的文本,因此语料库可以在多台机器和多个用户之间共享。
文件存储在云端的对应方案。接口相同、调用相同,但索引位于 Pinecone 中,可以扩展到超出内存容纳范围的规模。
sgcAI 是自包含的。该组件随 sgcAI 一同交付,并附带它所基于的 sgcWebSockets Core 运行时,因此无需购买基础授权。
设置 API 密钥、环境、索引和项目,然后把它赋给一个嵌入向量组件。
uses
sgcAI, sgcAI_DB_Vector_Pinecone, sgcAI_OpenAI_Embeddings;
var
oDB: TsgcAIDatabaseVectorPinecone;
oEmbeddings: TsgcAIOpenAIEmbeddings;
begin
oDB := TsgcAIDatabaseVectorPinecone.Create(nil);
oDB.PineconeOptions.ApiKey := 'pc-...';
oDB.PineconeOptions.Environment := 'us-west4-gcp-free';
oDB.PineconeIndexOptions.IndexName := 'sgc-embeddings';
oDB.PineconeIndexOptions.ProjectId := 'abcd1234';
oEmbeddings := TsgcAIOpenAIEmbeddings.Create(nil);
oEmbeddings.OpenAIOptions.ApiKey := 'sk-...';
oEmbeddings.Database := oDB;
// Every chunk is batched into a single upsert.
oEmbeddings.CreateEmbeddingsFromFile('manual.txt');
// Retrieve context for a question.
Memo1.Text := oEmbeddings.GetEmbedding('How do I reset the device?', '');
end;
// includes: sgcAI.hpp, sgcAI_DB_Vector_Pinecone.hpp
TsgcAIDatabaseVectorPinecone *oDB = new TsgcAIDatabaseVectorPinecone(NULL);
oDB->PineconeOptions->ApiKey = "pc-...";
oDB->PineconeOptions->Environment = "us-west4-gcp-free";
oDB->PineconeIndexOptions->IndexName = "sgc-embeddings";
oDB->PineconeIndexOptions->ProjectId = "abcd1234";
oDB->BeginAddData();
oDB->AddData("Reset procedure: hold the button for 10 seconds.", vVector);
oDB->EndAddData();
String vBest = oDB->QueryData(vQueryVector);
您最常使用的成员。
ApiKey 和 Environment 用于在您的 Pinecone 账户上完成身份验证,并选择索引所在的区域。
IndexName 和 ProjectId 用于定位具体的索引。两者都可以在 Pinecone 控制台中找到。
BeginAddData 开始收集,AddData 把一段文本及其向量排入队列,EndAddData 则把整批内容作为一次 upsert 发送,而不是每一块发一次请求。
QueryData 对索引发起一次相似度查询,并返回最佳匹配项背后所存储的文本。
OnBeginAddData 为本批次设置起始 id 和 id 标签,使多次导入可以共存于同一个索引中而不发生冲突。
当语料库超出本地文件的承载能力、多个应用程序共用一个索引,或者导入和查询发生在不同机器上时,它最为合适。
该组件所用服务和协议的权威资料来源。