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.
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.
The following methods are supported:
Method | Parameters | Description |
IndexesList | This operation returns a list of your Pinecone indexes. | |
IndexCreate | TsgcHTTPPineconeIndexCreate | This operation creates a Pinecone index. You can use it to specify the measure of similarity, the dimension of vectors to be stored in the index, the numbers of replicas to use, and more. |
IndexDescribe | Index Name | Get a description of an index. |
IndexDelete | Index Name | This operation deletes an existing index. |
IndexConfigure | Index Name, Replicas, PodType | This operation specifies the pod type and number of replicas for an index. |
The following methods are supported:
Method | Parameters | Description |
CollectionsList | This operation returns a list of your Pinecone collections. | |
CollectionCreate | Collection Name, Source | This operation creates a Pinecone collection. |
CollectionDescribe | Collection Name | Get a description of a collection. |
CollectionDelete | Collection Name | This operation deletes an existing collection. |
The following methods are supported:
Method | Parameters | Description |
VectorsDescribeIndexStats | Index Name, Project Id, Filter | The DescribeIndexStats operation returns statistics about the index's contents, including the vector count per namespace and the number of dimensions. |
VectorsQuery | Index Name, Project Id, Params | The Query operation searches a namespace, using a query vector. It retrieves the ids of the most similar items in a namespace, along with their similarity scores. |
VectorsDelete | Index Name, Project Id, Params | The Delete operation deletes vectors, by id, from a single namespace. You can delete items by their id, from a single namespace. |
VectorsFetch |
Index Name, Project Id, Ids |
The Fetch operation looks up and returns vectors, by ID, from a single namespace. The returned vectors include the vector data and/or metadata. |
VectorsUpdate | Index Name, Project Id, Params | The Update operation updates vector in a namespace. If a value is included, it will overwrite the previous value. If a set_metadata is included, the values of the fields specified in it will be added or overwrite the previous value. |
VectorsUpsert | Index Name, Project Id, Params | The Upsert operation writes vectors into a namespace. If a new value is upserted for an existing vector id, it will overwrite the previous value. |
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;
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;