$npx -y skills add cinience/alicloud-skills --skill aliyun-milvus-searchUse when working with AliCloud Milvus (serverless) with PyMilvus to create collections, insert vectors, and run filtered similarity search. Optimized for Claude Code/Codex vector retrieval flows.
| 1 | Category: provider |
| 2 | |
| 3 | # AliCloud Milvus (Serverless) via PyMilvus |
| 4 | |
| 5 | This skill uses standard PyMilvus APIs to connect to AliCloud Milvus and run vector search. |
| 6 | |
| 7 | ## Prerequisites |
| 8 | |
| 9 | - Install SDK (recommended in a venv to avoid PEP 668 limits): |
| 10 | |
| 11 | ```bash |
| 12 | python3 -m venv .venv |
| 13 | . .venv/bin/activate |
| 14 | python -m pip install --upgrade pymilvus |
| 15 | ``` |
| 16 | - Provide connection via environment variables: |
| 17 | - `MILVUS_URI` (e.g. `http://<host>:19530`) |
| 18 | - `MILVUS_TOKEN` (`<username>:<password>`) |
| 19 | - `MILVUS_DB` (default: `default`) |
| 20 | |
| 21 | ## Quickstart (Python) |
| 22 | |
| 23 | ```python |
| 24 | import os |
| 25 | from pymilvus import MilvusClient |
| 26 | |
| 27 | client = MilvusClient( |
| 28 | uri=os.getenv("MILVUS_URI"), |
| 29 | token=os.getenv("MILVUS_TOKEN"), |
| 30 | db_name=os.getenv("MILVUS_DB", "default"), |
| 31 | ) |
| 32 | |
| 33 | # 1) Create a collection |
| 34 | client.create_collection( |
| 35 | collection_name="docs", |
| 36 | dimension=768, |
| 37 | ) |
| 38 | |
| 39 | # 2) Insert data |
| 40 | items = [ |
| 41 | {"id": 1, "vector": [0.01] * 768, "source": "kb", "chunk": 0}, |
| 42 | {"id": 2, "vector": [0.02] * 768, "source": "kb", "chunk": 1}, |
| 43 | ] |
| 44 | client.insert(collection_name="docs", data=items) |
| 45 | |
| 46 | # 3) Search |
| 47 | query_vectors = [[0.01] * 768] |
| 48 | res = client.search( |
| 49 | collection_name="docs", |
| 50 | data=query_vectors, |
| 51 | limit=5, |
| 52 | filter='source == "kb" and chunk >= 0', |
| 53 | output_fields=["source", "chunk"], |
| 54 | ) |
| 55 | print(res) |
| 56 | ``` |
| 57 | |
| 58 | ## Script quickstart |
| 59 | |
| 60 | ```bash |
| 61 | python skills/ai/search/aliyun-milvus-search/scripts/quickstart.py |
| 62 | ``` |
| 63 | |
| 64 | Environment variables: |
| 65 | |
| 66 | - `MILVUS_URI` |
| 67 | - `MILVUS_TOKEN` |
| 68 | - `MILVUS_DB` (optional) |
| 69 | - `MILVUS_COLLECTION` (optional) |
| 70 | - `MILVUS_DIMENSION` (optional) |
| 71 | |
| 72 | Optional args: `--collection`, `--dimension`, `--limit`, `--filter`. |
| 73 | |
| 74 | ## Notes for Claude Code/Codex |
| 75 | |
| 76 | - Insert is async; wait a few seconds before searching newly inserted data. |
| 77 | - Keep vector `dimension` aligned with your embedding model. |
| 78 | - Use filters to enforce tenant scoping or dataset partitions. |
| 79 | |
| 80 | ## Error handling |
| 81 | |
| 82 | - Auth errors: check `MILVUS_TOKEN` and instance permissions. |
| 83 | - Dimension mismatch: ensure all vectors match collection dimension. |
| 84 | - Network errors: verify VPC/public access settings on the instance. |
| 85 | |
| 86 | ## Validation |
| 87 | |
| 88 | ```bash |
| 89 | mkdir -p output/aliyun-milvus-search |
| 90 | for f in skills/ai/search/aliyun-milvus-search/scripts/*.py; do |
| 91 | python3 -m py_compile "$f" |
| 92 | done |
| 93 | echo "py_compile_ok" > output/aliyun-milvus-search/validate.txt |
| 94 | ``` |
| 95 | |
| 96 | Pass criteria: command exits 0 and `output/aliyun-milvus-search/validate.txt` is generated. |
| 97 | |
| 98 | ## Output And Evidence |
| 99 | |
| 100 | - Save artifacts, command outputs, and API response summaries under `output/aliyun-milvus-search/`. |
| 101 | - Include key parameters (region/resource id/time range) in evidence files for reproducibility. |
| 102 | |
| 103 | ## Workflow |
| 104 | |
| 105 | 1) Confirm user intent, region, identifiers, and whether the operation is read-only or mutating. |
| 106 | 2) Run one minimal read-only query first to verify connectivity and permissions. |
| 107 | 3) Execute the target operation with explicit parameters and bounded scope. |
| 108 | 4) Verify results and save output/evidence files. |
| 109 | |
| 110 | ## References |
| 111 | |
| 112 | - PyMilvus `MilvusClient` examples for AliCloud Milvus |
| 113 | |
| 114 | - Source list: `references/sources.md` |