sgcWebSockets 2023.6.0 から Pinecone API がサポートされています。
Pinecone はベクトルデータを簡単かつ強力な方法でアップロード・クエリ・削除できるベクトルデータベースです。Pinecone はサードパーティが Pinecone を自身のアプリケーションに統合できるパブリック API を公開しています。コンポーネント 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 の動作を示すもので、sgcWebSockets Pinecone API クライアントを使用して Windows 向けにコンパイルされています。
