PHPackages                             mathsgod/milvus-client-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. mathsgod/milvus-client-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mathsgod/milvus-client-php
==========================

A PHP client for Milvus

2.1.0(9mo ago)5477↓50%1MITPHPCI passing

Since Jul 12Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/mathsgod/milvus-client-php)[ Packagist](https://packagist.org/packages/mathsgod/milvus-client-php)[ RSS](/packages/mathsgod-milvus-client-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (12)Used By (0)

milvus-client-php
=================

[](#milvus-client-php)

A PHP client for [Milvus](https://milvus.io/) 2.6.x.

Installation
------------

[](#installation)

```
composer require mathsgod/milvus-client-php
```

Quick Start
-----------

[](#quick-start)

### Initialize Client

[](#initialize-client)

```
use Milvus\Client;

$client = new Client(
    "http://localhost:19530", // Milvus server URI
    "username",               // Optional: username
    "password",               // Optional: password
    "default",                // Optional: database name
    "token"                   // Optional: JWT token
);
```

---

Example: Create Collection with Various Field Types and Search
--------------------------------------------------------------

[](#example-create-collection-with-various-field-types-and-search)

```
$client = new Milvus\Client();

$client->createCollection(
    collection_name: "testing",
    schema: $client->createSchema()
        ->addField("id", Milvus\DataType::INT64, is_primary: true)
        ->addField("array", Milvus\DataType::ARRAY, element_type: Milvus\DataType::INT64, max_capacity: 10)
        ->addField("vector", Milvus\DataType::FLOAT_VECTOR, dim: 5)
        ->addField("text", Milvus\DataType::VARCHAR, max_length: 1000, nullable: true)
        ->addField("metadata", Milvus\DataType::JSON, nullable: true),
    index_params: $client->prepareIndexParams()
        ->addIndex(
            field_name: "vector",
            index_name: "my_index",
            index_type: Milvus\IndexType::AUTOINDEX,
            metric_type: Milvus\MetricType::COSINE
        ),
);

// Insert data
$client->insert(
    collection_name: "testing",
    data: [
        [
            "id" => 1,
            "array" => [1, 2, 3],
            "vector" => [0.1, 0.2, 0.3, 0.4, 0.5],
            "text" => "Hello World",
            "metadata" => ["key1" => "value1", "key2" => "value2"]
        ],
        [
            "id" => 2,
            "array" => [4, 5, 6],
            "vector" => [0.6, 0.7, 0.8, 0.9, 1.0],
            "text" => null,
            "metadata" => null
        ]
    ]
);

print_R($client->search(
    collection_name: "testing",
    data: [[0.1, 0.2, 0.3, 0.4, 0.5]],
    anns_field: "vector",
    limit: 3,
    output_fields: ["id", "vector", "text", "metadata"],
));
```

#### Example Search Result

[](#example-search-result)

```
Array
(
    [0] => Array
        (
            [distance] => 0.99999994
            [id] => 1
            [metadata] => {"key1":"value1","key2":"value2"}
            [text] => Hello World
            [vector] => Array
                (
                    [0] => 0.1
                    [1] => 0.2
                    [2] => 0.3
                    [3] => 0.4
                    [4] => 0.5
                )

        )

    [1] => Array
        (
            [distance] => 0.96495044
            [id] => 2
            [metadata] =>
            [text] =>
            [vector] => Array
                (
                    [0] => 0.6
                    [1] => 0.7
                    [2] => 0.8
                    [3] => 0.9
                    [4] => 1
                )

        )

)
```

---

Full-Text Search Example
------------------------

[](#full-text-search-example)

```
$client = new Milvus\Client();

$client->dropCollection("testing2");

// Full-Text Search

$client->createCollection(
    collection_name: "testing2",
    schema: $client->createSchema()
        ->addField("id", Milvus\DataType::INT64, is_primary: true)
        ->addField("text_sparse", Milvus\DataType::SPARSE_FLOAT_VECTOR)
        ->addField("document", Milvus\DataType::VARCHAR, max_length: 1000, enable_analyzer: true, enable_match: true)
        ->addFunction(
            name: "bm25",
            function_type: Milvus\FunctionType::BM25,
            input_field_names: ["document"],
            output_field_names: ["text_sparse"]
        ),
    index_params: $client->prepareIndexParams()
        ->addIndex(
            field_name: "text_sparse",
            index_name: "text_sparse_index",
            index_type: Milvus\IndexType::SPARSE_INVERTED_INDEX,
            metric_type: Milvus\MetricType::BM25
        ),
);

// Insert data
$client->insert(
    collection_name: "testing2",
    data: [
        [
            "id" => 1,
            "document" => "This is a sample document for testing.",
        ],
        [
            "id" => 2,
            "document" => "Another document for testing purposes.",
        ],
        [
            "id" => 3,
            "document" => "Milvus is a vector database designed for scalable similarity search.",
        ],
        [
            "id" => 4,
            "document" => "Full-text search enables users to find relevant documents quickly.",
        ],
        [
            "id" => 5,
            "document" => "This document contains information about PHP and Milvus integration.",
        ],
        [
            "id" => 6,
            "document" => "Testing the search functionality with various sample documents.",
        ],
        [
            "id" => 7,
            "document" => "Another example document to increase the dataset size.",
        ],
        [
            "id" => 8,
            "document" => "Sample data helps in validating the search and indexing features.",
        ]
    ]
);

print_r($client->search(
    collection_name: "testing2",
    data: ['sample'],
    anns_field: "text_sparse",
    limit: 5
));
```

---

Text Embedding Example
----------------------

[](#text-embedding-example)

For more details about embedding functions, please refer to [Milvus Embedding Function Overview](https://milvus.io/docs/embedding-function-overview.md).

```
$client = new Milvus\Client();

// Text Embedding with Azure OpenAI
$client->createCollection(
    collection_name: "testing",
    schema: $client->createSchema()
        ->addField("id", Milvus\DataType::INT64, is_primary: true)
        ->addField("document", Milvus\DataType::VARCHAR, max_length: 1000, enable_analyzer: true, enable_match: true)
        ->addField("dense", Milvus\DataType::FLOAT_VECTOR, dim: 1536)
        ->addFunction(
            name: "azure_embedding",
            function_type: Milvus\FunctionType::TEXT_EMBEDDING,
            input_field_names: ["document"],
            output_field_names: ["dense"],
            params: [
                "provider" => "azure_openai",
                "model_name" => "text-embedding-3-small"
            ]
        ),
    index_params: $client->prepareIndexParams()
        ->addIndex(
            field_name: "dense",
            index_name: "dense_index",
            index_type: Milvus\IndexType::AUTOINDEX,
            metric_type: Milvus\MetricType::COSINE
        ),
);

// Insert data (embeddings will be automatically generated)
$client->insert(
    collection_name: "testing",
    data: [
        [
            "id" => 1,
            "document" => "This is a sample document for embedding.",
        ],
        [
            "id" => 2,
            "document" => "Another document to test text embedding functionality.",
        ],
        [
            "id" => 3,
            "document" => "Milvus supports automatic text embedding generation.",
        ],
        [
            "id" => 4,
            "document" => "Azure OpenAI provides powerful embedding models.",
        ]
    ]
);

// Search using embedding (the query text will be automatically embedded)
print_r($client->search(
    collection_name: "testing",
    data: ["sample document embedding"],
    anns_field: "dense",
    limit: 3,
    output_fields: ["id", "document"]
));
```

#### Example Search Result

[](#example-search-result-1)

```
Array
(
    [0] => Array
        (
            [distance] => 0.712204
            [document] => This is a sample document for embedding.
            [id] => 1
        )

    [1] => Array
        (
            [distance] => 0.6992143
            [document] => Another document to test text embedding functionality.
            [id] => 2
        )

    [2] => Array
        (
            [distance] => 0.43827245
            [document] => Azure OpenAI provides powerful embedding models.
            [id] => 4
        )

)
```

---

Hybrid Search Example
---------------------

[](#hybrid-search-example)

```
$client = new Milvus\Client();

$client->dropCollection("testing");

// Hybrid Search
$client->createCollection(
    collection_name: "testing",
    schema: $client->createSchema()
        ->addField("id", Milvus\DataType::INT64, is_primary: true)
        ->addField("vector", Milvus\DataType::FLOAT_VECTOR, dim: 5)
        ->addField("document", Milvus\DataType::VARCHAR, max_length: 1000, enable_analyzer: true, enable_match: true)
        ->addField("text_sparse", Milvus\DataType::SPARSE_FLOAT_VECTOR)
        ->addFunction(
            name: "bm25",
            function_type: Milvus\FunctionType::BM25,
            input_field_names: ["document"],
            output_field_names: ["text_sparse"]
        ),
    index_params: $client->prepareIndexParams()
        ->addIndex(
            field_name: "vector",
            index_name: "my_index",
            index_type: Milvus\IndexType::AUTOINDEX,
            metric_type: Milvus\MetricType::COSINE
        )->addIndex(
            field_name: "text_sparse",
            index_name: "text_sparse_index",
            index_type: Milvus\IndexType::SPARSE_INVERTED_INDEX,
            metric_type: Milvus\MetricType::BM25
        ),
);

// Insert data
$client->insert(
    collection_name: "testing",
    data: [
        [
            "id" => 1,
            "vector" => [0.1, 0.2, 0.3, 0.4, 0.5],
            "document" => "This is a sample document for testing.",
        ],
        [
            "id" => 2,
            "vector" => [0.6, 0.7, 0.8, 0.9, 1.0],
            "document" => "Another document for testing purposes.",
        ],
        [
            "id" => 3,
            "vector" => [0.1, 0.2, 0.3, 0.4, 0.5],
            "document" => "Milvus is a vector database designed for scalable similarity search.",
        ],
        [
            "id" => 4,
            "vector" => [0.6, 0.7, 0.8, 0.9, 1.0],
            "document" => "Full-text search enables users to find relevant documents quickly.",
        ],
    ]
);

$query = "sample document";

print_r($client->hybridSearch(
    collection_name: "testing",
    search: [
        new HybridSearchRequest(
            data: [[0.1, 0.2, 0.3, 0.4, 0.5]], // embedding vector of the query
            anns_field: "vector",
            limit: 10,
            param: ["nprobe" => 10] // search parameters
        ),
        new HybridSearchRequest(
            data: [$query], // query string
            anns_field: "text_sparse",
            limit: 10,
            param: ["drop_ratio_search" => 0.2]
        )
    ],
    ranker: new WeightedRanker([0.5, 0.5]),
    output_fields: ["id", "document"]
));
```

---

Database Operations
-------------------

[](#database-operations)

### Create Database

[](#create-database)

```
$client->createDatabase("my_db");
```

### Switch Database

[](#switch-database)

```
$client->usingDatabase("my_db");
```

### List All Databases

[](#list-all-databases)

```
$dbs = $client->listDatabases();
```

### Describe Database

[](#describe-database)

```
$info = $client->describeDatabase("my_db");
```

### Drop Database

[](#drop-database)

```
$client->dropDatabase("my_db");
```

---

Collection Operations
---------------------

[](#collection-operations)

### Create Collection

[](#create-collection)

```
$client->createCollection(
    collection_name: "test_collection",
    schema: $client->createSchema()
        ->addField("id", Milvus\DataType::INT64, is_primary: true)
        ->addField("array", Milvus\DataType::ARRAY, element_type: Milvus\DataType::INT64, max_capacity: 10)
        ->addField("vector", Milvus\DataType::FLOAT_VECTOR, dim: 5)
        ->addField("text", Milvus\DataType::VARCHAR, max_length: 1000, nullable: true)
        ->addField("metadata", Milvus\DataType::JSON, nullable: true),
    index_params: $client->prepareIndexParams()
        ->addIndex(
            field_name: "vector",
            index_name: "my_index",
            index_type: Milvus\IndexType::AUTOINDEX,
            metric_type: Milvus\MetricType::COSINE
        ),
);
```

### List All Collections

[](#list-all-collections)

```
$collections = $client->listCollections();
```

### Describe Collection

[](#describe-collection)

```
$desc = $client->describeCollection("test_collection");
```

### Drop Collection

[](#drop-collection)

```
$client->dropCollection("test_collection");
```

### Load/Release Collection

[](#loadrelease-collection)

```
$client->loadCollection("test_collection");
$client->releaseCollection("test_collection");
```

### Rename Collection

[](#rename-collection)

```
$client->renameCollection("old_name", "new_name");
```

---

Vector Data Operations
----------------------

[](#vector-data-operations)

### Insert Data

[](#insert-data)

```
$entities = [
    ["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]],
];
$client->insert("test_collection", $entities);
```

### Upsert Data

[](#upsert-data)

```
$client->upsert("test_collection", $entities);
```

### Query Data

[](#query-data)

```
$result = $client->query("test_collection", "id in [1,2]");
```

### Delete Data

[](#delete-data)

```
$client->delete("test_collection", "id in [1]");
```

### Vector Search

[](#vector-search)

```
$result = $client->search(
    collection_name: "test_collection",
    data: [[1.0, 2.0, 3.0, 4.0, 5.0]],
    anns_field: "vector",
    limit: 10,
    output_fields: ["id", "vector"]
);
```

---

Index Operations
----------------

[](#index-operations)

### Create Index

[](#create-index)

```
$indexParams = $client->prepareIndexParams();
$indexParams->addIndex(
    field_name: "vector",
    index_name: "my_index",
    index_type: Milvus\IndexType::AUTOINDEX,
    metric_type: Milvus\MetricType::COSINE
);
$client->createIndex("test_collection", $indexParams);
```

### List Indexes

[](#list-indexes)

```
$indexes = $client->listIndexes("test_collection");
```

---

Users &amp; Privileges
----------------------

[](#users--privileges)

### List Users

[](#list-users)

```
$users = $client->listUsers();
```

### Create User

[](#create-user)

```
$client->createUser("test_user", "password");
```

### Describe User

[](#describe-user)

```
$userInfo = $client->describeUser("test_user");
```

### Drop User

[](#drop-user)

```
$client->dropUser("test_user");
```

### Update Password

[](#update-password)

```
$client->updatePassword("test_user", "old_password", "new_password");
```

---

Roles &amp; Privileges
----------------------

[](#roles--privileges)

### List Roles

[](#list-roles)

```
$roles = $client->listRoles();
```

### Create Role

[](#create-role)

```
$client->createRole("admin");
```

### Describe Role

[](#describe-role)

```
$roleInfo = $client->describeRole("admin");
```

### Drop Role

[](#drop-role)

```
$client->dropRole("admin");
```

### Grant Privilege to Role

[](#grant-privilege-to-role)

```
$client->grantPrivilege("admin", "Collection", "Insert", "test_collection");
```

---

Advanced
--------

[](#advanced)

### Hybrid Search

[](#hybrid-search)

```
$result = $client->hybridSearch(
    collection_name: "test_collection",
    search: [
        new HybridSearchRequest(
            data: [[0.1, 0.2, 0.3, 0.4, 0.5]],
            anns_field: "vector",
            limit: 10,
            param: []
        ),
    ],
    ranker: new Milvus\RRFRanker(10),
    output_fields: ["id", "vector"]
);
```

---

Reference
---------

[](#reference)

- [Milvus Documentation](https://milvus.io/docs)
- [mathsgod/milvus-client-php on GitHub](https://github.com/mathsgod/milvus-client-php)

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance70

Regular maintenance activity

Popularity22

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 99.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~44 days

Recently: every ~10 days

Total

10

Last Release

273d ago

Major Versions

1.0.0 → 2.0.02025-07-04

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/18732337?v=4)[Raymond](/maintainers/mathsgod)[@mathsgod](https://github.com/mathsgod)

---

Top Contributors

[![mathsgod](https://avatars.githubusercontent.com/u/18732337?v=4)](https://github.com/mathsgod "mathsgod (118 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

milvusphpclientmilvusvector-database

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mathsgod-milvus-client-php/health.svg)

```
[![Health](https://phpackages.com/badges/mathsgod-milvus-client-php/health.svg)](https://phpackages.com/packages/mathsgod-milvus-client-php)
```

###  Alternatives

[stevebauman/location

Retrieve a user's location by their IP Address

1.3k7.6M65](/packages/stevebauman-location)[gehrisandro/tailwind-merge-laravel

TailwindMerge for Laravel merges multiple Tailwind CSS classes by automatically resolving conflicts between them

341682.2k18](/packages/gehrisandro-tailwind-merge-laravel)[graze/telnet-client

Telnet client written in PHP

50233.9k4](/packages/graze-telnet-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
