{"id":16278109,"url":"https://github.com/helgesverre/milvus","last_synced_at":"2025-09-17T21:33:37.024Z","repository":{"id":214369250,"uuid":"734525525","full_name":"HelgeSverre/milvus","owner":"HelgeSverre","description":"A PHP Client for the Milvus Vector Database Rest API","archived":false,"fork":false,"pushed_at":"2025-01-03T09:19:11.000Z","size":111,"stargazers_count":14,"open_issues_count":4,"forks_count":9,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-07T22:19:24.304Z","etag":null,"topics":["client","laravel","milvus","php","sdk","vector-database"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HelgeSverre.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-21T23:04:51.000Z","updated_at":"2025-01-03T09:19:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"a8c7a17f-e14e-4b19-a6ef-3774c8a1669b","html_url":"https://github.com/HelgeSverre/milvus","commit_stats":null,"previous_names":["helgesverre/milvus"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HelgeSverre%2Fmilvus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HelgeSverre%2Fmilvus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HelgeSverre%2Fmilvus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HelgeSverre%2Fmilvus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HelgeSverre","download_url":"https://codeload.github.com/HelgeSverre/milvus/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233426276,"owners_count":18674555,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["client","laravel","milvus","php","sdk","vector-database"],"created_at":"2024-10-10T18:57:20.809Z","updated_at":"2025-09-17T21:33:31.633Z","avatar_url":"https://github.com/HelgeSverre.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg src=\"./art/header.png\"\u003e\u003c/p\u003e\n\n# Milvus.io PHP API Client\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/helgesverre/milvus.svg?style=flat-square)](https://packagist.org/packages/helgesverre/milvus)\n[![Total Downloads](https://img.shields.io/packagist/dt/helgesverre/milvus.svg?style=flat-square)](https://packagist.org/packages/helgesverre/milvus)\n\n[Milvus](https://github.com/milvus-io/milvus) is an open-source vector database that is highly flexible, reliable, and\nblazing fast. It supports adding,\ndeleting, updating, and near real-time search of vectors on a trillion-byte scale.\n\nThis package is an API Client for the Milvus v2.3.3 Restful API, and is built on the [Saloon](https://docs.saloon.dev/)\npackage.\n\nDocumentation about the Restful API is available on\nthe [Milvus website](https://milvus.io/api-reference/restful/v2.3.x/About.md), and an OpenAPI spec is\navailable [here](https://raw.githubusercontent.com/milvus-io/web-content/master/API_Reference/milvus-restful/v2.3.x/Restful%20API.openapi.json).\n\n## Versions\n\n| Milvus Version | PHP Client Version |\n|----------------|--------------------|\n| v2.3.x         | v0.0.x             |\n| v2.2.x         | Not supported (*)  |\n\n(*) But is mostly compatible, the only difference (that I can see) between them is the new Vector Upsert endpoint, and\nnew parameters (`params.range_filter` and `params.radius`)  in the Vector Search endpoint.\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require helgesverre/milvus\n```\n\nYou can publish the config file with:\n\n```bash\nphp artisan vendor:publish --tag=\"milvus-config\"\n```\n\nThis is the contents of the published `config/milvus.php` file:\n\n```php\nreturn [\n    'token' =\u003e env('MILVUS_TOKEN'),\n    'username' =\u003e env('MILVUS_USERNAME'),\n    'password' =\u003e env('MILVUS_PASSWORD'),\n    'host' =\u003e env('MILVUS_HOST', 'localhost'),\n    'port' =\u003e env('MILVUS_PORT', '19530'),\n];\n```\n\n## Usage\n\n### With Laravel\n\nFor Laravel users, you can use the `Milvus` facade to interact with the Milvus API:\n\n```php\nuse HelgeSverre\\Milvus\\Facades\\Milvus;\n\n// NOTE: dbName is optional and defaults to 'default', this is only relevant if you have multiple databases.\n// List all collections in the 'default' database\nMilvus::collections()-\u003elist(\n    dbName: 'default'\n);\n\n// Create a new collection named 'documents' in the 'default' database with a specified dimension\nMilvus::collections()-\u003ecreate(\n    collectionName: 'documents',\n    dimension: 128,\n    dbName: 'default',\n);\n\n// Describe the structure and properties of the 'documents' collection in the 'default' database\nMilvus::collections()-\u003edescribe(\n    collectionName: 'documents',\n    dbName: 'default',\n);\n\n// Drop or delete the 'documents' collection from the 'default' database\nMilvus::collections()-\u003edrop(\n    collectionName: 'documents',\n    dbName: 'default',\n);\n\n\n// Insert a new vector into the 'documents' collection with additional fields like title and link\n// Note \"vector\" is a reserved field name and must be used for the vector data\nMilvus::vector()-\u003einsert(\n    collectionName: 'documents',\n    data: [\n        'vector' =\u003e [0.1, 0.2, 0.3 /* etc... */],\n        \"title\" =\u003e \"Document name here\",\n        \"link\" =\u003e \"https://example.com/document-name-here\",\n    ]\n);\n\n// Search for similar vectors in the 'documents' collection using a provided vector\nMilvus::vector()-\u003esearch(\n    collectionName: 'documents',\n    vector: [0.1, 0.2, 0.3 /* etc... */],\n);\n\n// Delete a vector from the 'documents' collection using its ID\nMilvus::vector()-\u003edelete(\n    id: '123129471497',\n    collectionName: 'documents'\n);\n\n// Query the 'documents' collection for specific documents using a filter condition and select specific output fields\nMilvus::vector()-\u003equery(\n    collectionName: 'documents',\n    filter: \"id in [443300716234671427, 443300716234671426]\",\n    outputFields: [\"id\", \"title\", \"link\"],\n);\n\n// Retrieve a specific vector from the 'documents' collection using its ID\nMilvus::vector()-\u003eget(\n    id: '123129471497',\n    collectionName: 'documents'\n);\n\n// Update or insert a vector in the 'documents' collection. If the ID exists, it's updated; if not, a new entry is created\nMilvus::vector()-\u003eupsert(\n    collectionName: 'documents',\n    data: [\n        'id' =\u003e 123129471497,\n        'vector' =\u003e [0.1, 0.2, 0.3 /* etc... */],\n        \"title\" =\u003e \"Document name here\",\n        \"link\" =\u003e \"https://example.com/document-name-here\",\n    ]\n);\n\n```\n\n### Without Laravel\n\nIf you are not using laravel, you will have to create a new instance of the Milvus class and provide a token or\nuser/pass, the host and the port.\n\n```php\n\u003c?php\n// use HelgeSverre\\Milvus\\Facades\\Milvus;\nuse HelgeSverre\\Milvus\\Milvus;\n\n$milvus = new Milvus(\n    token: \"your-token\",\n    host: \"localhost\",\n    port: \"19530\"\n);\n\n\n// Import the Milvus facade for easier access to Milvus functions\n\n// NOTE: dbName is optional and defaults to 'default', this is only relevant if you have multiple databases.\n// List all collections in the 'default' database\n$milvus-\u003ecollections()-\u003elist(\n    dbName: 'default'\n);\n\n// Create a new collection named 'documents' in the 'default' database with a specified dimension\n$milvus-\u003ecollections()-\u003ecreate(\n    collectionName: 'documents',\n    dimension: 128,\n    dbName: 'default',\n);\n\n// Describe the structure and properties of the 'documents' collection in the 'default' database\n$milvus-\u003ecollections()-\u003edescribe(\n    collectionName: 'documents',\n    dbName: 'default',\n);\n\n// Drop or delete the 'documents' collection from the 'default' database\n$milvus-\u003ecollections()-\u003edrop(\n    collectionName: 'documents',\n    dbName: 'default',\n);\n\n\n// Insert a new vector into the 'documents' collection with additional fields like title and link\n// Note \"vector\" is a reserved field name and must be used for the vector data\n$milvus-\u003evector()-\u003einsert(\n    collectionName: 'documents',\n    data: [\n        'vector' =\u003e [0.1, 0.2, 0.3 /* etc... */],\n        \"title\" =\u003e \"Document name here\",\n        \"link\" =\u003e \"https://example.com/document-name-here\",\n    ]\n);\n\n// Search for similar vectors in the 'documents' collection using a provided vector\n$milvus-\u003evector()-\u003esearch(\n    collectionName: 'documents',\n    vector: [0.1, 0.2, 0.3 /* etc... */],\n);\n\n// Delete a vector from the 'documents' collection using its ID\n$milvus-\u003evector()-\u003edelete(\n    id: '123129471497',\n    collectionName: 'documents'\n);\n\n// Query the 'documents' collection for specific documents using a filter condition and select specific output fields\n$milvus-\u003evector()-\u003equery(\n    collectionName: 'documents',\n    filter: \"id in [443300716234671427, 443300716234671426]\",\n    outputFields: [\"id\", \"title\", \"link\"],\n);\n\n// Retrieve a specific vector from the 'documents' collection using its ID\n$milvus-\u003evector()-\u003eget(\n    id: '123129471497',\n    collectionName: 'documents'\n);\n\n// Update or insert a vector in the 'documents' collection. If the ID exists, it's updated; if not, a new entry is created\n$milvus-\u003evector()-\u003eupsert(\n    collectionName: 'documents',\n    data: [\n        'id' =\u003e 123129471497,\n        'vector' =\u003e [0.1, 0.2, 0.3 /* etc... */],\n        \"title\" =\u003e \"Document name here\",\n        \"link\" =\u003e \"https://example.com/document-name-here\",\n    ]\n);\n\n```\n\n### Using with Zilliz Cloud\n\nIf you are using the hosted version of Milvus, you will need to specify the following host and port along with your API\ntoken:\n\n```php\nuse HelgeSverre\\Milvus\\Milvus;\n\n$milvus = new Milvus(\n    token: \"db_randomstringhere:passwordhere\",\n    host: 'https://in03-somerandomstring.api.gcp-us-west1.zillizcloud.com',\n    port: '443'\n);\n```\n\n## Example: Semantic Search with Milvus and OpenAI Embeddings\n\nThis example demonstrates how to perform a semantic search in Milvus using embeddings generated from OpenAI.\n\n### Prepare Your Data\n\nFirst, create an array of data you wish to index. In this example, we'll use blog posts with titles, summaries, and\ntags.\n\n```php\n$blogPosts = [\n    [\n        'title' =\u003e 'Exploring Laravel',\n        'summary' =\u003e 'A deep dive into Laravel frameworks...',\n        'tags' =\u003e ['PHP', 'Laravel', 'Web Development']\n    ],\n       [\n        'title' =\u003e 'Exploring Laravel',\n        'summary' =\u003e 'A deep dive into Laravel frameworks, exploring its features and benefits for modern web development.',\n        'tags' =\u003e ['PHP', 'Laravel', 'Web Development']\n    ],\n    [\n        'title' =\u003e 'Introduction to React',\n        'summary' =\u003e 'Understanding the basics of React and how it revolutionizes frontend development.',\n        'tags' =\u003e ['JavaScript', 'React', 'Frontend']\n    ],\n    [\n        'title' =\u003e 'Getting Started with Vue.js',\n        'summary' =\u003e 'A beginner’s guide to building interactive web interfaces with Vue.js.',\n        'tags' =\u003e ['JavaScript', 'Vue.js', 'Frontend']\n    ],\n];\n```\n\n### Generate Embeddings\n\nUse OpenAI's embeddings API to convert the summaries of your blog posts into vector embeddings.\n\n```php\n$summaries = array_column($blogPosts, 'summary');\n$embeddingsResponse = OpenAI::client('sk-your-openai-api-key')\n    -\u003eembeddings()\n    -\u003ecreate([\n        'model' =\u003e 'text-embedding-ada-002',\n        'input' =\u003e $summaries,\n    ]);\n\nforeach ($embeddingsResponse-\u003eembeddings as $embedding) {\n    $blogPosts[$embedding-\u003eindex]['vector'] = $embedding-\u003eembedding;\n}\n```\n\n### Create Milvus collection\n\nCreate a collection in Milvus to store your blog post embeddings, note that the dimension of the embeddings must match\nthe dimension of the embeddings generated by OpenAI (`1536` if you are using the `text-embedding-ada-002` model).\n\n```php\n$milvus = new Milvus(\n    token: \"your-token\",\n    host: \"localhost\",\n    port: \"19530\"\n);\n\n\n$milvus-\u003ecollections()-\u003ecreate(\n    collectionName: 'blog_posts',\n    dimension: 1536,\n);\n```\n\n### Insert into Milvus\n\nInsert these embeddings, along with other blog post data, into your Milvus collection.\n\n```php\n\n$insertResponse = $milvus-\u003evector()-\u003einsert('blog_posts', $blogPosts);\n```\n\n### Creating a Search Vector with OpenAI\n\nGenerate a search vector for your query, akin to how you processed the blog posts.\n\n```php\n$searchVectorResponse = OpenAI::client('sk-your-openai-api-key')\n    -\u003eembeddings()\n    -\u003ecreate([\n        'model' =\u003e 'text-embedding-ada-002',\n        'input' =\u003e 'laravel framework',\n    ]);\n\n$searchEmbedding = $searchVectorResponse-\u003eembeddings[0]-\u003eembedding;\n```\n\n### Searching using the Embedding in Milvus\n\nUse the Milvus client to perform a search with the generated embedding.\n\n```php\n$searchResponse = $milvus-\u003evector()-\u003esearch(\n    collectionName: 'blog_posts',\n    vector: $searchEmbedding,\n    limit: 3,\n    outputFields: ['title', 'summary', 'tags']\n);\n\n// Output the search results\nforeach ($searchResponse as $result) {\n    echo \"Title: \" . $result['title'] . \"\\n\";\n    echo \"Summary: \" . $result['summary'] . \"\\n\";\n    echo \"Tags: \" . implode(', ', $result['tags']) . \"\\n\\n\";\n}\n```\n\n## Running Milvus in Docker\n\nTo quickly get started with Milvus, you can run it in Docker, by using the following command\n\n```bash\n# Download the docker-compose.yml file\nwget https://github.com/milvus-io/milvus/releases/download/v2.3.3/milvus-standalone-docker-compose.yml -O docker-compose.yml\n\n# Start Milvus\ndocker compose up -d\n```\n\nA healthcheck endpoint will now be available on `http://localhost:9091/healthz`, and the Milvus API will be available\non `http://localhost:19530`.\n\nTo stop Milvus, run `docker compose down`, to wipe all the data, run `docker compose down -v`.\n\nFor more\ndetails [Installing Milvus Standalone with Docker Compose](https://milvus.io/docs/install_standalone-docker.md)\n\nFor production workloads, consider checking out [Zilliz.com](https://zilliz.com/), which are the developers behind\nMilvus and provides a hosted version of Milvus in the Cloud ☁️.\n\n## Testing\n\n```bash\ncp .env.example .env\n\n## Start a local Milvus instance, it takes awhile to boot up\ndocker compose up -d\n \ncomposer test\ncomposer analyse src\n```\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n## Disclaimer\n\n\"Milvus®\" and the Milvus logo are registered trademarks of\nthe [Linux Foundation](https://www.linuxfoundation.org/about) (LF Projects, LLC). This package is not affiliated with,\nendorsed by, or sponsored by the Linux Foundation. It's developed independently and uses the \"Milvus\" name under fair\nuse, solely for identification. All trademarks and registered trademarks, including \"Milvus®\", are the property of their\nrespective owners. \"Milvus®\" is\na [registered trademark](https://branddb.wipo.int/en/quicksearch/brand/EM500000018660437) of the Linux Foundation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhelgesverre%2Fmilvus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhelgesverre%2Fmilvus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhelgesverre%2Fmilvus/lists"}