PHP code example of claudiogs16 / laravel-sdk-qdrant

1. Go to this page and download the library: Download claudiogs16/laravel-sdk-qdrant 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/ */

    

claudiogs16 / laravel-sdk-qdrant example snippets


use Claudiogs16\LarQ\Qdrant\Client;

$client = new Client();

// Raw HTTP calls
$response = $client->get('/collections');
$response = $client->put('/collections/my-collection', [...]);
$response = $client->post('/collections/my-collection/points/search', [...]);

use Claudiogs16\LarQ\Qdrant\Collections\CreateCollection;
use Claudiogs16\LarQ\Qdrant\Collections\ListCollections;
use Claudiogs16\LarQ\Qdrant\Collections\GetCollection;
use Claudiogs16\LarQ\Qdrant\Collections\UpdateCollection;
use Claudiogs16\LarQ\Qdrant\Collections\DeleteCollection;

CreateCollection::make()->handle('my-collection', [
    'vectors' => ['size' => 1536, 'distance' => 'Cosine'],
]);

$collections = ListCollections::make()->handle();
$info = GetCollection::make()->handle('my-collection');

use Claudiogs16\LarQ\Qdrant\Points\UpsertPoints;
use Claudiogs16\LarQ\Qdrant\Points\SearchPoints;
use Claudiogs16\LarQ\Qdrant\Points\ScrollPoints;
use Claudiogs16\LarQ\Qdrant\Points\CountPoints;
use Claudiogs16\LarQ\Qdrant\Points\DeletePoints;
use Claudiogs16\LarQ\Qdrant\Points\RecommendPoints;

// Upsert
UpsertPoints::make()->handle('my-collection', [
    [
        'id' => 1,
        'vector' => [0.1, 0.2, ...],
        'payload' => ['title' => 'Document 1'],
    ],
]);

// Search
$results = SearchPoints::make()->handle('my-collection', [
    'vector' => [0.1, 0.2, ...],
    'limit' => 10,
]);

// Count
$count = CountPoints::make()->handle('my-collection');

use Claudiogs16\LarQ\Qdrant\Payload\SetPayload;
use Claudiogs16\LarQ\Qdrant\Payload\DeletePayload;
use Claudiogs16\LarQ\Qdrant\Payload\ClearPayload;

use Claudiogs16\LarQ\Qdrant\Index\CreateIndex;
use Claudiogs16\LarQ\Qdrant\Index\DeleteIndex;

use Claudiogs16\LarQ\Qdrant\Vectors\DeleteVector;

use Claudiogs16\LarQ\Embedders\OpenAIEmbedder;
use Claudiogs16\LarQ\Embedders\GeminiEmbedder;
use Claudiogs16\LarQ\Embedders\OpenRouterEmbedder;

// OpenAI
$embedder = new OpenAIEmbedder();
$vector = $embedder->embed('Some text to embed');

// Gemini
$gemini = new GeminiEmbedder();
$vector = $gemini->embed('Some text to embed');

// OpenRouter
$openrouter = new OpenRouterEmbedder();
$vector = $openrouter->embed('Some text to embed');

use Claudiogs16\LarQ\Traits\HasVectors;

class Document extends Model
{
    use HasVectors;

    // Optional overrides:
    protected function getVectorText(): string { ... }
    protected function getVectorPayload(): array { ... }
    protected function getVectorId(): string|int { ... }
    protected function getVectorCollection(): string { ... }
    protected function getEmbedder(): EmbedderInterface { ... }
}

$document->upsertToQdrant();
bash
php artisan vendor:publish --tag=larq-config