mathsgod/milvus-client-php

Milvus 的 PHP 客户端

1.0.0 2024-07-12 02:14 UTC

This package is auto-updated.

Last update: 2024-09-12 08:02:42 UTC


README

Milvus 的 PHP 客户端。此库仅支持 Milvus 2.x。

设置

composer require mathsgod/milvus-client-php

用法

创建集合

$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();