### Install Qdrant PHP Client Source: https://github.com/hkulekci/qdrant-php/blob/main/README.md Install the Qdrant PHP client using composer. This is the first step to integrating Qdrant into your PHP project. ```shell composer require hkulekci/qdrant ``` -------------------------------- ### Install Qdrant PHP Client with Composer Source: https://context7.com/hkulekci/qdrant-php/llms.txt Install the Qdrant PHP client and required dependencies using Composer. Ensure you have an HTTP client like Symfony HTTP Client and a PSR-7 factory like Nyholm PSR7. ```bash composer require hkulekci/qdrant symfony/http-client nyholm/psr7 ``` -------------------------------- ### Create a Qdrant Collection Source: https://github.com/hkulekci/qdrant-php/blob/main/README.md Create a new collection in Qdrant with specified vector parameters. This example defines a collection named 'contents' with cosine distance for 1536-dimensional vectors. ```php 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); ``` -------------------------------- ### Query Points with `Query::query()` - Recommendation Source: https://context7.com/hkulekci/qdrant-php/llms.txt Execute recommendation queries using positive and negative example point IDs. This method replaces the deprecated `recommend()` method and requires importing `QueryRequest`. ```php use Qdrant\Models\Request\Points\QueryRequest; // --- Recommendation query (positive/negative examples) --- $recRequest = (new QueryRequest()) ->setQuery([ 'recommend' => [ 'positive' => [1, 5], // point IDs to use as positive examples 'negative' => [3], // point IDs to push away from ] ]) ->setUsing('content') ->setLimit(5) ->setWithPayload(true); $recResponse = $client->collections('articles')->points()->query()->query($recRequest); ``` -------------------------------- ### List, Inspect, and Check Collection Existence Source: https://context7.com/hkulekci/qdrant-php/llms.txt Provides methods to list all collections, get detailed information about a specific collection, and check if a collection exists. ```APIDOC ## List and Inspect Collections — `Collections::list()`, `Collections::info()`, `Collections::exists()` Retrieve all collections, inspect a single collection's configuration and statistics, or check existence. ```php // List all collections $all = $client->collections()->list(); foreach ($all['result']['collections'] as $col) { echo $col['name'] . PHP_EOL; } // Get detailed info for a specific collection $info = $client->collections('articles')->info(); echo $info['result']['status']; // 'green' echo $info['result']['vectors_count']; // total vectors stored // Check existence $exists = $client->collections('articles')->exists(); // $exists['result']['exists'] === true|false ``` ``` -------------------------------- ### Search Points with OpenAI Embeddings Source: https://github.com/hkulekci/qdrant-php/blob/main/README.md Search for points using embeddings generated by OpenAI. This example demonstrates generating embeddings for a query and then performing a search, followed by iterating through results. ```php $openai = OpenAI::client(OPENAI_API_KEY); $query = 'lorem ipsum dolor sit amed'; $response = $openai->embeddings()->create([ 'model' => 'text-embedding-ada-002', 'input' => $query, ]); $embedding = array_values($response->embeddings[0]->embedding); $searchRequest = (new SearchRequest(new VectorStruct($embedding, 'content'))) ->setLimit(10) ->setParams([ 'hnsw_ef' => 128, 'exact' => false, ]) ->setWithPayload(true); $response = $client->collections('contents')->points()->search($searchRequest); foreach ($response['result'] as $item) { echo $item['score'] . ';' . $item['payload']['id'] . ';' . $item['payload']['meta_data'] . PHP_EOL; } ``` -------------------------------- ### List, Inspect, and Check Collection Existence Source: https://context7.com/hkulekci/qdrant-php/llms.txt Retrieve a list of all collections, get detailed information about a specific collection, or check if a collection exists. Useful for managing and monitoring collections. ```php // List all collections $all = $client->collections()->list(); foreach ($all['result']['collections'] as $col) { echo $col['name'] . PHP_EOL; } // Get detailed info for a specific collection $info = $client->collections('articles')->info(); echo $info['result']['status']; // 'green' echo $info['result']['vectors_count']; // total vectors stored // Check existence $exists = $client->collections('articles')->exists(); // $exists['result']['exists'] === true|false ``` -------------------------------- ### Search Points with Filter Source: https://github.com/hkulekci/qdrant-php/blob/main/README.md Perform a search operation on points within a collection, applying a filter to narrow down results. This example searches for points matching 'Palm' in the 'name' field. ```php 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); ``` -------------------------------- ### Count Points Source: https://context7.com/hkulekci/qdrant-php/llms.txt Get the total number of points in a collection or count points that match a specified filter. This is useful for understanding collection size or subset sizes. ```APIDOC ## Count Points — `Points::count()` Count total points or points matching a filter. ```php use Qdrant\Models\Filter\Filter; use Qdrant\Models\Filter\Condition\MatchString; // Count all $response = $client->collections('articles')->points()->count(); echo $response['result']['count']; // e.g. 10540 // Count with filter (exact count) $filter = (new Filter())->addMust(new MatchString('tags', 'eco')); $response = $client->collections('articles')->points()->count($filter, exact: true); echo $response['result']['count']; ``` ``` -------------------------------- ### Count Points — `Points::count()` Source: https://context7.com/hkulekci/qdrant-php/llms.txt Get the total number of points in a collection or the count of points that match a given filter. The `exact` parameter can be set to `true` for a precise count, which may be slower for large collections. ```php use Qdrant\Models\Filter\Filter; use Qdrant\Models\Filter\Condition\MatchString; // Count all $response = $client->collections('articles')->points()->count(); echo $response['result']['count']; // e.g. 10540 // Count with filter (exact count) $filter = (new Filter())->addMust(new MatchString('tags', 'eco')); $response = $client->collections('articles')->points()->count($filter, exact: true); echo $response['result']['count']; ``` -------------------------------- ### Connect to Qdrant Source: https://github.com/hkulekci/qdrant-php/blob/main/README.md Establish a connection to the Qdrant instance using configuration details like host and API key. Ensure you have the `config.php` file with necessary credentials. ```php include __DIR__ . "/../vendor/autoload.php"; include_once 'config.php'; 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); ``` -------------------------------- ### Client Initialization Source: https://context7.com/hkulekci/qdrant-php/llms.txt Initializes the Qdrant client with connection parameters and an optional API key. ```APIDOC ## Client Initialization — `Qdrant`, `Config`, `Http\Builder` `Config` holds the connection parameters (host, port, optional API key). `Http\Builder` wires together the PSR-18 HTTP client and the config into a `Transport`, which is passed to the main `Qdrant` client. ```php use Qdrant\Qdrant; use Qdrant\Config; use Qdrant\Http\Builder; $config = new Config('http://localhost', 6333); $config->setApiKey('your-api-key'); // optional, for Qdrant Cloud $transport = (new Builder())->build($config); $client = new Qdrant($transport); ``` ``` -------------------------------- ### Initialize Qdrant Client Source: https://context7.com/hkulekci/qdrant-php/llms.txt Initialize the Qdrant client by configuring connection parameters and building the transport layer. The API key is optional and used for Qdrant Cloud. ```php use Qdrant\Qdrant; use Qdrant\Config; use Qdrant\Http\Builder; $config = new Config('http://localhost', 6333); $config->setApiKey('your-api-key'); // optional, for Qdrant Cloud $transport = (new Builder())->build($config); $client = new Qdrant($transport); ``` -------------------------------- ### Create and Manage Custom Sharding Keys Source: https://context7.com/hkulekci/qdrant-php/llms.txt Use these methods to create and delete custom sharding keys for tenant-based data isolation. Ensure the `CreateShardKey` or `DeleteShardKey` models are imported. ```php use Qdrant\Models\Request\CollectionConfig\CreateShardKey; use Qdrant\Models\Request\CollectionConfig\DeleteShardKey; // Create a custom shard key $createShard = new CreateShardKey( shardKey: 'tenant-001', shardNumber: 2, replicationFactor: 1, placement: [1, 2] // peer IDs ); $client->collections('articles')->shards()->create($createShard); // Delete a shard key $deleteShard = new DeleteShardKey('tenant-001'); $client->collections('articles')->shards()->delete($deleteShard); ``` -------------------------------- ### Manage Collection Snapshots Source: https://context7.com/hkulekci/qdrant-php/llms.txt Use these methods to create, list, download, restore, and delete snapshots for individual collections. Ensure the 'wait' parameter is set to 'true' for synchronous operations. ```php // Create a snapshot $response = $client->collections('articles')->snapshots()->create([], ['wait' => 'true']); $snapshotName = $response['result']['name']; // e.g. "articles-1715000000" ``` ```php // List snapshots $list = $client->collections('articles')->snapshots()->list(); foreach ($list['result'] as $snap) { echo $snap['name'] . ' size=' . $snap['size'] . PHP_EOL; } ``` ```php // Download snapshot (returns binary stream response) $download = $client->collections('articles')->snapshots()->download($snapshotName); ``` ```php // Restore (recover) a collection from snapshot $recover = $client->collections('articles')->snapshots()->recover(); ``` ```php // Delete snapshot $client->collections('articles')->snapshots()->delete($snapshotName); ``` -------------------------------- ### Manage Collection Aliases Source: https://context7.com/hkulekci/qdrant-php/llms.txt Manage zero-downtime collection aliases for blue/green deployments. Create, switch, or delete aliases atomically. ```php use Qdrant\Models\Request\AliasActions; // Create or switch an alias $actions = new AliasActions(); $actions->add('articles-live', 'articles-v2'); // alias → collection $actions->delete('articles-live'); // remove old alias (atomic swap) $response = $client->collections('articles-v2')->aliases()->actions($actions); ``` ```php // List all aliases on a collection $aliases = $client->collections('articles-v2')->aliases()->aliases(); ``` ```php // List all aliases globally $allAliases = $client->aliases()->all(); ``` -------------------------------- ### Manage Storage-Level Snapshots Source: https://context7.com/hkulekci/qdrant-php/llms.txt These methods manage full-storage snapshots that encompass all collections. Use 'wait' => 'true' for synchronous snapshot creation. ```php // List storage snapshots $list = $client->snapshots()->get(); ``` ```php // Create a storage-wide snapshot $response = $client->snapshots()->create(['wait' => 'true']); $name = $response['result']['name']; ``` ```php // Download storage snapshot $client->snapshots()->download($name); ``` ```php // Delete storage snapshot $client->snapshots()->delete($name); ``` -------------------------------- ### Storage-Level Snapshots Source: https://context7.com/hkulekci/qdrant-php/llms.txt Manage full-storage snapshots that cover all collections within the Qdrant instance. ```APIDOC ## Storage-Level Snapshots — `Snapshots` ### Description Manage full-storage snapshots covering all collections. ### List Storage Snapshots ```php $list = $client->snapshots()->get(); ``` ### Create Storage Snapshot ```php $response = $client->snapshots()->create(['wait' => 'true']); $name = $response['result']['name']; ``` ### Download Storage Snapshot ```php $client->snapshots()->download($name); ``` ### Delete Storage Snapshot ```php $client->snapshots()->delete($name); ``` ``` -------------------------------- ### Create a New Collection Source: https://context7.com/hkulekci/qdrant-php/llms.txt Define and create a new Qdrant collection with specified vector parameters, distance metric, HNSW configuration, and quantization settings. Supports named vector spaces. ```php use Qdrant\Models\Request\CreateCollection; use Qdrant\Models\Request\VectorParams; use Qdrant\Models\Request\CollectionConfig\HnswConfig; use Qdrant\Models\Request\CollectionConfig\ScalarQuantization; $createCollection = new CreateCollection(); $createCollection->addVector( new VectorParams(1536, VectorParams::DISTANCE_COSINE), 'content' // named vector space ); $createCollection->addVector( new VectorParams(512, VectorParams::DISTANCE_EUCLID), 'thumbnail' ); $createCollection->setHnswConfig( (new HnswConfig())->setM(16)->setEfConstruct(100) ); $createCollection->setQuantizationConfig( new ScalarQuantization('int8', 0.99, true) // type, quantile, always_ram ); $createCollection->setReplicationFactor(2); $createCollection->setOnDiskPayload(false); $response = $client->collections('articles')->create($createCollection); // $response['status'] === 'ok' // $response['result'] === true ``` -------------------------------- ### Inspect Cluster Topology and Manage Shards Source: https://context7.com/hkulekci/qdrant-php/llms.txt Provides methods for inspecting cluster topology and performing shard operations like moving, replicating, or dropping shards. Ensure necessary models are imported. ```php use Qdrant\Models\Request\UpdateCollectionCluster; use Qdrant\Models\Request\ClusterUpdate\MoveShardOperation; use Qdrant\Models\Request\ClusterUpdate\ReplicateShardOperation; use Qdrant\Models\Request\ClusterUpdate\DropReplicaOperation; // Global cluster status $clusterInfo = $client->cluster()->info(); // Collection-level cluster info $colCluster = $client->collections('articles')->cluster()->info(); // Move shard between peers $moveOp = new MoveShardOperation( shardId: 0, toPeerId: 2, fromPeerId: 1 ); $client->collections('articles')->cluster()->update( new UpdateCollectionCluster($moveOp) ); // Replicate a shard to another peer $replicateOp = new ReplicateShardOperation( shardId: 0, toPeerId: 3, fromPeerId: 1 ); $client->collections('articles')->cluster()->update( new UpdateCollectionCluster($replicateOp) ); // Drop a replica $dropOp = new DropReplicaOperation(shardId: 0, peerId: 3); $client->collections('articles')->cluster()->update( new UpdateCollectionCluster($dropOp) ); // Remove a peer from the cluster $client->cluster()->removePeer(peerId: 2, queryParams: ['force' => 'true']); ``` -------------------------------- ### Collection Aliases Source: https://context7.com/hkulekci/qdrant-php/llms.txt Manage zero-downtime collection aliases for blue/green deployments using `Aliases::actions()` and `Aliases::aliases()`. ```APIDOC ## Collection Aliases — `Aliases::actions()`, `Aliases::aliases()` Manage zero-downtime collection aliases for blue/green deployments. ```php use Qdrant\Models\Request\AliasActions; // Create or switch an alias $actions = new AliasActions(); $actions->add('articles-live', 'articles-v2'); // alias → collection $actions->delete('articles-live'); // remove old alias (atomic swap) $response = $client->collections('articles-v2')->aliases()->actions($actions); // List all aliases on a collection $aliases = $client->collections('articles-v2')->aliases()->aliases(); // List all aliases globally $allAliases = $client->aliases()->all(); ``` ``` -------------------------------- ### Collection Snapshots Source: https://context7.com/hkulekci/qdrant-php/llms.txt Manage snapshots for individual collections, including creation, listing, downloading, restoring, and deletion. ```APIDOC ## Collection Snapshots — `Collections\Snapshots` ### Description Create, list, download, and restore collection snapshots for backup and migration. ### Create Snapshot ```php $response = $client->collections('articles')->snapshots()->create([], ['wait' => 'true']); $snapshotName = $response['result']['name']; ``` ### List Snapshots ```php $list = $client->collections('articles')->snapshots()->list(); foreach ($list['result'] as $snap) { echo $snap['name'] . ' size=' . $snap['size'] . PHP_EOL; } ``` ### Download Snapshot ```php $download = $client->collections('articles')->snapshots()->download($snapshotName); ``` ### Restore Snapshot ```php $recover = $client->collections('articles')->snapshots()->recover(); ``` ### Delete Snapshot ```php $client->collections('articles')->snapshots()->delete($snapshotName); ``` ``` -------------------------------- ### Batch Upsert Points with `Points::batch()` Source: https://context7.com/hkulekci/qdrant-php/llms.txt Efficiently insert multiple points using the columnar batch format for better performance. Set `wait` to 'true' for synchronous acknowledgment. Requires importing `PointsBatch`, `PointStruct`, and `VectorStruct`. ```php use Qdrant\Models\Request\PointsBatch; use Qdrant\Models\PointStruct; use Qdrant\Models\VectorStruct; $batch = new PointsBatch(); $batch->addPoint(PointStruct::createFromArray([ 'id' => 1, 'vector' => new VectorStruct([0.1, 0.2, 0.3], 'image'), 'payload' => ['color' => 'red', 'size' => 'large'], ])); $batch->addPoint(PointStruct::createFromArray([ 'id' => 2, 'vector' => new VectorStruct([0.4, 0.5, 0.6], 'image'), 'payload' => ['color' => 'blue', 'size' => 'small'], ])); $batch->addPoint(PointStruct::createFromArray([ 'id' => 3, 'vector' => new VectorStruct([0.7, 0.8, 0.9], 'image'), 'payload' => ['color' => 'green', 'size' => 'medium'], ])); $response = $client->collections('products')->points()->batch($batch, ['wait' => 'true']); // $response['status'] === 'ok' ``` -------------------------------- ### Cluster Info and Management Source: https://context7.com/hkulekci/qdrant-php/llms.txt Inspect cluster topology and perform shard operations across the Qdrant cluster. ```APIDOC ## Cluster Info and Management — `Cluster`, `Collections\Cluster` ### Description Inspect cluster topology and perform shard operations. ### Global Cluster Info ```php $clusterInfo = $client->cluster()->info(); ``` ### Collection-Level Cluster Info ```php $colCluster = $client->collections('articles')->cluster()->info(); ``` ### Move Shard ```php use Qdrant\Models\Request\UpdateCollectionCluster; use Qdrant\Models\Request\ClusterUpdate\MoveShardOperation; $moveOp = new MoveShardOperation( shardId: 0, toPeerId: 2, fromPeerId: 1 ); $client->collections('articles')->cluster()->update( new UpdateCollectionCluster($moveOp) ); ``` ### Replicate Shard ```php use Qdrant\Models\Request\ClusterUpdate\ReplicateShardOperation; $replicateOp = new ReplicateShardOperation( shardId: 0, toPeerId: 3, fromPeerId: 1 ); $client->collections('articles')->cluster()->update( new UpdateCollectionCluster($replicateOp) ); ``` ### Drop Replica ```php use Qdrant\Models\Request\ClusterUpdate\DropReplicaOperation; $dropOp = new DropReplicaOperation(shardId: 0, peerId: 3); $client->collections('articles')->cluster()->update( new UpdateCollectionCluster($dropOp) ); ``` ### Remove Peer ```php $client->cluster()->removePeer(peerId: 2, queryParams: ['force' => 'true']); ``` ``` -------------------------------- ### Query Points Source: https://context7.com/hkulekci/qdrant-php/llms.txt The universal query endpoint supporting nearest-neighbor search, recommendation by point IDs, discover, fusion, sample, and multi-stage prefetch. Replaces the deprecated `search()` and `recommend()` methods. ```APIDOC ## Query Points (Recommended) — `Query::query()` The universal query endpoint supporting nearest-neighbor search, recommendation by point IDs, discover, fusion, sample, and multi-stage prefetch. Replaces the deprecated `search()` and `recommend()` methods. ```php use Qdrant\Models\Request\Points\QueryRequest; use Qdrant\Models\Filter\Filter; use Qdrant\Models\Filter\Condition\MatchString; use Qdrant\Models\Filter\Condition\Range; // --- Nearest-neighbor vector search --- $queryRequest = (new QueryRequest()) ->setQuery(['nearest' => [0.12, 0.53, /* ...1536 dims */]]) ->setUsing('content') // named vector space ->setFilter( (new Filter()) ->addMust(new MatchString('tags', 'eco')) ->addMust(new Range('year', ['gte' => 2020])) ) ->setParams(['hnsw_ef' => 128, 'exact' => false]) ->setScoreThreshold(0.7) ->setLimit(10) ->setOffset(0) ->setWithPayload(true) ->setWithVector(false); $response = $client->collections('articles')->points()->query()->query($queryRequest); foreach ($response['result']['points'] as $point) { echo $point['id'] . ' score=' . $point['score'] . ' title=' . $point['payload']['title'] . PHP_EOL; } // --- Recommendation query (positive/negative examples) --- $recRequest = (new QueryRequest()) ->setQuery([ 'recommend' => [ 'positive' => [1, 5], // point IDs to use as positive examples 'negative' => [3], // point IDs to push away from ] ]) ->setUsing('content') ->setLimit(5) ->setWithPayload(true); $recResponse = $client->collections('articles')->points()->query()->query($recRequest); ``` ``` -------------------------------- ### Insert Points into Collection Source: https://github.com/hkulekci/qdrant-php/blob/main/README.md Insert points into a Qdrant collection. This snippet includes generating embeddings using OpenAI and structuring the data for insertion. ```php 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); ``` -------------------------------- ### Shards (Custom Sharding) Source: https://context7.com/hkulekci/qdrant-php/llms.txt Create and manage custom sharding keys for tenant-based data isolation within collections. ```APIDOC ## Shards (Custom Sharding) — `Shards::create()`, `Shards::delete()` ### Description Create and manage custom sharding keys for tenant-based data isolation. ### Create Shard Key ```php use Qdrant\Models\Request\CollectionConfig\CreateShardKey; $createShard = new CreateShardKey( shardKey: 'tenant-001', shardNumber: 2, replicationFactor: 1, placement: [1, 2] // peer IDs ); $client->collections('articles')->shards()->create($createShard); ``` ### Delete Shard Key ```php use Qdrant\Models\Request\CollectionConfig\DeleteShardKey; $deleteShard = new DeleteShardKey('tenant-001'); $client->collections('articles')->shards()->delete($deleteShard); ``` ``` -------------------------------- ### Create Collection Source: https://context7.com/hkulekci/qdrant-php/llms.txt Defines and creates a new named vector collection with specified parameters. ```APIDOC ## Create a Collection — `Collections::create()` Defines a new named vector collection with one or more named vector spaces, distance metric, optional quantization, HNSW tuning, and WAL configuration. ```php use Qdrant\Models\Request\CreateCollection; use Qdrant\Models\Request\VectorParams; use Qdrant\Models\Request\CollectionConfig\HnswConfig; use Qdrant\Models\Request\CollectionConfig\ScalarQuantization; $createCollection = new CreateCollection(); $createCollection->addVector( new VectorParams(1536, VectorParams::DISTANCE_COSINE), 'content' // named vector space ); $createCollection->addVector( new VectorParams(512, VectorParams::DISTANCE_EUCLID), 'thumbnail' ); $createCollection->setHnswConfig( (new HnswConfig())->setM(16)->setEfConstruct(100) ); $createCollection->setQuantizationConfig( new ScalarQuantization('int8', 0.99, true) // type, quantile, always_ram ); $createCollection->setReplicationFactor(2); $createCollection->setOnDiskPayload(false); $response = $client->collections('articles')->create($createCollection); // $response['status'] === 'ok' // $response['result'] === true ``` ``` -------------------------------- ### Query Points with `Query::query()` - Nearest Neighbor Search Source: https://context7.com/hkulekci/qdrant-php/llms.txt Perform nearest-neighbor vector search using the universal query endpoint. Supports filtering, named vector spaces, and score thresholds. Requires importing `QueryRequest`, `Filter`, `MatchString`, and `Range`. ```php use Qdrant\Models\Request\Points\QueryRequest; use Qdrant\Models\Filter\Filter; use Qdrant\Models\Filter\Condition\MatchString; use Qdrant\Models\Filter\Condition\Range; // --- Nearest-neighbor vector search --- $queryRequest = (new QueryRequest()) ->setQuery(['nearest' => [0.12, 0.53, /* ...1536 dims */]]) ->setUsing('content') // named vector space ->setFilter( (new Filter()) ->addMust(new MatchString('tags', 'eco')) ->addMust(new Range('year', ['gte' => 2020])) ) ->setParams(['hnsw_ef' => 128, 'exact' => false]) ->setScoreThreshold(0.7) ->setLimit(10) ->setOffset(0) ->setWithPayload(true) ->setWithVector(false); $response = $client->collections('articles')->points()->query()->query($queryRequest); foreach ($response['result']['points'] as $point) { echo $point['id'] . ' score=' . $point['score'] . ' title=' . $point['payload']['title'] . PHP_EOL; } ``` -------------------------------- ### Wait for Upsert Acknowledgement Source: https://github.com/hkulekci/qdrant-php/blob/main/README.md Ensure data upsert operations are completed by Qdrant before proceeding. This is achieved by passing the 'wait' query parameter set to 'true'. ```php $client->collections('contents')->points()->upsert($points, ['wait' => 'true']); ``` -------------------------------- ### Service Telemetry and Metrics Source: https://context7.com/hkulekci/qdrant-php/llms.txt Retrieve Prometheus-compatible metrics or anonymized telemetry from the Qdrant instance. ```APIDOC ## Service Telemetry and Metrics — `Service` ### Description Retrieve Prometheus-compatible metrics or anonymized telemetry from the Qdrant instance. ### Collect Telemetry ```php $telemetry = $client->service()->telemetry(anonymize: true); ``` ### Collect Metrics ```php $metrics = $client->service()->metrics(anonymize: false); // Returns Prometheus text exposition format ``` ``` -------------------------------- ### Retrieve Service Telemetry and Metrics Source: https://context7.com/hkulekci/qdrant-php/llms.txt Collect anonymized telemetry or Prometheus-compatible metrics from the Qdrant instance. The `metrics` method returns data in Prometheus text exposition format. ```php // Collect anonymized telemetry $telemetry = $client->service()->telemetry(anonymize: true); // Collect Prometheus metrics $metrics = $client->service()->metrics(anonymize: false); // Returns Prometheus text exposition format ``` -------------------------------- ### Multi-Vector Points with `MultiVectorStruct` Source: https://context7.com/hkulekci/qdrant-php/llms.txt Insert points into collections that support multiple named vector spaces. Requires importing `MultiVectorStruct`, `PointStruct`, and `PointsStruct`. The `upsert` method is used after defining the `MultiVectorStruct`. ```php use Qdrant\Models\MultiVectorStruct; use Qdrant\Models\PointStruct; use Qdrant\Models\PointsStruct; $vectors = new MultiVectorStruct(); $vectors->addVector('content', [0.12, 0.53, /* ...1536 dims */]); $vectors->addVector('thumbnail', [0.88, 0.12, /* ...512 dims */]); $points = new PointsStruct(); $points->addPoint(new PointStruct( 1, $vectors, ['title' => 'My Article', 'published' => true] )); $response = $client->collections('articles')->points()->upsert($points, ['wait' => 'true']); ``` -------------------------------- ### Batch Query — `Query::batch()` Source: https://context7.com/hkulekci/qdrant-php/llms.txt Execute multiple independent queries in a single HTTP request to reduce network latency. Each query in the batch can have its own parameters, including limits and whether to return payloads or vectors. ```php use Qdrant\Models\Request\Points\BatchQueryRequest; use Qdrant\Models\Request\Points\QueryRequest; $req1 = (new QueryRequest()) ->setQuery(['nearest' => [0.1, 0.2, 0.3]]) ->setUsing('image') ->setLimit(5); $req2 = (new QueryRequest()) ->setQuery(['nearest' => [0.7, 0.8, 0.9]]) ->setUsing('image') ->setLimit(3) ->setWithPayload(true); $batchRequest = new BatchQueryRequest([$req1, $req2]); $response = $client->collections('products')->points()->query()->batch($batchRequest); // $response['result'] is an array of result sets, one per query foreach ($response['result'] as $i => $result) { echo "Query $i: " . count($result['points']) . " results" . PHP_EOL; } ``` -------------------------------- ### Create and Delete Field Indexes Source: https://context7.com/hkulekci/qdrant-php/llms.txt Create payload field indexes to accelerate filtered queries. Supports keyword, integer, float, full-text, and geo indexes. ```php use Qdrant\Models\Request\CreateIndex; use Qdrant\Models\Field\TextField; // Keyword index (for exact match filtering) $client->collections('articles')->index()->create( new CreateIndex('status', 'keyword') ); ``` ```php $client->collections('articles')->index()->create( new CreateIndex('year', 'integer') ); ``` ```php $client->collections('articles')->index()->create( new CreateIndex('price', 'float') ); ``` ```php // Full-text index with custom tokenizer $textField = new TextField(); $client->collections('articles')->index()->create( new CreateIndex('body', $textField->schema()) ); ``` ```php // Geo index $client->collections('articles')->index()->create( new CreateIndex('location', 'geo') ); ``` ```php // Delete an index $client->collections('articles')->index()->delete('status'); ``` -------------------------------- ### Field Index Source: https://context7.com/hkulekci/qdrant-php/llms.txt Create payload field indexes to accelerate filtered queries using `Index::create()` and remove them with `Index::delete()`. ```APIDOC ## Field Index — `Index::create()`, `Index::delete()` Create payload field indexes to accelerate filtered queries. ```php use Qdrant\Models\Request\CreateIndex; use Qdrant\Models\Field\TextField; // Keyword index (for exact match filtering) $client->collections('articles')->index()->create( new CreateIndex('status', 'keyword') ); // Integer index $client->collections('articles')->index()->create( new CreateIndex('year', 'integer') ); // Float index $client->collections('articles')->index()->create( new CreateIndex('price', 'float') ); // Full-text index with custom tokenizer $textField = new TextField(); $client->collections('articles')->index()->create( new CreateIndex('body', $textField->schema()) ); // Geo index $client->collections('articles')->index()->create( new CreateIndex('location', 'geo') ); // Delete an index $client->collections('articles')->index()->delete('status'); ``` ``` -------------------------------- ### Multi-Vector Points Source: https://context7.com/hkulekci/qdrant-php/llms.txt Insert points into collections that have multiple named vector spaces. ```APIDOC ## Multi-Vector Points — `MultiVectorStruct` Insert points into collections that have multiple named vector spaces. ```php use Qdrant\Models\MultiVectorStruct; use Qdrant\Models\PointStruct; use Qdrant\Models\PointsStruct; $vectors = new MultiVectorStruct(); $vectors->addVector('content', [0.12, 0.53, /* ...1536 dims */]); $vectors->addVector('thumbnail', [0.88, 0.12, /* ...512 dims */]); $points = new PointsStruct(); $points->addPoint(new PointStruct( 1, $vectors, ['title' => 'My Article', 'published' => true] )); $response = $client->collections('articles')->points()->upsert($points, ['wait' => 'true']); ``` ``` -------------------------------- ### Upsert Points with `Points::upsert()` Source: https://context7.com/hkulekci/qdrant-php/llms.txt Use this method to insert or update individual points with vectors and payloads. Supports synchronous acknowledgment by setting `wait` to 'true'. Ensure all necessary models are imported. ```php use Qdrant\Models\PointsStruct; use Qdrant\Models\PointStruct; use Qdrant\Models\VectorStruct; $points = new PointsStruct(); $points->addPoint(new PointStruct( 1, // integer or UUID string ID new VectorStruct([0.12, 0.53, /* ...1536 dims */], 'content'), ['title' => 'Sustainable Farming', 'year' => 2024, 'tags' => ['agri', 'eco']] )); $points->addPoint(new PointStruct( 2, new VectorStruct([0.88, 0.12, /* ... */], 'content'), ['title' => 'Urban Beekeeping', 'year' => 2023, 'tags' => ['urban', 'eco']] )); // Upsert with wait=true to block until indexing is complete $response = $client->collections('articles')->points()->upsert($points, ['wait' => 'true']); // $response['status'] === 'ok' // $response['result']['status'] === 'completed' ``` -------------------------------- ### Scroll Points — `Points::scroll()` Source: https://context7.com/hkulekci/qdrant-php/llms.txt Iterate through all points in a collection, optionally filtered, without needing a query vector. Supports pagination using an offset or a cursor for efficient retrieval of large datasets. Can return payloads and vectors. ```php use Qdrant\Models\Request\ScrollRequest; use Qdrant\Models\Filter\Filter; use Qdrant\Models\Filter\Condition\Range; $scrollRequest = (new ScrollRequest()) ->setFilter( (new Filter())->addMust(new Range('year', ['gte' => 2022, 'lte' => 2024])) ) ->setLimit(100) ->setOffset(0) // or pass a point ID string for cursor-based pagination ->setWithPayload(true) ->setWithVector(false); $response = $client->collections('articles')->points()->scroll($scrollRequest); $nextOffset = $response['result']['next_page_offset']; // null if no more pages foreach ($response['result']['points'] as $point) { echo $point['id'] . ': ' . $point['payload']['title'] . PHP_EOL; } ``` -------------------------------- ### Batch Upsert Points Source: https://context7.com/hkulekci/qdrant-php/llms.txt Efficiently batch-inserts points using the columnar batch format. ```APIDOC ## Batch Upsert Points — `Points::batch()` Efficiently batch-insert points using the columnar batch format. ```php use Qdrant\Models\Request\PointsBatch; use Qdrant\Models\PointStruct; use Qdrant\Models\VectorStruct; $batch = new PointsBatch(); $batch->addPoint(PointStruct::createFromArray([ 'id' => 1, 'vector' => new VectorStruct([0.1, 0.2, 0.3], 'image'), 'payload' => ['color' => 'red', 'size' => 'large'], ])); $batch->addPoint(PointStruct::createFromArray([ 'id' => 2, 'vector' => new VectorStruct([0.4, 0.5, 0.6], 'image'), 'payload' => ['color' => 'blue', 'size' => 'small'], ])); $batch->addPoint(PointStruct::createFromArray([ 'id' => 3, 'vector' => new VectorStruct([0.7, 0.8, 0.9], 'image'), 'payload' => ['color' => 'green', 'size' => 'medium'], ])); $response = $client->collections('products')->points()->batch($batch, ['wait' => 'true']); // $response['status'] === 'ok' ``` ``` -------------------------------- ### Build Complex Filters with Conditions Source: https://context7.com/hkulekci/qdrant-php/llms.txt Compose `Filter` objects using `addMust()`, `addShould()`, and `addMustNot()` to define query conditions. Supports various data types and nested structures. ```php use Qdrant\Models\Filter\Filter; use Qdrant\Models\Filter\Nested; use Qdrant\Models\Filter\Condition\MatchString; use Qdrant\Models\Filter\Condition\MatchInt; use Qdrant\Models\Filter\Condition\MatchBool; use Qdrant\Models\Filter\Condition\MatchAny; use Qdrant\Models\Filter\Condition\MatchExcept; use Qdrant\Models\Filter\Condition\Range; use Qdrant\Models\Filter\Condition\HasId; use Qdrant\Models\Filter\Condition\IsEmpty; use Qdrant\Models\Filter\Condition\FullTextMatch; use Qdrant\Models\Filter\Condition\GeoRadius; use Qdrant\Models\Filter\Condition\GeoBoundingBox; use Qdrant\Models\Filter\Condition\ValueCount; $filter = (new Filter()) ->addMust(new MatchString('status', 'active')) // exact string match ->addMust(new MatchInt('category_id', 7)) // exact int match ->addMust(new MatchBool('is_featured', true)) // boolean match ->addMust(new MatchAny('tags', ['eco', 'bio', 'green'])) // match any of list ->addMust(new MatchExcept('region', ['banned', 'test'])) // exclude these values ->addMust(new Range('price', ['gte' => 10.0, 'lte' => 500.0])) ->addMust(new HasId([1, 5, 99])) // restrict to IDs ->addMustNot(new IsEmpty('description')) // field must not be empty ->addMust(new FullTextMatch('body', 'organic farming')) // full-text search ->addMust(new GeoRadius('location', [ 'center' => ['lat' => 52.52, 'lon' => 13.405], 'radius' => 5000, // metres ])) ->addMust(new GeoBoundingBox('location', [ 'top_left' => ['lat' => 53.0, 'lon' => 13.0], 'bottom_right' => ['lat' => 52.0, 'lon' => 14.0], ])) ->addMust(new ValueCount('comments', ['gte' => 1])); // array field count // Nested filter (for object array fields) $nestedFilter = new Filter(); $nestedFilter->addMust(new MatchString('color', 'red')); $filter->addMust(new Nested('attributes', $nestedFilter)); ``` -------------------------------- ### Retrieve Points by ID — `Points::id()`, `Points::ids()` Source: https://context7.com/hkulekci/qdrant-php/llms.txt Fetch one or multiple points directly from a collection using their unique IDs. This method is efficient for retrieving specific known points. You can specify whether to include payloads and vectors in the response. ```php // Single point $response = $client->collections('articles')->points()->id(42); echo $response['result']['id']; echo $response['result']['payload']['title']; // Multiple points $response = $client->collections('articles')->points()->ids( [1, 2, 3, 42], withPayload: true, withVector: false ); foreach ($response['result'] as $point) { echo $point['id'] . ': ' . $point['payload']['title'] . PHP_EOL; } ``` -------------------------------- ### Update Collection Parameters Source: https://context7.com/hkulekci/qdrant-php/llms.txt Allows modification of optimizer settings, HNSW parameters, collection parameters, or quantization on an existing collection. ```APIDOC ## Update Collection Parameters — `Collections::update()` Modify optimizer settings, HNSW parameters, collection params, or quantization on an existing collection without recreation. ```php use Qdrant\Models\Request\UpdateCollection; use Qdrant\Models\Request\CollectionConfig\OptimizersConfig; use Qdrant\Models\Request\CollectionConfig\CollectionParams; $update = new UpdateCollection(); $update->setOptimizersConfig( (new OptimizersConfig()) ->setIndexingThreshold(20000) ->setDefaultSegmentNumber(4) ->setFlushIntervalSec(5) ); $update->setCollectionParams( (new CollectionParams()) ->setReplicationFactor(2) ->setWriteConsistencyFactor(1) ->setOnDiskPayload(true) ); $response = $client->collections('articles')->update($update); // $response['result'] === true ``` ``` -------------------------------- ### Batch Query Source: https://context7.com/hkulekci/qdrant-php/llms.txt Execute multiple independent queries in a single HTTP request to optimize performance by reducing network round-trips. This is useful when you need to perform several distinct searches simultaneously. ```APIDOC ## Batch Query — `Query::batch()` Run multiple independent queries in a single HTTP request to minimize round-trips. ```php use Qdrant\Models\Request\Points\BatchQueryRequest; use Qdrant\Models\Request\Points\QueryRequest; $req1 = (new QueryRequest()) ->setQuery(['nearest' => [0.1, 0.2, 0.3]]) ->setUsing('image') ->setLimit(5); $req2 = (new QueryRequest()) ->setQuery(['nearest' => [0.7, 0.8, 0.9]]) ->setUsing('image') ->setLimit(3) ->setWithPayload(true); $batchRequest = new BatchQueryRequest([$req1, $req2]); $response = $client->collections('products')->points()->query()->batch($batchRequest); // $response['result'] is an array of result sets, one per query foreach ($response['result'] as $i => $result) { echo "Query $i: " . count($result['points']) . " results" . PHP_EOL; } ``` ``` -------------------------------- ### Update Collection Parameters Source: https://context7.com/hkulekci/qdrant-php/llms.txt Modify existing collection parameters such as optimizer settings, HNSW configuration, replication factor, and write consistency without recreating the collection. ```php use Qdrant\Models\Request\UpdateCollection; use Qdrant\Models\Request\CollectionConfig\OptimizersConfig; use Qdrant\Models\Request\CollectionConfig\CollectionParams; $update = new UpdateCollection(); $update->setOptimizersConfig( (new OptimizersConfig()) ->setIndexingThreshold(20000) ->setDefaultSegmentNumber(4) ->setFlushIntervalSec(5) ); $update->setCollectionParams( (new CollectionParams()) ->setReplicationFactor(2) ->setWriteConsistencyFactor(1) ->setOnDiskPayload(true) ); $response = $client->collections('articles')->update($update); // $response['result'] === true ```