PHPackages                             helgesverre/milvus - 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. [Database &amp; ORM](/categories/database)
4. /
5. helgesverre/milvus

ActiveLibrary[Database &amp; ORM](/categories/database)

helgesverre/milvus
==================

PHP Client for the Milvus Rest API

v0.1.0(2y ago)306.2k↑50%9[4 issues](https://github.com/HelgeSverre/milvus/issues)[1 PRs](https://github.com/HelgeSverre/milvus/pulls)MITPHPPHP ^8.2

Since Dec 27Pushed 1y ago1 watchersCompare

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

READMEChangelog (4)Dependencies (14)Versions (5)Used By (0)

[![](./art/header.png)](./art/header.png)

Milvus.io PHP API Client
========================

[](#milvusio-php-api-client)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ba1938203b89958ee4b8d7242bd7a650ef896c6505b901ab296840c00a06cf6b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68656c67657376657272652f6d696c7675732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/helgesverre/milvus)[![Total Downloads](https://camo.githubusercontent.com/26597e01166b3957d6d2df455eaacccf4b65e43e1840296adbd2a6faece51ca5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f68656c67657376657272652f6d696c7675732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/helgesverre/milvus)

[Milvus](https://github.com/milvus-io/milvus) is an open-source vector database that is highly flexible, reliable, and blazing fast. It supports adding, deleting, updating, and near real-time search of vectors on a trillion-byte scale.

This package is an API Client for the Milvus v2.3.3 Restful API, and is built on the [Saloon](https://docs.saloon.dev/)package.

Documentation about the Restful API is available on the [Milvus website](https://milvus.io/api-reference/restful/v2.3.x/About.md), and an OpenAPI spec is available [here](https://raw.githubusercontent.com/milvus-io/web-content/master/API_Reference/milvus-restful/v2.3.x/Restful%20API.openapi.json).

Versions
--------

[](#versions)

Milvus VersionPHP Client Versionv2.3.xv0.0.xv2.2.xNot supported (\*)(\*) But is mostly compatible, the only difference (that I can see) between them is the new Vector Upsert endpoint, and new parameters (`params.range_filter` and `params.radius`) in the Vector Search endpoint.

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

[](#installation)

You can install the package via composer:

```
composer require helgesverre/milvus
```

You can publish the config file with:

```
php artisan vendor:publish --tag="milvus-config"
```

This is the contents of the published `config/milvus.php` file:

```
return [
    'token' => env('MILVUS_TOKEN'),
    'username' => env('MILVUS_USERNAME'),
    'password' => env('MILVUS_PASSWORD'),
    'host' => env('MILVUS_HOST', 'localhost'),
    'port' => env('MILVUS_PORT', '19530'),
];
```

Usage
-----

[](#usage)

### With Laravel

[](#with-laravel)

For Laravel users, you can use the `Milvus` facade to interact with the Milvus API:

```
use HelgeSverre\Milvus\Facades\Milvus;

// NOTE: dbName is optional and defaults to 'default', this is only relevant if you have multiple databases.
// List all collections in the 'default' database
Milvus::collections()->list(
    dbName: 'default'
);

// Create a new collection named 'documents' in the 'default' database with a specified dimension
Milvus::collections()->create(
    collectionName: 'documents',
    dimension: 128,
    dbName: 'default',
);

// Describe the structure and properties of the 'documents' collection in the 'default' database
Milvus::collections()->describe(
    collectionName: 'documents',
    dbName: 'default',
);

// Drop or delete the 'documents' collection from the 'default' database
Milvus::collections()->drop(
    collectionName: 'documents',
    dbName: 'default',
);

// Insert a new vector into the 'documents' collection with additional fields like title and link
// Note "vector" is a reserved field name and must be used for the vector data
Milvus::vector()->insert(
    collectionName: 'documents',
    data: [
        'vector' => [0.1, 0.2, 0.3 /* etc... */],
        "title" => "Document name here",
        "link" => "https://example.com/document-name-here",
    ]
);

// Search for similar vectors in the 'documents' collection using a provided vector
Milvus::vector()->search(
    collectionName: 'documents',
    vector: [0.1, 0.2, 0.3 /* etc... */],
);

// Delete a vector from the 'documents' collection using its ID
Milvus::vector()->delete(
    id: '123129471497',
    collectionName: 'documents'
);

// Query the 'documents' collection for specific documents using a filter condition and select specific output fields
Milvus::vector()->query(
    collectionName: 'documents',
    filter: "id in [443300716234671427, 443300716234671426]",
    outputFields: ["id", "title", "link"],
);

// Retrieve a specific vector from the 'documents' collection using its ID
Milvus::vector()->get(
    id: '123129471497',
    collectionName: 'documents'
);

// Update or insert a vector in the 'documents' collection. If the ID exists, it's updated; if not, a new entry is created
Milvus::vector()->upsert(
    collectionName: 'documents',
    data: [
        'id' => 123129471497,
        'vector' => [0.1, 0.2, 0.3 /* etc... */],
        "title" => "Document name here",
        "link" => "https://example.com/document-name-here",
    ]
);
```

### Without Laravel

[](#without-laravel)

If you are not using laravel, you will have to create a new instance of the Milvus class and provide a token or user/pass, the host and the port.

```
