@@ -197,17 +197,20 @@ func ExampleClient_CreateCollection_quickSetupCustomize() {
197197 ctx , cancel := context .WithCancel (context .Background ())
198198 defer cancel ()
199199
200- collectionName := `quick_setup_3`
201200 cli , err := milvusclient .New (ctx , & milvusclient.ClientConfig {
202201 Address : milvusAddr ,
203202 })
204203 if err != nil {
205204 // handle err
206205 }
207206
208- err = cli .CreateCollection (ctx , milvusclient .SimpleCreateCollectionOptions (collectionName , 512 ).
209- WithVarcharPK (true , 64 ).
210- WithShardNum (1 ),
207+ err = cli .CreateCollection (ctx , milvusclient .SimpleCreateCollectionOptions ("custom_quick_setup" , 512 ).
208+ WithPKFieldName ("my_id" ).
209+ WithVarcharPK (true , 512 ).
210+ WithVectorFieldName ("my_vector" ).
211+ WithMetricType (entity .L2 ).
212+ WithShardNum (5 ).
213+ WithAutoID (true ),
211214 )
212215 if err != nil {
213216 log .Println (err .Error ())
@@ -239,6 +242,132 @@ func ExampleClient_CreateCollection_consistencyLevel() {
239242 }
240243}
241244
245+ func ExampleClient_CreateCollection_withIndexes () {
246+ ctx , cancel := context .WithCancel (context .Background ())
247+ defer cancel ()
248+
249+ collectionName := `customized_setup_5`
250+
251+ cli , err := milvusclient .New (ctx , & milvusclient.ClientConfig {
252+ Address : milvusAddr ,
253+ })
254+ if err != nil {
255+ // handle err
256+ }
257+
258+ schema := entity .NewSchema ().WithDynamicFieldEnabled (true ).
259+ WithField (entity .NewField ().WithName ("my_id" ).WithIsAutoID (true ).WithDataType (entity .FieldTypeInt64 ).WithIsPrimaryKey (true )).
260+ WithField (entity .NewField ().WithName ("my_vector" ).WithDataType (entity .FieldTypeFloatVector ).WithDim (5 )).
261+ WithField (entity .NewField ().WithName ("my_varchar" ).WithDataType (entity .FieldTypeVarChar ).WithMaxLength (512 ))
262+
263+ idx := index .NewAutoIndex (entity .IP )
264+ indexOption := milvusclient .NewCreateIndexOption ("my_dense_collection" , "dense_vector" , idx )
265+
266+ err = cli .CreateCollection (ctx ,
267+ milvusclient .NewCreateCollectionOption (collectionName , schema ).
268+ WithIndexOptions (indexOption ))
269+ if err != nil {
270+ // handle error
271+ }
272+ }
273+
274+ func ExampleClient_CreateCollection_binaryVector () {
275+ ctx , cancel := context .WithCancel (context .Background ())
276+ defer cancel ()
277+
278+ collectionName := `my_binary_collection`
279+
280+ cli , err := milvusclient .New (ctx , & milvusclient.ClientConfig {
281+ Address : milvusAddr ,
282+ })
283+ if err != nil {
284+ // handle err
285+ }
286+
287+ schema := entity .NewSchema ()
288+ schema .WithField (entity .NewField ().
289+ WithName ("pk" ).
290+ WithDataType (entity .FieldTypeVarChar ).
291+ WithMaxLength (100 ).
292+ WithIsAutoID (true ),
293+ ).WithField (entity .NewField ().
294+ WithName ("binary_vector" ).
295+ WithDataType (entity .FieldTypeBinaryVector ).
296+ WithDim (128 ),
297+ )
298+
299+ idx := index .NewAutoIndex (entity .HAMMING )
300+ indexOption := milvusclient .NewCreateIndexOption ("my_binary_collection" , "binary_vector" , idx )
301+
302+ err = cli .CreateCollection (ctx ,
303+ milvusclient .NewCreateCollectionOption (collectionName , schema ).
304+ WithIndexOptions (indexOption ))
305+ if err != nil {
306+ // handle error
307+ }
308+ }
309+
310+ func ExampleClient_CreateCollection_jsonField () {
311+ ctx , cancel := context .WithCancel (context .Background ())
312+ defer cancel ()
313+
314+ cli , err := milvusclient .New (ctx , & milvusclient.ClientConfig {
315+ Address : milvusAddr ,
316+ })
317+ if err != nil {
318+ // handle err
319+ }
320+
321+ schema := entity .NewSchema ()
322+ schema .WithField (entity .NewField ().
323+ WithName ("pk" ).
324+ WithDataType (entity .FieldTypeInt64 ).
325+ WithIsAutoID (true ),
326+ ).WithField (entity .NewField ().
327+ WithName ("embedding" ).
328+ WithDataType (entity .FieldTypeFloatVector ).
329+ WithDim (3 ),
330+ ).WithField (entity .NewField ().
331+ WithName ("metadata" ).
332+ WithDataType (entity .FieldTypeJSON ),
333+ )
334+
335+ jsonIndex1 := index .NewJSONPathIndex (index .Inverted , "varchar" , `metadata["product_info"]["category"]` )
336+ jsonIndex2 := index .NewJSONPathIndex (index .Inverted , "double" , `metadata["price"]` )
337+ indexOpt1 := milvusclient .NewCreateIndexOption ("my_json_collection" , "meta" , jsonIndex1 )
338+ indexOpt2 := milvusclient .NewCreateIndexOption ("my_json_collection" , "meta" , jsonIndex2 )
339+
340+ vectorIndex := index .NewAutoIndex (entity .COSINE )
341+ indexOpt := milvusclient .NewCreateIndexOption ("my_json_collection" , "embedding" , vectorIndex )
342+
343+ err = cli .CreateCollection (ctx , milvusclient .NewCreateCollectionOption ("my_json_collection" , schema ).
344+ WithIndexOptions (indexOpt1 , indexOpt2 , indexOpt ))
345+ if err != nil {
346+ // handler err
347+ }
348+ }
349+
350+ func ExampleClient_CreateCollection_dynamicSchema () {
351+ ctx , cancel := context .WithCancel (context .Background ())
352+ defer cancel ()
353+
354+ // collectionName := `my_dynamic_collection`
355+
356+ cli , err := milvusclient .New (ctx , & milvusclient.ClientConfig {
357+ Address : milvusAddr ,
358+ })
359+ if err != nil {
360+ // handle err
361+ }
362+
363+ err = cli .CreateCollection (ctx ,
364+ milvusclient .SimpleCreateCollectionOptions ("my_dynamic_collection" , 5 ).
365+ WithDynamicSchema (true ))
366+ if err != nil {
367+ // handle error
368+ }
369+ }
370+
242371func ExampleClient_ListCollections () {
243372 ctx , cancel := context .WithCancel (context .Background ())
244373 defer cancel ()
0 commit comments