从 sgcWebSockets 2023.6.0 起,支持 Pinecone API。
Pinecone 是一个向量数据库,可以轻松而强大地上传/查询/删除向量数据。Pinecone 提供公共 API,允许第三方将 Pinecone 集成到其自己的应用程序中。TsgcHTTP_API_Pinecone 组件是对 Pinecone API 的封装。
配置
开始之前,您必须在 Pinecone 网站注册并申请 API 密钥。此 API 密钥用于发送 API 请求,必须在 TsgcHTTP_API_Pinecone 组件的 PineconeOptions.ApiKey 属性中设置。
方法
支持以下方法:
- 索引操作:允许列出、创建、描述、删除和配置索引。
- 集合操作:可以列出、创建和描述操作。
- 向量操作:支持查询、删除、更新、插入更新和获取向量。
如何进行 UPSERT(插入更新)
以下示例演示如何对 Id 为 "id1" 的单个向量进行 UPSERT 操作。
procedure UpsertPinecone(const aIndexName, aProjectId: string; const aVector: Array of Double);
var
oPinecone: TsgcHTTP_API_Pinecone;
oParams: TsgcHTTPPineconeVectorUpserts;
oVectors: TsgcArrayOfVectorUpsert;
begin
oPinecone := TsgcHTTP_API_Pinecone.Create(nil);
Try
oPinecone.PineconeOptions.API := 'your-api-key';
oParams := TsgcHTTPPineconeVectorUpserts.Create;
Try
SetLength(oVectors, 1);
oVectors[0] := TsgcHTTPPineconeVectorUpsert.Create;
oVectors[0].Id := 'id1';
oVectors[0].Values := aVector;
oParams.Vectors := oVectors;
Pinecone.VectorsUpsert(aIndexName, aProjectId, oParams);
Finally
oParams.Free;
End;
Finally
oPinecone.Free;
End;
end;
如何进行查询
以下示例演示如何查询单个向量。
procedure QueryPinecone(const aIndexName, aProjectId: string; const aVector: Array of Double);
var
oParams: TsgcHTTPPineconeVectorQuery;
begin
oParams := TsgcHTTPPineconeVectorQuery.Create;
Try
oParams.Vector := aVector;
Pinecone.VectorsQuery(aIndexName, aProjectId, oParams);
Finally
oParams.Free;
End;
end;
演示
以下演示展示了 Pinecone API 的工作原理,该演示针对 Windows 编译,使用 sgcWebSockets Pinecone API 客户端。
