Skip to content

Commit 89a1159

Browse files
authored
enhance: [2.5][GoSDK] Cherry-pick commits and bump version to 2.5.2 (#41235)
Cherry-pick from master pr: #41161 #41197 #41234 Related to #41108 #40928 Also this PR bump milvusclient go SDK version to v2.5.2 --------- Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
1 parent de6687e commit 89a1159

File tree

11 files changed

+572
-7
lines changed

11 files changed

+572
-7
lines changed

client/common/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ package common
1818

1919
const (
2020
// SDKVersion const value for current version
21-
SDKVersion = `2.5.1`
21+
SDKVersion = `2.5.2`
2222
)
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// Licensed to the LF AI & Data foundation under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
// nolint
18+
package entity_test
19+
20+
import (
21+
"log"
22+
23+
"github.com/milvus-io/milvus/client/v2/entity"
24+
)
25+
26+
func ExampleNewSchema() {
27+
schema := entity.NewSchema()
28+
log.Println(schema)
29+
}
30+
31+
func ExampleSchema_WithField_primaryKey() {
32+
schema := entity.NewSchema()
33+
schema.WithField(entity.NewField().WithName("my_id").
34+
WithDataType(entity.FieldTypeInt64).
35+
WithIsPrimaryKey(true).
36+
WithIsAutoID(false),
37+
)
38+
}
39+
40+
func ExampleSchema_WithField_varcharPK() {
41+
schema := entity.NewSchema()
42+
schema.WithField(entity.NewField().WithName("my_id").
43+
WithDataType(entity.FieldTypeVarChar).
44+
WithIsPrimaryKey(true).
45+
WithMaxLength(100),
46+
)
47+
}
48+
49+
func ExampleSchema_WithField_vectorField() {
50+
schema := entity.NewSchema()
51+
schema.WithField(entity.NewField().WithName("my_vector").
52+
WithDataType(entity.FieldTypeFloatVector).
53+
WithDim(5),
54+
)
55+
}
56+
57+
func ExampleSchema_WithField_varcharField() {
58+
schema := entity.NewSchema()
59+
schema.WithField(entity.NewField().WithName("my_varchar").
60+
WithDataType(entity.FieldTypeVarChar).
61+
WithMaxLength(512),
62+
)
63+
}
64+
65+
func ExampleSchema_WithField_int64Field() {
66+
schema := entity.NewSchema()
67+
schema.WithField(entity.NewField().WithName("my_int64").
68+
WithDataType(entity.FieldTypeInt64),
69+
)
70+
}
71+
72+
func ExampleSchema_WithField_boolField() {
73+
schema := entity.NewSchema()
74+
schema.WithField(entity.NewField().WithName("my_bool").
75+
WithDataType(entity.FieldTypeBool),
76+
)
77+
}
78+
79+
func ExampleSchema_WithField_jsonField() {
80+
schema := entity.NewSchema()
81+
schema.WithField(entity.NewField().WithName("my_json").
82+
WithDataType(entity.FieldTypeJSON),
83+
)
84+
}
85+
86+
func ExampleSchema_WithField_arrayField() {
87+
schema := entity.NewSchema()
88+
schema.WithField(entity.NewField().WithName("my_array").
89+
WithDataType(entity.FieldTypeArray).
90+
WithElementType(entity.FieldTypeInt64).
91+
WithMaxLength(512).
92+
WithMaxCapacity(5),
93+
)
94+
}
95+
96+
func ExampleSchema_WithField_pkAndVector() {
97+
schema := entity.NewSchema()
98+
schema.WithField(entity.NewField().
99+
WithName("pk").
100+
WithDataType(entity.FieldTypeVarChar).
101+
WithMaxLength(100),
102+
).WithField(entity.NewField().
103+
WithName("dense_vector").
104+
WithDataType(entity.FieldTypeFloatVector).
105+
WithDim(4),
106+
)
107+
}
108+
109+
func ExampleSchema_WithField_binaryVector() {
110+
schema := entity.NewSchema()
111+
schema.WithField(entity.NewField().
112+
WithName("pk").
113+
WithDataType(entity.FieldTypeVarChar).
114+
WithMaxLength(100).
115+
WithIsAutoID(true),
116+
).WithField(entity.NewField().
117+
WithName("binary_vector").
118+
WithDataType(entity.FieldTypeBinaryVector).
119+
WithDim(128),
120+
)
121+
}

client/index/auto_example_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Licensed to the LF AI & Data foundation under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
// nolint
18+
package index_test
19+
20+
import (
21+
"log"
22+
23+
"github.com/milvus-io/milvus/client/v2/entity"
24+
"github.com/milvus-io/milvus/client/v2/index"
25+
)
26+
27+
func ExampleNewAutoIndex() {
28+
index := index.NewAutoIndex(entity.L2)
29+
log.Println(index)
30+
}

client/milvusclient/collection_example_test.go

Lines changed: 133 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
242371
func ExampleClient_ListCollections() {
243372
ctx, cancel := context.WithCancel(context.Background())
244373
defer cancel()

client/milvusclient/index_example_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,32 @@ func ExampleClient_CreateIndex() {
4949
}
5050
}
5151

52+
func ExampleClient_CreateIndex_jsonPathIndex_dynamicField() {
53+
ctx, cancel := context.WithCancel(context.Background())
54+
defer cancel()
55+
56+
cli, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
57+
Address: milvusAddr,
58+
})
59+
if err != nil {
60+
// handle err
61+
}
62+
63+
jsonPathIndex := index.NewJSONPathIndex(index.Inverted,
64+
"varchar", // cast type
65+
"color", // json path
66+
)
67+
indexTask, err := cli.CreateIndex(ctx, milvusclient.NewCreateIndexOption("my_dynamic_collection", "color", jsonPathIndex))
68+
if err != nil {
69+
// handler err
70+
}
71+
72+
err = indexTask.Await(ctx)
73+
if err != nil {
74+
// handler err
75+
}
76+
}
77+
5278
func ExampleClient_DescribeIndex() {
5379
ctx, cancel := context.WithCancel(context.Background())
5480
defer cancel()

0 commit comments

Comments
 (0)