1. Go to this page and download the library: Download mcpuishor/qdrant-laravel 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/ */
use \Mcpuishor\QdrantLaravel\Facades\Schema;
use \Mcpuishor\QdrantLaravel\Enums\DistanceMetric;
use \Mcpuishor\QdrantLaravel\DTOs\Vector;
$vector = Vector::fromArray([
'size' => 128,
'distance' => DistanceMetric::COSINE
]);
$response = Schema::create(
name: "new_collection",
vector: $vector,
options: []
);
if ($response) {
echo "Schema created successfully";
}
use \Mcpuishor\QdrantLaravel\Schema;
use \Mcpuishor\QdrantLaravel\Enums\DistanceMetric;
use \Mcpuishor\QdrantLaravel\DTOs\Vector;
$vector = Vector::fromArray([
'size' => 128,
'distance' => DistanceMetric::COSINE
]);
$response = Schema::connection('backup')
->create(
name: "new_collection",
vector: $vector,
);
if ($response) {
echo "Schema created successfully";
}
use \Mcpuishor\QdrantLaravel\Schema;
use \Mcpuishor\QdrantLaravel\QdrantTransport;
use \Mcpuishor\QdrantLaravel\Enums\DistanceMetric;
use \Mcpuishor\QdrantLaravel\DTOs\Vector;
use \Mcpuishor\QdrantLaravel\DTOs\HnswConfig;
$vector1 = Vector::fromArray([
'size' => 128,
'distance' => DistanceMetric::COSINE
//optional parameters
'on_disk' => true,
]);
$vector2 = Vector::fromArray([
'size' => 1024,
'distance' => DistanceMetric::COSINE,
//optional parameters
'hsnw_config' => Hnswconfig::fromArray([
'm' => 10,
'ef_construct' => 4,
'on_disk' => true,
]),
]);
$response = Schema::create(
name: "new_collection",
vector: array($vector1, $vector2),
);
if ($response) {
echo "Schema created successfully";
}
use \Mcpuishor\QdrantLaravel\Facades\Schema;
$result = Schema::delete('collection_name');
if ($result) {
echo "Collection has been successfully deleted.";
}
use \Mcpuishor\QdrantLaravel\Facades\Schema;
if ( Schema::exists() ) {
echo "Collection exists.";
}
use \Mcpuishor\QdrantLaravel\Facades\Schema;
if ( Schema::exists( 'another_collection' ) ) {
echo "Collection 'another_collection' exists.";
}
use \Mcpuishor\QdrantLaravel\Facades\Qdrant;
use \Mcpuishor\QdrantLaravel\Enums\FieldType;
$result = Qdrant::indexes()->add('field_name', FieldType::KEYWORD);
use \Mcpuishor\QdrantLaravel\Enums\TokenizerType;
use \Mcpuishor\QdrantLaravel\Facades\Qdrant;
$result = Qdrant::indexes()->fulltext('text_field_name', TokenizerType::WORD);
use \Mcpuishor\QdrantLaravel\Facades\Qdrant;
$result = Qdrant::indexes()->delete('payload_field');
use Mcpuishor\QdrantLaravel\Facades\Qdrant;
// Search using a vector
$results = Qdrant::search()
->vector([0.2, 0.3, 0.4, ...]) // Your vector data
->limit(10)
->get();
use Mcpuishor\QdrantLaravel\Facades\Qdrant;
use Mcpuishor\QdrantLaravel\DTOs\Point;
$point = new Point(id: 123);
$results = Qdrant::search()
->point($point)
->limit(5)
->get();
// Include all payload data
$results = Qdrant::search()
->vector($vector)
->withPayload()
->get();
// Include only specific payload fields
$results = Qdrant::search()
->vector($vector)
-> ->vector($vector)
->withVectors()
->get();
$results = Qdrant::search()
->vector($vector)
->using('image_embedding') // Use the named vector
->get();
use Mcpuishor\QdrantLaravel\Facades\Qdrant;
// Recommend based on point IDs
$recommendations = Qdrant::recommend()
->positive([123, 456]) // Points you like
->limit(10)
->get();
$recommendations = Qdrant::recommend()
->positive([123, 456]) // Points you like
->negative([789, 101]) // Points you don't like
->limit(10)
->get();
use Mcpuishor\QdrantLaravel\Enums\AverageVectorStrategy;
$recommendations = Qdrant::recommend()
->positive([123, 456])
->strategy(AverageVectorStrategy::WEIGHTED) // Use weighted average
->limit(10)
->get();
use Mcpuishor\QdrantLaravel\Facades\Qdrant;
// Get multiple points
$points = Qdrant::points()->get([123, 456, 789]);
// Find a single point
$point = Qdrant::points()->find(123);
// With payload (default)
$points = Qdrant::points()->withPayload()->get([123, 456]);
// Without payload
$points = Qdrant::points()->withoutPayload()->get([123, 456]);
// With vector data
$points = Qdrant::points()->withVector()->get([123, 456]);
// Without vector data (default)
$points = Qdrant::points()->withoutVector()->get([123, 456]);
use Mcpuishor\QdrantLaravel\DTOs\Point;
// Create a point
$point = new Point(
id: 123,
vector: [0.2, 0.3, 0.4, ...],
payload: ['name' => 'Example', 'category' => 'test']
);
// Insert the point
$success = Qdrant::points()->insert($point);
use Mcpuishor\QdrantLaravel\PointsCollection;
use Mcpuishor\QdrantLaravel\DTOs\Point;
// Create points collection
$points = new PointsCollection([
new Point(id: 123, vector: [0.2, 0.3, 0.4, ...], payload: ['name' => 'First']),
new Point(id: 456, vector: [0.5, 0.6, 0.7, ...], payload: ['name' => 'Second'])
]);
// Upsert the points
$success = Qdrant::points()->upsert($points);
// Create an autochunker with chunk size of 100
$chunker = Qdrant::points()->autochunk(100);
// Add points - they'll be automatically upserted when the chunk size is reached
foreach ($largeDataset as $data) {
$point = new Point(
id: $data['id'],
vector: $data['embedding'],
payload: $data['metadata']
);
$chunker->add($point);
}
// Manually flush any remaining points
$chunker->flush();
use Mcpuishor\QdrantLaravel\Facades\Qdrant;
use Mcpuishor\QdrantLaravel\PointsCollection;
use Mcpuishor\QdrantLaravel\DTOs\Point;
// Create a collection of points with updated vectors
$points = new PointsCollection([
new Point(id: 123, vector: [0.2, 0.3, 0.4, ...]),
new Point(id: 456, vector: [0.5, 0.6, 0.7, ...])
]);
// Update the vectors
$success = Qdrant::vectors()->update($points);
use Mcpuishor\QdrantLaravel\Facades\Qdrant;
// Delete vectors for specific points
$success = Qdrant::vectors()->delete([123, 456]);
use Mcpuishor\QdrantLaravel\QdrantClient;
QdrantClient::macro('byClimate', function ($climate) {
return $this->where('climate', '=', $climate);
});
$results = Qdrant::collection('plants')->byClimate('tropical')->get();
sh
php artisan vendor:publish --tag=qdrant-laravel-config
sh
php artisan qdrant:migrate --collection=plants --vector-size=256 --distance-metric=euclidean --indexes='{"species":"text","age":"integer"}'
sh
php artisan qdrant:migrate --rollback --collection=plants
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.