Delphi Pinecone API 클라이언트

· 컴포넌트

sgcWebSockets 2023.6.0부터 Pinecone API를 지원해요.

Pinecone.io

Pinecone은 벡터 데이터를 쉽고 강력하게 업로드, 쿼리, 삭제할 수 있는 벡터 데이터베이스예요. Pinecone은 서드파티가 자신의 애플리케이션에 Pinecone을 통합할 수 있는 공개 API를 제공해요. TsgcHTTP_API_Pinecone 컴포넌트는 Pinecone API를 래핑한 컴포넌트예요.

설정

시작하기 전에 Pinecone 웹사이트에 등록하고 API 키를 발급받아야 해요. 이 API 키는 API 요청을 보낼 때 사용되며, TsgcHTTP_API_Pinecone 컴포넌트의 PineconeOptions.ApiKey 속성에 설정해야 해요.

메서드

다음 메서드를 지원해요:

  1.  인덱스 작업: 인덱스를 목록 조회, 생성, 상세 조회, 삭제 및 설정할 수 있어요.
  2. 컬렉션 작업: 컬렉션을 목록 조회, 생성, 상세 조회할 수 있어요.
  3. 벡터 작업: 벡터 쿼리, 삭제, 업데이트, upsert 및 가져오기를 지원해요.

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 클라이언트를 사용해요.