@ia-ccun/code-agent-cli 0.0.52-beta.5 → 0.0.52-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/config/agent/bin/README.md +112 -0
  2. package/config/agent/bin/fd-win.zip +0 -0
  3. package/config/agent/bin/rg-win.zip +0 -0
  4. package/config/agent/extensions/aicode-safety-guard.ts +2 -2
  5. package/config/agent/extensions/aicode-tips.ts +8 -0
  6. package/config/agent/skills/chroma/LICENSE +21 -0
  7. package/config/agent/skills/chroma/chroma-local/SKILL.md +165 -0
  8. package/config/agent/skills/chroma/chroma-local/cli.md +48 -0
  9. package/config/agent/skills/chroma/chroma-local/data-model.md +103 -0
  10. package/config/agent/skills/chroma/chroma-local/error-handling/python.md +166 -0
  11. package/config/agent/skills/chroma/chroma-local/error-handling/typescript.md +231 -0
  12. package/config/agent/skills/chroma/chroma-local/local-chroma/python.md +95 -0
  13. package/config/agent/skills/chroma/chroma-local/local-chroma/typescript.md +101 -0
  14. package/config/agent/skills/chroma/chroma-local/metadata/python.md +154 -0
  15. package/config/agent/skills/chroma/chroma-local/metadata/typescript.md +153 -0
  16. package/config/agent/skills/chroma/chroma-local/querying/python.md +147 -0
  17. package/config/agent/skills/chroma/chroma-local/querying/typescript.md +157 -0
  18. package/config/agent/skills/chroma/chroma-local/regex/python.md +69 -0
  19. package/config/agent/skills/chroma/chroma-local/regex/typescript.md +71 -0
  20. package/config/agent/skills/chroma/chroma-local/understanding-a-codebase.md +80 -0
  21. package/config/agent/skills/chroma/chroma-local/updating-deleting/python.md +159 -0
  22. package/config/agent/skills/chroma/chroma-local/updating-deleting/typescript.md +228 -0
  23. package/config/agent/skills/milvus-skill/LICENSE +202 -0
  24. package/config/agent/skills/milvus-skill/README.md +37 -0
  25. package/config/agent/skills/milvus-skill/SKILL.md +259 -0
  26. package/config/agent/skills/milvus-skill/references/collection.md +86 -0
  27. package/config/agent/skills/milvus-skill/references/database.md +24 -0
  28. package/config/agent/skills/milvus-skill/references/index.md +69 -0
  29. package/config/agent/skills/milvus-skill/references/partition.md +29 -0
  30. package/config/agent/skills/milvus-skill/references/patterns.md +150 -0
  31. package/config/agent/skills/milvus-skill/references/user-role.md +90 -0
  32. package/config/agent/skills/milvus-skill/references/vector.md +247 -0
  33. package/package.json +5 -5
@@ -0,0 +1,259 @@
1
+ ---
2
+ name: milvus
3
+ description: Operate Milvus vector database with pymilvus Python SDK. Use when the user wants to connect to Milvus, create collections, insert vectors, perform similarity search, hybrid search, full-text search, manage indexes, partitions, databases, or RBAC via Python code.
4
+ license: Apache-2.0
5
+ compatibility: Requires Python 3.8+ and pymilvus (pip install pymilvus). Runs on macOS and Linux.
6
+ metadata:
7
+ author: zilliztech
8
+ version: "1.0.0"
9
+ allowed-tools: Bash Read Write
10
+ ---
11
+
12
+ # Milvus Vector Database Skill
13
+
14
+ Operate [Milvus](https://milvus.io/) vector databases directly through Python code using the `pymilvus` SDK. Covers the full lifecycle — connecting, schema design, collection management, vector CRUD, search, hybrid search, full-text search, indexing, partitions, databases, and RBAC.
15
+
16
+ ## When to Use
17
+
18
+ Use this skill when the user wants to:
19
+ - Connect to a Milvus instance (local, standalone, cluster, or Milvus Lite)
20
+ - Create collections with custom schemas
21
+ - Insert, upsert, search, query, get, or delete vectors
22
+ - Perform hybrid search with reranking
23
+ - Perform full-text search (BM25)
24
+ - Manage indexes, partitions, databases
25
+ - Set up users, roles, and access control (RBAC)
26
+ - Build RAG pipelines, semantic search, or recommendation systems with Milvus
27
+ - Iterate over large result sets with search/query iterators
28
+
29
+ ## Requirements
30
+
31
+ - Python 3.8+
32
+ - `pymilvus` (`pip install pymilvus`)
33
+ - A running Milvus instance, or use Milvus Lite (embedded, file-based) for development
34
+
35
+ ## Capabilities Overview
36
+
37
+ | Area | What You Can Do |
38
+ |------|----------------|
39
+ | **Connection** | Connect to Milvus Lite, Standalone, Cluster, or Zilliz Cloud |
40
+ | **Collections** | Create (quick or custom schema), list, describe, drop, rename, truncate, load, release |
41
+ | **Vectors** | Insert, upsert, search, hybrid search, query, get, delete |
42
+ | **Full-Text Search** | BM25-based keyword search with sparse vectors |
43
+ | **Iterators** | Paginated search and query over large datasets |
44
+ | **Indexes** | Create (AUTOINDEX, HNSW, IVF_FLAT, etc.), list, describe, drop |
45
+ | **Partitions** | Create, list, load, release, drop |
46
+ | **Databases** | Create, list, switch, drop |
47
+ | **RBAC** | Users, roles, privileges management |
48
+
49
+ ---
50
+
51
+ ## Connection
52
+
53
+ > **IMPORTANT: Before writing any connection code, you MUST ask the user for their connection details.** Ask:
54
+ > 1. **Deployment type** — Milvus Lite (local file), Standalone/Cluster (self-hosted), or Zilliz Cloud (managed)?
55
+ > 2. **URI** — For self-hosted: host and port (e.g., `http://localhost:19530`). For Zilliz Cloud: the endpoint URL.
56
+ > 3. **Authentication** — Token, API key, or username/password if required.
57
+ > 4. **Database name** — If not using the default database.
58
+ >
59
+ > **Never assume or hardcode connection parameters.** Use Milvus Lite (`uri="./milvus.db"`) only if the user explicitly wants local/embedded mode for development.
60
+
61
+ ```python
62
+ from pymilvus import MilvusClient
63
+
64
+ # Milvus Lite (embedded, file-based — great for dev/test)
65
+ client = MilvusClient(uri="./milvus.db")
66
+
67
+ # Standalone / Cluster Milvus (ask user for actual host:port and credentials)
68
+ client = MilvusClient(uri="<USER_URI>", token="<USER_TOKEN>")
69
+
70
+ # Zilliz Cloud (ask user for endpoint and API key)
71
+ client = MilvusClient(uri="<USER_ZILLIZ_ENDPOINT>", token="<USER_API_KEY>")
72
+ ```
73
+
74
+ **Parameters:**
75
+
76
+ | Parameter | Type | Description |
77
+ |-----------|------|-------------|
78
+ | `uri` | str | `"./file.db"` for Milvus Lite, `"http://host:19530"` for server |
79
+ | `token` | str | API key or `"username:password"` |
80
+ | `user` | str | Username (alternative to token) |
81
+ | `password` | str | Password (alternative to token) |
82
+ | `db_name` | str | Target database (default: `"default"`) |
83
+ | `timeout` | float | Operation timeout in seconds |
84
+
85
+ ### Async Client
86
+
87
+ ```python
88
+ from pymilvus import AsyncMilvusClient
89
+
90
+ async with AsyncMilvusClient(uri="<USER_URI>") as client:
91
+ results = await client.search(collection_name="my_collection", data=[query_vector], limit=10)
92
+ ```
93
+
94
+ ---
95
+
96
+ ## Collection Management
97
+
98
+ ### Quick Create (auto schema + auto index + auto load)
99
+
100
+ ```python
101
+ client.create_collection(
102
+ collection_name="my_collection",
103
+ dimension=768,
104
+ metric_type="COSINE" # Optional: "COSINE" (default), "L2", "IP"
105
+ )
106
+ ```
107
+
108
+ This automatically creates an `id` field (INT64, primary key, auto_id), a `vector` field (FLOAT_VECTOR), AUTOINDEX, and auto-loads the collection.
109
+
110
+ ### Custom Schema Create
111
+
112
+ ```python
113
+ from pymilvus import DataType
114
+
115
+ schema = client.create_schema(auto_id=False, enable_dynamic_field=True)
116
+ schema.add_field("id", DataType.INT64, is_primary=True)
117
+ schema.add_field("text", DataType.VARCHAR, max_length=512)
118
+ schema.add_field("embedding", DataType.FLOAT_VECTOR, dim=768)
119
+
120
+ index_params = client.prepare_index_params()
121
+ index_params.add_index(field_name="embedding", index_type="AUTOINDEX", metric_type="COSINE")
122
+
123
+ client.create_collection(collection_name="my_collection", schema=schema, index_params=index_params)
124
+ ```
125
+
126
+ **See [references/collection.md](references/collection.md) for data types, add_field parameters, and all collection operations.**
127
+
128
+ ### Other Collection Operations
129
+
130
+ ```python
131
+ client.list_collections()
132
+ client.describe_collection(collection_name="my_collection")
133
+ client.has_collection(collection_name="my_collection")
134
+ client.rename_collection(old_name="old", new_name="new")
135
+ client.drop_collection(collection_name="my_collection")
136
+ client.truncate_collection(collection_name="my_collection")
137
+ client.load_collection(collection_name="my_collection")
138
+ client.release_collection(collection_name="my_collection")
139
+ client.get_load_state(collection_name="my_collection")
140
+ client.get_collection_stats(collection_name="my_collection")
141
+ ```
142
+
143
+ - Quick create is best for prototyping; use custom schema for production.
144
+ - A collection must be **loaded** before search or query.
145
+ - Use `enable_dynamic_field=True` to allow inserting fields not defined in the schema.
146
+
147
+ ---
148
+
149
+ ## Vector Operations
150
+
151
+ **See [references/vector.md](references/vector.md) for hybrid search, full-text search, iterators, filter syntax, and detailed examples.**
152
+
153
+ ### Insert / Upsert
154
+
155
+ ```python
156
+ # Vectors must come from an embedding model — never use fake/placeholder vectors
157
+ from pymilvus import model
158
+
159
+ embedding_fn = model.dense.SentenceTransformerEmbeddingFunction(model_name="all-MiniLM-L6-v2")
160
+
161
+ docs = ["AI advances in 2024", "ML basics for beginners"]
162
+ vectors = embedding_fn.encode_documents(docs)
163
+
164
+ data = [
165
+ {"id": 1, "text": docs[0], "embedding": vectors[0]},
166
+ {"id": 2, "text": docs[1], "embedding": vectors[1]},
167
+ ]
168
+ client.insert(collection_name="my_collection", data=data)
169
+ client.upsert(collection_name="my_collection", data=data)
170
+ ```
171
+
172
+ ### Search (vector similarity)
173
+
174
+ ```python
175
+ # Use the same embedding model to encode the query
176
+ query_vectors = embedding_fn.encode_queries(["What is artificial intelligence?"])
177
+
178
+ results = client.search(
179
+ collection_name="my_collection",
180
+ data=query_vectors,
181
+ anns_field="embedding",
182
+ limit=10,
183
+ output_fields=["text", "id"],
184
+ filter='age > 20 and status == "active"',
185
+ search_params={"metric_type": "COSINE", "params": {"nprobe": 10}}
186
+ )
187
+ ```
188
+
189
+ ### Query / Get / Delete
190
+
191
+ ```python
192
+ # Query by filter
193
+ client.query(collection_name="my_collection", filter='id in [1, 2, 3]', output_fields=["text"], limit=100)
194
+
195
+ # Get by primary key
196
+ client.get(collection_name="my_collection", ids=[1, 2, 3], output_fields=["text"])
197
+
198
+ # Delete
199
+ client.delete(collection_name="my_collection", ids=[1, 2, 3])
200
+ client.delete(collection_name="my_collection", filter='status == "obsolete"')
201
+ ```
202
+
203
+ - **Never use fake or placeholder vectors** (e.g., `[0.1, 0.2, ...]`). Always generate vectors from an embedding model.
204
+ - Use `pip install "pymilvus[model]"` for built-in embedding functions, or use any embedding model (OpenAI, Cohere, etc.).
205
+ - Vector dimension in search must match the collection schema exactly.
206
+ - The query embedding model must be the **same model** used to generate the stored vectors.
207
+ - For large inserts, batch data into chunks (e.g., 1000 rows per batch).
208
+ - For large result sets, use iterators — see [references/vector.md](references/vector.md).
209
+
210
+ ---
211
+
212
+ ## Index Management
213
+
214
+ **See [references/index.md](references/index.md) for index types, metric types, and parameters.**
215
+
216
+ ```python
217
+ index_params = client.prepare_index_params()
218
+ index_params.add_index(
219
+ field_name="embedding",
220
+ index_type="HNSW",
221
+ metric_type="COSINE",
222
+ params={"M": 16, "efConstruction": 256}
223
+ )
224
+ client.create_index(collection_name="my_collection", index_params=index_params)
225
+
226
+ client.list_indexes(collection_name="my_collection")
227
+ client.describe_index(collection_name="my_collection", index_name="my_index")
228
+ client.drop_index(collection_name="my_collection", index_name="my_index")
229
+ ```
230
+
231
+ - `AUTOINDEX` is recommended for most use cases.
232
+ - An index is required before loading a collection.
233
+
234
+ ---
235
+
236
+ ## Additional Features
237
+
238
+ | Feature | Reference |
239
+ |---------|-----------|
240
+ | Partition Management | [references/partition.md](references/partition.md) |
241
+ | Database Management | [references/database.md](references/database.md) |
242
+ | User & Role Management (RBAC) | [references/user-role.md](references/user-role.md) |
243
+ | Common Patterns (RAG, Semantic Search) | [references/patterns.md](references/patterns.md) |
244
+
245
+ ---
246
+
247
+ ## General Guidance
248
+
249
+ - **Always ask the user for connection details** (URI, token/credentials) before writing connection code. Never assume or hardcode connection parameters.
250
+ - **Never generate fake or placeholder vectors.** Always use an embedding model to produce real vectors. Suggest `pip install "pymilvus[model]"` for built-in embedding functions.
251
+ - For quick prototyping, use **Milvus Lite** (`uri="./file.db"`) — no server needed, but only if the user explicitly requests local/embedded mode.
252
+ - A collection must be **loaded into memory** before search/query.
253
+ - The vector dimension in search data must **exactly match** the collection schema.
254
+ - The query embedding model must be the **same model** used to generate the stored vectors.
255
+ - Before any destructive operation (drop collection, drop database, delete vectors), always confirm with the user.
256
+ - Use `enable_dynamic_field=True` when the schema may evolve.
257
+ - Prefer `AUTOINDEX` unless the user has specific performance requirements.
258
+ - Use `truncate_collection` to clear all data without dropping the collection.
259
+ - For large datasets, use iterators (`search_iterator`, `query_iterator`) instead of increasing limit.
@@ -0,0 +1,86 @@
1
+ # Collection Management — Detailed Reference
2
+
3
+ ## Supported Data Types
4
+
5
+ ### Scalar Types
6
+
7
+ | DataType | Notes |
8
+ |----------|-------|
9
+ | `DataType.BOOL` | Boolean |
10
+ | `DataType.INT8` / `INT16` / `INT32` / `INT64` | Integers |
11
+ | `DataType.FLOAT` / `DOUBLE` | Floating point |
12
+ | `DataType.VARCHAR` | String (requires `max_length`) |
13
+ | `DataType.JSON` | JSON object |
14
+ | `DataType.ARRAY` | Array (requires `element_type`, `max_capacity`) |
15
+
16
+ ### Vector Types
17
+
18
+ | DataType | Notes |
19
+ |----------|-------|
20
+ | `DataType.FLOAT_VECTOR` | Float32 vector (requires `dim`) |
21
+ | `DataType.FLOAT16_VECTOR` | Float16 vector (requires `dim`) |
22
+ | `DataType.BFLOAT16_VECTOR` | BFloat16 vector (requires `dim`) |
23
+ | `DataType.BINARY_VECTOR` | Binary vector (requires `dim`) |
24
+ | `DataType.SPARSE_FLOAT_VECTOR` | Sparse vector (no `dim` needed) |
25
+ | `DataType.INT8_VECTOR` | Int8 vector (requires `dim`) |
26
+
27
+ ## add_field Parameters
28
+
29
+ ```python
30
+ schema.add_field(
31
+ field_name="my_field",
32
+ datatype=DataType.VARCHAR,
33
+ is_primary=False,
34
+ auto_id=False,
35
+ max_length=256, # Required for VARCHAR
36
+ dim=768, # Required for vector types (except sparse)
37
+ element_type=DataType.INT64, # Required for ARRAY
38
+ max_capacity=100, # Required for ARRAY
39
+ nullable=False,
40
+ default_value=None,
41
+ is_partition_key=False,
42
+ description=""
43
+ )
44
+ ```
45
+
46
+ ## All Collection Operations
47
+
48
+ ```python
49
+ # List all collections
50
+ collections = client.list_collections()
51
+
52
+ # Describe a collection
53
+ info = client.describe_collection(collection_name="my_collection")
54
+
55
+ # Check if collection exists
56
+ exists = client.has_collection(collection_name="my_collection")
57
+
58
+ # Rename a collection
59
+ client.rename_collection(old_name="old_name", new_name="new_name")
60
+
61
+ # Drop a collection
62
+ client.drop_collection(collection_name="my_collection")
63
+
64
+ # Truncate a collection (delete all data, keep schema and index)
65
+ client.truncate_collection(collection_name="my_collection")
66
+
67
+ # Load collection into memory (required before search/query)
68
+ client.load_collection(collection_name="my_collection")
69
+
70
+ # Release collection from memory
71
+ client.release_collection(collection_name="my_collection")
72
+
73
+ # Get load state
74
+ state = client.get_load_state(collection_name="my_collection")
75
+
76
+ # Get collection statistics
77
+ stats = client.get_collection_stats(collection_name="my_collection")
78
+ ```
79
+
80
+ ## Guidance
81
+
82
+ - Quick create is best for prototyping; use custom schema for production.
83
+ - A collection must be **loaded** before search or query operations.
84
+ - Before dropping a collection, confirm with the user — this deletes all data.
85
+ - Use `enable_dynamic_field=True` to allow inserting fields not defined in the schema.
86
+ - Use `truncate_collection` to clear all data while preserving the collection structure.
@@ -0,0 +1,24 @@
1
+ # Database Management
2
+
3
+ ```python
4
+ # Create a database
5
+ client.create_database(db_name="my_database")
6
+
7
+ # List all databases
8
+ databases = client.list_databases()
9
+ # Returns: ["default", "my_database"]
10
+
11
+ # Switch to a database
12
+ client.using_database(db_name="my_database")
13
+
14
+ # Drop a database (must drop all collections first)
15
+ client.drop_database(db_name="my_database")
16
+
17
+ # Or connect to a specific database at init (use the user's actual URI and credentials)
18
+ client = MilvusClient(uri="<USER_URI>", token="<USER_TOKEN>", db_name="my_database")
19
+ ```
20
+
21
+ ## Guidance
22
+
23
+ - Every Milvus instance has a `"default"` database.
24
+ - Before dropping a database, all collections in it must be dropped first.
@@ -0,0 +1,69 @@
1
+ # Index Management — Detailed Reference
2
+
3
+ ## Create Index
4
+
5
+ ```python
6
+ index_params = client.prepare_index_params()
7
+
8
+ # Vector index
9
+ index_params.add_index(
10
+ field_name="embedding",
11
+ index_type="HNSW", # See index types table below
12
+ metric_type="COSINE", # "COSINE", "L2", "IP"
13
+ params={"M": 16, "efConstruction": 256}
14
+ )
15
+
16
+ # Optional: scalar index
17
+ index_params.add_index(
18
+ field_name="text",
19
+ index_type="" # Auto-select for scalars
20
+ )
21
+
22
+ client.create_index(
23
+ collection_name="my_collection",
24
+ index_params=index_params
25
+ )
26
+ ```
27
+
28
+ ## Common Index Types
29
+
30
+ | Index Type | For | Key Params | Notes |
31
+ |------------|-----|------------|-------|
32
+ | `AUTOINDEX` | Dense vectors | Auto-tuned | Recommended for most cases |
33
+ | `FLAT` | Dense vectors | None | Brute force, 100% recall |
34
+ | `IVF_FLAT` | Dense vectors | `nlist` | Good balance |
35
+ | `IVF_SQ8` | Dense vectors | `nlist` | Compressed, less memory |
36
+ | `HNSW` | Dense vectors | `M`, `efConstruction` | High recall, more memory |
37
+ | `DISKANN` | Dense vectors | None | Disk-based, large datasets |
38
+ | `SPARSE_INVERTED_INDEX` | Sparse vectors | `drop_ratio_build` | For sparse vectors |
39
+ | `SPARSE_WAND` | Sparse vectors | `drop_ratio_build` | Faster sparse search |
40
+
41
+ ## Metric Types
42
+
43
+ | Metric | Description | Use With |
44
+ |--------|-------------|----------|
45
+ | `"COSINE"` | Cosine similarity (larger = more similar) | Dense vectors |
46
+ | `"L2"` | Euclidean distance (smaller = more similar) | Dense vectors |
47
+ | `"IP"` | Inner product (larger = more similar) | Dense & Sparse vectors |
48
+ | `"BM25"` | BM25 relevance scoring | Full-text search (sparse vectors from built-in tokenizer) |
49
+
50
+ ## Other Index Operations
51
+
52
+ ```python
53
+ # List indexes
54
+ indexes = client.list_indexes(collection_name="my_collection")
55
+
56
+ # Describe an index
57
+ info = client.describe_index(collection_name="my_collection", index_name="my_index")
58
+
59
+ # Drop an index
60
+ client.drop_index(collection_name="my_collection", index_name="my_index")
61
+ ```
62
+
63
+ ## Guidance
64
+
65
+ - `AUTOINDEX` is recommended for most use cases.
66
+ - An index is required before loading a collection.
67
+ - After creating an index, load the collection before searching.
68
+ - Sparse vectors only support `"IP"` metric type.
69
+ - For full-text search, use `"BM25"` metric type with `SPARSE_INVERTED_INDEX` or `SPARSE_WAND`.
@@ -0,0 +1,29 @@
1
+ # Partition Management
2
+
3
+ ```python
4
+ # Create a partition
5
+ client.create_partition(collection_name="my_collection", partition_name="partition_A")
6
+
7
+ # List partitions
8
+ partitions = client.list_partitions(collection_name="my_collection")
9
+ # Returns: ["_default", "partition_A"]
10
+
11
+ # Check if partition exists
12
+ exists = client.has_partition(collection_name="my_collection", partition_name="partition_A")
13
+
14
+ # Load specific partitions
15
+ client.load_partitions(collection_name="my_collection", partition_names=["partition_A"])
16
+
17
+ # Release specific partitions
18
+ client.release_partitions(collection_name="my_collection", partition_names=["partition_A"])
19
+
20
+ # Drop a partition
21
+ client.drop_partition(collection_name="my_collection", partition_name="partition_A")
22
+ ```
23
+
24
+ ## Guidance
25
+
26
+ - Every collection has a `_default` partition.
27
+ - Use `is_partition_key=True` on a field to enable automatic partitioning by field value.
28
+ - A partition must be loaded before search.
29
+ - Before dropping a partition, confirm with the user — all data in it will be deleted.
@@ -0,0 +1,150 @@
1
+ # Common Patterns
2
+
3
+ > **Note:** All patterns below use `<USER_URI>` and `<USER_TOKEN>` as connection placeholders. Always ask the user for their actual connection details before writing code. For local development, use Milvus Lite (`uri="./milvus.db"`) only if the user explicitly requests it.
4
+
5
+ ## RAG Pipeline Pattern
6
+
7
+ ```python
8
+ from pymilvus import MilvusClient, DataType, model
9
+
10
+ # 1. Connect (ask user for URI and credentials)
11
+ client = MilvusClient(uri="<USER_URI>", token="<USER_TOKEN>")
12
+
13
+ # 2. Set up embedding model
14
+ embedding_fn = model.dense.SentenceTransformerEmbeddingFunction(model_name="all-MiniLM-L6-v2")
15
+
16
+ # 3. Create collection (dim must match embedding model output)
17
+ schema = client.create_schema(auto_id=True, enable_dynamic_field=True)
18
+ schema.add_field("id", DataType.INT64, is_primary=True)
19
+ schema.add_field("text", DataType.VARCHAR, max_length=2048)
20
+ schema.add_field("embedding", DataType.FLOAT_VECTOR, dim=384) # all-MiniLM-L6-v2 outputs 384-dim
21
+ schema.add_field("source", DataType.VARCHAR, max_length=256)
22
+
23
+ index_params = client.prepare_index_params()
24
+ index_params.add_index(field_name="embedding", index_type="AUTOINDEX", metric_type="COSINE")
25
+
26
+ client.create_collection(collection_name="knowledge_base", schema=schema, index_params=index_params)
27
+
28
+ # 4. Insert documents — generate real vectors from text chunks
29
+ chunks = ["Milvus is a vector database...", "RAG combines retrieval and generation..."]
30
+ vectors = embedding_fn.encode_documents(chunks)
31
+
32
+ client.insert("knowledge_base", data=[
33
+ {"text": chunk, "embedding": vec, "source": "doc1.pdf"}
34
+ for chunk, vec in zip(chunks, vectors)
35
+ ])
36
+
37
+ # 5. Retrieve relevant context — use the SAME embedding model
38
+ query = "What is a vector database?"
39
+ query_vectors = embedding_fn.encode_queries([query])
40
+
41
+ results = client.search(
42
+ collection_name="knowledge_base",
43
+ data=query_vectors,
44
+ limit=5,
45
+ output_fields=["text", "source"],
46
+ search_params={"metric_type": "COSINE"}
47
+ )
48
+ ```
49
+
50
+ ## Quick Semantic Search Pattern
51
+
52
+ ```python
53
+ from pymilvus import MilvusClient, model
54
+
55
+ # Simplest possible setup (Milvus Lite for local dev)
56
+ client = MilvusClient(uri="./search.db")
57
+ embedding_fn = model.dense.SentenceTransformerEmbeddingFunction(model_name="all-MiniLM-L6-v2")
58
+
59
+ # Prepare data — vectors come from embedding model
60
+ texts = ["first document", "second document", "third document"]
61
+ vectors = embedding_fn.encode_documents(texts)
62
+
63
+ client.create_collection(collection_name="docs", dimension=384)
64
+ client.insert("docs", data=[
65
+ {"id": i, "vector": vec, "text": txt}
66
+ for i, (vec, txt) in enumerate(zip(vectors, texts))
67
+ ])
68
+
69
+ # Search — encode query with the same model
70
+ query_vectors = embedding_fn.encode_queries(["search query"])
71
+ results = client.search("docs", data=query_vectors, limit=10, output_fields=["text"])
72
+ ```
73
+
74
+ ## Hybrid Search Pattern (Dense + Sparse)
75
+
76
+ ```python
77
+ from pymilvus import MilvusClient, DataType, AnnSearchRequest, RRFRanker
78
+
79
+ # Ask user for connection details
80
+ client = MilvusClient(uri="<USER_URI>", token="<USER_TOKEN>")
81
+
82
+ # Schema with both dense and sparse vectors
83
+ schema = client.create_schema(auto_id=True)
84
+ schema.add_field("id", DataType.INT64, is_primary=True)
85
+ schema.add_field("text", DataType.VARCHAR, max_length=2048)
86
+ schema.add_field("dense_embedding", DataType.FLOAT_VECTOR, dim=768)
87
+ schema.add_field("sparse_embedding", DataType.SPARSE_FLOAT_VECTOR)
88
+
89
+ index_params = client.prepare_index_params()
90
+ index_params.add_index(field_name="dense_embedding", index_type="AUTOINDEX", metric_type="COSINE")
91
+ index_params.add_index(field_name="sparse_embedding", index_type="SPARSE_INVERTED_INDEX", metric_type="IP")
92
+
93
+ client.create_collection(collection_name="hybrid_col", schema=schema, index_params=index_params)
94
+
95
+ # Search with both vectors and fuse results
96
+ # dense_query_vector and sparse_query_vector come from your respective embedding models
97
+ req1 = AnnSearchRequest(data=[dense_query_vector], anns_field="dense_embedding",
98
+ param={"metric_type": "COSINE"}, limit=20)
99
+ req2 = AnnSearchRequest(data=[sparse_query_vector], anns_field="sparse_embedding",
100
+ param={"metric_type": "IP"}, limit=20)
101
+
102
+ results = client.hybrid_search(
103
+ collection_name="hybrid_col",
104
+ reqs=[req1, req2],
105
+ ranker=RRFRanker(k=60),
106
+ limit=10,
107
+ output_fields=["text"]
108
+ )
109
+ ```
110
+
111
+ ## Full-Text Search Pattern (BM25)
112
+
113
+ ```python
114
+ from pymilvus import MilvusClient, DataType, Function, FunctionType
115
+
116
+ # Ask user for connection details
117
+ client = MilvusClient(uri="<USER_URI>", token="<USER_TOKEN>")
118
+
119
+ schema = client.create_schema(auto_id=True)
120
+ schema.add_field("id", DataType.INT64, is_primary=True)
121
+ schema.add_field("title", DataType.VARCHAR, max_length=512)
122
+ schema.add_field("body", DataType.VARCHAR, max_length=4096, enable_analyzer=True)
123
+ schema.add_field("body_sparse", DataType.SPARSE_FLOAT_VECTOR)
124
+
125
+ schema.add_function(Function(
126
+ name="body_bm25",
127
+ input_field_names=["body"],
128
+ output_field_names=["body_sparse"],
129
+ function_type=FunctionType.BM25,
130
+ ))
131
+
132
+ index_params = client.prepare_index_params()
133
+ index_params.add_index(field_name="body_sparse", index_type="AUTOINDEX", metric_type="BM25")
134
+
135
+ client.create_collection(collection_name="articles", schema=schema, index_params=index_params)
136
+
137
+ # Insert — only provide text, sparse vector is auto-generated by BM25 function
138
+ client.insert("articles", data=[
139
+ {"title": "Intro to ML", "body": "Machine learning is a subset of artificial intelligence..."},
140
+ ])
141
+
142
+ # Search with raw text — no embedding model needed, Milvus handles BM25 tokenization
143
+ results = client.search(
144
+ collection_name="articles",
145
+ data=["machine learning fundamentals"],
146
+ anns_field="body_sparse",
147
+ limit=10,
148
+ output_fields=["title", "body"]
149
+ )
150
+ ```