1. Go to this page and download the library: Download hkulekci/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/ */
hkulekci / qdrant example snippets
use Qdrant\Qdrant;
use Qdrant\Config;
use Qdrant\Http\Builder;
$config = new Config(QDRANT_HOST);
$config->setApiKey(QDRANT_API_KEY);
$transport = (new Builder())->build($config);
$client = new Qdrant($transport);
use Qdrant\Endpoints\Collections;
use Qdrant\Models\Request\CreateCollection;
use Qdrant\Models\Request\VectorParams;
$createCollection = new CreateCollection();
$createCollection->addVector(new VectorParams(1536, VectorParams::DISTANCE_COSINE), 'content');
$response = $client->collections('contents')->create($createCollection);
use Qdrant\Models\PointsStruct;
use Qdrant\Models\PointStruct;
use Qdrant\Models\VectorStruct;
$openai = OpenAI::client(OPENAI_API_KEY);
$query = 'sustainable agricultural startups';
$response = $openai->embeddings()->create([
'model' => 'text-embedding-ada-002',
'input' => $query,
]);
$embedding = array_values($response->embeddings[0]->embedding);
$points = new PointsStruct();
$points->addPoint(
new PointStruct(
(int) $imageId,
new VectorStruct($embedding, 'content'),
[
'id' => 1,
'meta' => 'Meta data'
]
)
);
$client->collections('contents')->points()->upsert($points);
use Qdrant\Models\Filter\Condition\MatchString;
use Qdrant\Models\Filter\Filter;
use Qdrant\Models\Request\SearchRequest;
use Qdrant\Models\VectorStruct;
$searchRequest = (new SearchRequest(new VectorStruct($embedding, 'elev_pitch')))
->setFilter(
(new Filter())->addMust(
new MatchString('name', 'Palm')
)
)
->setLimit(10)
->setParams([
'hnsw_ef' => 128,
'exact' => false,
])
->setWithPayload(true);
$response = $client->collections('contents')->points()->search($searchRequest);