PHP code example of mathsgod / milvus-client-php

1. Go to this page and download the library: Download mathsgod/milvus-client-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/ */

    

mathsgod / milvus-client-php example snippets


$client=new Milvus\Client($host, $port);

// Create a collection with 5 dimensions
$client->collections()->create("test_collection",5);


$collection = $client->entities("test_collection");
$collection->insert([
    [ "id"=>1, "vector" => [1.0, 2.0, 3.0, 4.0, 5.0] ],
    [ "id"=>2, "vector" => [2.0, 2.0, 3.0, 4.0, 5.0] ],
    [ "id"=>3, "vector" => [3.0, 2.0, 3.0, 4.0, 5.0] ],
    [ "id"=>4, "vector" => [4.0, 2.0, 3.0, 4.0, 5.0] ],
    [ "id"=>5, "vector" => [5.0, 2.0, 3.0, 4.0, 5.0] ],
]);

$collection = $client->collection("test_collection");
$collection->load();

// Search for the top 10 vectors that are most similar to the vector [1.0,3.0,3.0,4.0,5.0]
$result = $client->entities("test_collection")->search("vector",[1.0,3.0,3.0,4.0,5.0],10);

$e = $client->entities("test_collection");
$result = $e->query("id in [1,2,3,4,5]");

$e = $client->entities("test_collection");
$e->delete("id in [1]");

$users = $client->users()->list();

$client->users()->create("test_user");

$client->user("test_user")->drop();

$client->user("test_user")->grantRole("admin");

$client->user("test_user")->revokeRole("admin");

$roles = $client->roles()->list();

composer