hejunjie / milvus
一个轻量级的 PHP 库,用来通过 RESTful API 调用 Milvus 向量数据库,可以用它来管理集合、插入数据,以及进行向量搜索 | A lightweight PHP library for interacting with the Milvus vector database via RESTful API. It allows you to manage collections, insert data, and perform vector searches
README
English|简体中文A lightweight PHP library for interacting with the Milvus vector database via RESTful API. It allows you to manage collections, insert data, and perform vector searches.
This project has been parsed by Zread. If you need a quick overview of the project, you can click here to view it:Understand this project
Installation
composer require hejunjie/milvus
Usage
Here is the basic usage. Full supported operations are listed below.
All methods are fully commented, and parameter details can be found in the corresponding method comments.
Initialize Client
use Hejunjie\Milvus; $client = new Milvus\Client($baseUrl, $apiKey);
Create Collection
$client->collections()->create(string $collectionName, array $schema, ?array $indexParams = null);
Insert Data
$client->entities()->insert(string $collectionName, array $data, ?string $partitionName = null);
Vector Search
$results = $client->entities()->search(string $collectionName, array $data, string $annsField);
Supported Methods
- Client - Main entry point
- customize - Custom requests
- collections - Collection operations
- create - Create a collection
- describe - Get collection info
- drop - Delete a collection
- get_load_state - Get collection load state
- get_stats - Get collection stats
- has - Check if a collection exists
- list - List all collection names
- load - Load a collection
- release - Release a collection
- rename - Rename a collection
- alter_properties - Set collection properties
- drop_properties - Remove collection properties
- partitions - Partition operations
- create - Create a partition
- drop - Delete a partition
- get_stats - Get partition stats
- has - Check if a partition exists
- list - List partitions
- load - Load a partition
- release - Release a partition
- indexes - Index operations
- create - Create an index
- describe - Get index info
- drop - Delete an index
- list - List all indexes
- aliases - Alias operations
- alter - Change an alias
- create - Create an alias
- describe - Describe an alias
- drop - Delete an alias
- list - List all aliases
- entities - Vector data operations
- delete - Delete data
- get - Get data by primary key
- query - Get data by filter expression
- insert - Insert data
- upsert - Update data
- search - Search vector data
Motivation
Normally, PHP rarely interacts with vector databases, but here's how it started: I was using a “slightly naughty” novel website with short stories of tens of thousands of words. The site was fine, but it limited me to reading only a few stories per day—and worse, it didn’t allow searching. Frustrated, I wrote a crawler and downloaded all the stories.
With so many novels, finding anything specific became nearly impossible. That’s when I thought of Milvus. My little 2-core, 2GB server couldn’t run a local deployment, not to mention vectorization. But fortunately, Milvus offers a managed service with a free tier. I could run the vectorization on my Mac and upload the data. Later, searches that required vectorized queries could use SiliconFlow’s free quota.
So, I needed a PHP library to operate Milvus, allowing the whole process to work smoothly—and making it easy to find the stories I wanted.
(The only issue is that the free quota isn’t very large—enough to store about 5GB of data—but it’s already sufficient, and it didn’t cost a thing)
Welcome
If you find this library useful, feel free to ⭐ it, or submit issues/PRs. Discussion and feedback are always welcome.