Giter Site home page Giter Site logo

govtribe / pinecone-php Goto Github PK

View Code? Open in Web Editor NEW

This project forked from probots-io/pinecone-php

0.0 0.0 0.0 498 KB

A beautiful, extendable PHP Package to communicate with your pinecone.io indices, collections and vectors.

Home Page: https://probots.io

License: MIT License

PHP 100.00%

pinecone-php's Introduction

Pinecone PHP

A beautiful, extendable PHP Package to communicate with your pinecone.io indices, collections and vectors, powered by Saloon.

Info This package is still in active development, but is already used in some production scenarios. Check Todo list below for more information what's missing.

probots.io

Introduction

This API provides a feature rich, elegant baseline for working with the pinecone.io API. Developers can install and leverage this API to help them integrate pinecone.io easily and beautifully.

Installation

composer require probots-io/pinecone-php

Features

Currently supports all of the available endpoints in the pinecone.io API based on the official documentation

Authentication

Authentication via Api Key is the only available authentication methods currently supported. First, you will need to create an Api Key in your pinecone.io instance.

use \Probots\Pinecone\Client as Pinecone;


$apiKey = 'YOUR_PINECONE_API_KEY';
$environment = 'YOU_PINECONE_ENVIRONMENT';

// Initialize Pinecone
$pinecone = new Pinecone($apiKey, $environment);

// Now you are ready to make requests, all requests will be authenticated automatically.

Responses

All responses are returned as a Response object. Please check the Saloon documentation to see all available methods.

Index Operations

Work(s) with your indices.

Create Index

Pinecone Docs

$response = $pinecone->index()->create(
    name: 'my-index',
    dimension: 1536
);

if($response->successful()) {
    // 
}

Describe Index

Pinecone Docs

$response = $pinecone->index('my-index')->describe();

if($response->successful()) {
    // 
}

List Indices

Pinecone Docs

$response = $pinecone->index()->list();

if($response->successful()) {
    // 
}

Configure Index

Pinecone Docs

$response = $pinecone->index('my-index')->configure(
    pod_type: 'p1.x1',
    replicas: 1
);

if($response->successful()) {
    // 
}

Delete Index

Pinecone Docs

$response = $pinecone->index('my-index')->delete();

if($response->successful()) {
    // 
}

Collection Operations

Work(s) with your collections too.

Create Collection

Pinecone Docs

$response = $pinecone->collections()->create(
    name: 'my-collection',
    source: 'my-index'
);

if($response->successful()) {
    // 
}

Describe Collection

Pinecone Docs

$response = $pinecone->collections('my-collection')->describe();

if($response->successful()) {
    // 
}

List Collections

Pinecone Docs

$response = $pinecone->collections()->list();

if($response->successful()) {
    // 
}

Delete Collections

Pinecone Docs

$response = $pinecone->collections('my-collection')->delete();

if($response->successful()) {
    // 
}

Vector Operations

Vectors are the basic unit of data in Pinecone. Use them.

Describe Index Stats

TBD

$response = $pinecone->index('my-index')->vectors()->stats();

if($response->successful()) {
    // 
}

Update Vector

Pinecone Docs

$response = $pinecone->index('my-index')->vectors()->update(
    id: 'vector_1',
    values: array_fill(0, 128, 0.14),
    setMetadata: [
        'meta1' => 'value1',
    ]
);

if($response->successful()) {
    // 
}

Upsert Vectors

Pinecone Docs

$response = $pinecone->index('my-index')->vectors()->upsert(vectors: [
    'id' => 'vector_1',
    'values' => array_fill(0, 128, 0.14),
    'metadata' => [
        'meta1' => 'value1',
    ]
]);

if($response->successful()) {
    // 
}

Query Vectors

Pinecone Docs

$response = $pinecone->index('my-index')->vectors()->query(
    vector: array_fill(0, 128, 0.12),
    topK: 1,
);

if($response->successful()) {
    // 
}

Delete Vectors

Pinecone Docs

$response = $pinecone->index('my-index')->vectors()->delete(
    deleteAll: true
);

if($response->successful()) {
    // 
}

Fetch Vectors

Pinecone Docs

$response = $pinecone->index('my-index')->vectors()->fetch([
    'vector_1', 'vector_2'
]);

if($response->successful()) {
    // 
}

Testing

Testing is done via PestPHP. You can run the tests by running ./vendor/bin/pest in the root of the project. Copy .env.example to .env and update accordingly.

Credits

License

The MIT License (MIT). Please see License File for more information.

TODO:

  • validate parameters based on API docs - needs more checking
  • Implement Custom Exceptions
  • Add failure tests
  • Add some examples
  • Finish docs

pinecone-php's People

Contributors

boralp avatar derpoho avatar ianfortier avatar sammyjo20 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.