1. Go to this page and download the library: Download vectorifyai/vectorify-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/ */
vectorifyai / vectorify-php example snippets
use Vectorify\Vectorify;
use Vectorify\Objects\CollectionObject;
use Vectorify\Objects\ItemObject;
use Vectorify\Objects\UpsertObject;
use Vectorify\Objects\QueryObject;
// Initialize the client
$vectorify = new Vectorify('your-api-key');
// Create a collection
$collection = new CollectionObject(
slug: 'invoices',
metadata: [
'customer_name' => ['type' => 'string'],
'status' => [
'type' => 'enum',
'options' => ['draft', 'sent', 'paid'],
]
],
);
// Create items
$items = [
new ItemObject(
id: '123',
data: [
'customer_name' => 'John Doe',
'status' => 'draft',
'amount' => '100',
'currency' => 'USD',
'due_date' => '2023-10-01'
],
metadata: [
'customer_name' => 'John Doe',
'status' => 'draft'
],
tenant: 987,
url: 'https://example.com/invoice/123',
),
];
// Upsert data
$upsertObject = new UpsertObject($collection, $items);
$success = $vectorify->upserts->create($upsertObject);
if ($success) {
echo "Data upserted successfully!\n";
}
// Query data
$queryObject = new QueryObject(
text: 'how many invoices are in draft status?',
collections: ['invoices'],
tenant: 987,
identifier: [
'id' => '123',
'name' => 'John Doe',
'email' => '[email protected]',
]
);
$result = $vectorify->query->send($queryObject);
if ($result !== false) {
print_r($result);
}
$upsertObject = new UpsertObject($collection, $items);
$success = $vectorify->upserts->create($upsertObject);
$queryObject = new QueryObject('your question here');
$result = $vectorify->query->send($queryObject);
$vectorify = new Vectorify('your-api-key', 60); // 60 seconds timeout
define('VECTORIFY_DEBUG', true);
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.