PHP code example of scotteuser / pinecone-php

1. Go to this page and download the library: Download scotteuser/pinecone-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

scotteuser / pinecone-php example snippets


use \Probots\Pinecone\Client as Pinecone;

$apiKey = 'YOUR_PINECONE_API_KEY';

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

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

use \Probots\Pinecone\Client as Pinecone;

$apiKey = 'YOUR_PINECONE_API_KEY';
$pinecone = new Pinecone($apiKey);

// all control methods are available now, create an index or similar
// e.g. $pinecone->control()->index()

// later on you can provide the index
$pinecone->setIndexHost('INDEX_HOST_FROM_PINECONE');

// data methods are available now

// e.g. $pinecone->data()->vectors()

use \Probots\Pinecone\Client as Pinecone;

$apiKey = 'YOUR_PINECONE_API_KEY';
$indexHost = 'INDEX_HOST_FROM_PINECONE';

$pinecone = new Pinecone($apiKey, $indexHost);

// all control AND data methods are available now

$response = $pinecone->control()->index('my-index')->createPod(
    dimension: 1536,
    metric: 'cosine',
    podType: 'p1.x1',
    replicas: 1
    // ... more options    
);

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

$response = $pinecone->control()->index('my-index')->createServerless(
    dimension: 1536,
    metric: 'cosine',
    cloud: 'aws',
    region: 'us-west-2'
    // ... more options    
);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

$response = $pinecone->data()->vectors()->stats();

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

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

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

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

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

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

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

$response = $pinecone->data()->vectors()->delete(
    deleteAll: true
);

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

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

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