Delphi Pinecone API client

From sgcWebSockets 2023.6.0 Pinecone API is supported.

Pinecone.io

Pinecone is a vector database that allows to upload / query / delete vector data in an easy and powerful way.Pinecone has a public API that allows third-parties to integrate pinecone into it's own applications. The component TsgcHTTP_API_Pinecone is a wrapper over the Pinecone API.

Configuration

Before start, you must register in Pinecone website and request an API. This API key is used to send the API requests and must be set in the property PineconeOptions.ApiKey of the TsgcHTTP_API_Pinecone component.

Methods

The following methods are supported:

  1.  Index Operations: allows to list, create, describe, delete and configure indexes.
  2. Collection Operations: you can list, create and describe operations.
  3. Vector Operations: supports query, delete, update, upsert and fetch the vectors.

How to UPSERT

Find below an example of UPSERT a single vector with the Id = "id1". 

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; 

How to Query

Find below an example of QUERY a single vector. 

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; 

Demo

The following demo shows how the Pinecone API works, the demo is compiled for Windows and it's using the sgcWebSockets Pinecone API client.

sgcPinecone
2.8 mb
×
Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

sgcWebSockets 2023.6
Customizing OpenAI with your Data (2 / 2)

Related Posts