$npx -y skills add cinience/alicloud-skills --skill aliyun-dashvector-searchUse when building vector retrieval with DashVector using the Python SDK. Use when creating collections, upserting docs, and running similarity search with filters in Claude Code/Codex.
| 1 | Category: provider |
| 2 | |
| 3 | # DashVector Vector Search |
| 4 | |
| 5 | Use DashVector to manage collections and perform vector similarity search with optional filters and sparse vectors. |
| 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 dashvector |
| 15 | ``` |
| 16 | - Provide credentials and endpoint via environment variables: |
| 17 | - `DASHVECTOR_API_KEY` |
| 18 | - `DASHVECTOR_ENDPOINT` (cluster endpoint) |
| 19 | |
| 20 | ## Normalized operations |
| 21 | |
| 22 | ### Create collection |
| 23 | - `name` (str) |
| 24 | - `dimension` (int) |
| 25 | - `metric` (str: `cosine` | `dotproduct` | `euclidean`) |
| 26 | - `fields_schema` (optional dict of field types) |
| 27 | |
| 28 | ### Upsert docs |
| 29 | - `docs` list of `{id, vector, fields}` or tuples |
| 30 | - Supports `sparse_vector` and multi-vector collections |
| 31 | |
| 32 | ### Query docs |
| 33 | - `vector` or `id` (one required; if both empty, only filter is applied) |
| 34 | - `topk` (int) |
| 35 | - `filter` (SQL-like where clause) |
| 36 | - `output_fields` (list of field names) |
| 37 | - `include_vector` (bool) |
| 38 | |
| 39 | ## Quickstart (Python SDK) |
| 40 | |
| 41 | ```python |
| 42 | import os |
| 43 | import dashvector |
| 44 | from dashvector import Doc |
| 45 | |
| 46 | client = dashvector.Client( |
| 47 | api_key=os.getenv("DASHVECTOR_API_KEY"), |
| 48 | endpoint=os.getenv("DASHVECTOR_ENDPOINT"), |
| 49 | ) |
| 50 | |
| 51 | # 1) Create a collection |
| 52 | ret = client.create( |
| 53 | name="docs", |
| 54 | dimension=768, |
| 55 | metric="cosine", |
| 56 | fields_schema={"title": str, "source": str, "chunk": int}, |
| 57 | ) |
| 58 | assert ret |
| 59 | |
| 60 | # 2) Upsert docs |
| 61 | collection = client.get(name="docs") |
| 62 | ret = collection.upsert( |
| 63 | [ |
| 64 | Doc(id="1", vector=[0.01] * 768, fields={"title": "Intro", "source": "kb", "chunk": 0}), |
| 65 | Doc(id="2", vector=[0.02] * 768, fields={"title": "FAQ", "source": "kb", "chunk": 1}), |
| 66 | ] |
| 67 | ) |
| 68 | assert ret |
| 69 | |
| 70 | # 3) Query |
| 71 | ret = collection.query( |
| 72 | vector=[0.01] * 768, |
| 73 | topk=5, |
| 74 | filter="source = 'kb' AND chunk >= 0", |
| 75 | output_fields=["title", "source", "chunk"], |
| 76 | include_vector=False, |
| 77 | ) |
| 78 | for doc in ret: |
| 79 | print(doc.id, doc.fields) |
| 80 | ``` |
| 81 | |
| 82 | ## Script quickstart |
| 83 | |
| 84 | ```bash |
| 85 | python skills/ai/search/aliyun-dashvector-search/scripts/quickstart.py |
| 86 | ``` |
| 87 | |
| 88 | Environment variables: |
| 89 | |
| 90 | - `DASHVECTOR_API_KEY` |
| 91 | - `DASHVECTOR_ENDPOINT` |
| 92 | - `DASHVECTOR_COLLECTION` (optional) |
| 93 | - `DASHVECTOR_DIMENSION` (optional) |
| 94 | |
| 95 | Optional args: `--collection`, `--dimension`, `--topk`, `--filter`. |
| 96 | |
| 97 | ## Notes for Claude Code/Codex |
| 98 | |
| 99 | - Prefer `upsert` for idempotent ingestion. |
| 100 | - Keep `dimension` aligned to your embedding model output size. |
| 101 | - Use filters to enforce tenant or dataset scoping. |
| 102 | - If using sparse vectors, pass `sparse_vector={token_id: weight, ...}` when upserting/querying. |
| 103 | |
| 104 | ## Error handling |
| 105 | |
| 106 | - 401/403: invalid `DASHVECTOR_API_KEY` |
| 107 | - 400: invalid collection schema or dimension mismatch |
| 108 | - 429/5xx: retry with exponential backoff |
| 109 | |
| 110 | ## Validation |
| 111 | |
| 112 | ```bash |
| 113 | mkdir -p output/aliyun-dashvector-search |
| 114 | for f in skills/ai/search/aliyun-dashvector-search/scripts/*.py; do |
| 115 | python3 -m py_compile "$f" |
| 116 | done |
| 117 | echo "py_compile_ok" > output/aliyun-dashvector-search/validate.txt |
| 118 | ``` |
| 119 | |
| 120 | Pass criteria: command exits 0 and `output/aliyun-dashvector-search/validate.txt` is generated. |
| 121 | |
| 122 | ## Output And Evidence |
| 123 | |
| 124 | - Save artifacts, command outputs, and API response summaries under `output/aliyun-dashvector-search/`. |
| 125 | - Include key parameters (region/resource id/time range) in evidence files for reproducibility. |
| 126 | |
| 127 | ## Workflow |
| 128 | |
| 129 | 1) Confirm user intent, region, identifiers, and whether the operation is read-only or mutating. |
| 130 | 2) Run one minimal read-only query first to verify connectivity and permissions. |
| 131 | 3) Execute the target operation with explicit parameters and bounded scope. |
| 132 | 4) Verify results and save output/evidence files. |
| 133 | |
| 134 | ## References |
| 135 | |
| 136 | - DashVector Python SDK: `Client.create`, `Collection.upsert`, `Collection.query` |
| 137 | |
| 138 | - Source list: `references/sources.md` |