Repository: milvus-io/milvus-sdk-go
Pull request #504 (2023-06-28 02:57:12)

Add forTuning option
milvus issue: https://github.com/milvus-io/milvus/issues/25151

sre-ci-robot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by: *<a href="https://github.com/milvus-io/milvus-sdk-go/pull/504#" title="Author self-approved">chasingegg</a>*
To complete the [pull request process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process), please assign **congqixia** after the PR has been reviewed.
You can assign the PR to them by writing `/assign @congqixia` in a comment when ready.

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=milvus-io%2Fmilvus-sdk-go).

<details open>
Needs approval from an approver in each of these files:

- **[OWNERS](https://github.com/milvus-io/milvus-sdk-go/blob/master/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["congqixia"]} -->
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/504?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io) Report
> Merging [#504](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/504?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io) (4c0fb94) into [master](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/commit/06b4a4a41a09a9e2e15790080c9a55609dabc0b9?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io) (06b4a4a) will **increase** coverage by `0.01%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/504/graphs/tree.svg?width=650&height=150&src=pr&token=WJK43PV390&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io)](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/504?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io)

```diff
@@            Coverage Diff             @@
##           master     #504      +/-   ##
==========================================
+ Coverage   84.09%   84.10%   +0.01%     
==========================================
  Files          36       36              
  Lines        3319     3322       +3     
==========================================
+ Hits         2791     2794       +3     
  Misses        425      425              
  Partials      103      103              
```


| [Impacted Files](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/504?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io) | Coverage Δ | |
|---|---|---|
| [client/data.go](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/504?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io#diff-Y2xpZW50L2RhdGEuZ28=) | `70.00% <100.00%> (+0.08%)` | :arrow_up: |
| [client/options.go](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/504?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io#diff-Y2xpZW50L29wdGlvbnMuZ28=) | `69.23% <100.00%> (+1.23%)` | :arrow_up: |

sre-ci-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/milvus-io/milvus-sdk-go/pull/504#" title="Author self-approved">chasingegg</a>*, *<a href="https://github.com/milvus-io/milvus-sdk-go/pull/504#pullrequestreview-1510242590" title="LGTM">congqixia</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=milvus-io%2Fmilvus-sdk-go).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/milvus-io/milvus-sdk-go/blob/master/OWNERS)~~ [congqixia]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->

Patch:
diff --git a/client/data.go b/client/data.go
index 147e8ba..4faa027 100644
--- a/client/data.go
+++ b/client/data.go
@@ -31,6 +31,7 @@ const (
 	offsetKey        = `offset`
 	limitKey         = `limit`
 	ignoreGrowingKey = `ignore_growing`
+	forTuningKey     = `for_tuning`
 )
 
 // Search with bool expression
@@ -253,6 +254,7 @@ func prepareSearchRequest(collName string, partitions []string,
 	expr string, outputFields []string, vectors []entity.Vector, vectorField string,
 	metricType entity.MetricType, topK int, sp entity.SearchParam, opt *SearchQueryOption) (*server.SearchRequest, error) {
 	params := sp.Params()
+	params[forTuningKey] = opt.ForTuning
 	bs, err := json.Marshal(params)
 	if err != nil {
 		return nil, err
diff --git a/client/options.go b/client/options.go
index 5eaa460..db85bdc 100644
--- a/client/options.go
+++ b/client/options.go
@@ -65,11 +65,18 @@ type SearchQueryOption struct {
 	Offset int64
 
 	IgnoreGrowing bool
+	ForTuning     bool
 }
 
 // SearchQueryOptionFunc is a function which modifies SearchOption
 type SearchQueryOptionFunc func(option *SearchQueryOption)
 
+func WithForTuning() SearchQueryOptionFunc {
+	return func(option *SearchQueryOption) {
+		option.ForTuning = true
+	}
+}
+
 func WithIgnoreGrowing() SearchQueryOptionFunc {
 	return func(option *SearchQueryOption) {
 		option.IgnoreGrowing = true


Test patch:
diff --git a/client/data_test.go b/client/data_test.go
index f2bd43a..38475dd 100644
--- a/client/data_test.go
+++ b/client/data_test.go
@@ -403,7 +403,7 @@ func (s *SearchSuite) TestSearchSuccess() {
 			}, nil)
 
 		r, err := c.Search(ctx, testCollectionName, []string{partName}, expr, []string{"ID"}, []entity.Vector{entity.FloatVector(vectors[0])},
-			testVectorField, entity.L2, 10, sp, WithIgnoreGrowing(), WithSearchQueryConsistencyLevel(entity.ClCustomized), WithGuaranteeTimestamp(10000000000))
+			testVectorField, entity.L2, 10, sp, WithIgnoreGrowing(), WithForTuning(), WithSearchQueryConsistencyLevel(entity.ClCustomized), WithGuaranteeTimestamp(10000000000))
 		s.NoError(err)
 		s.Require().Equal(1, len(r))
 		result := r[0]
@@ -445,7 +445,7 @@ func (s *SearchSuite) TestSearchSuccess() {
 			}, nil)
 
 		r, err := c.Search(ctx, testCollectionName, []string{partName}, expr, []string{"A", "B"}, []entity.Vector{entity.FloatVector(vectors[0])},
-			testVectorField, entity.L2, 2, sp, WithIgnoreGrowing(), WithSearchQueryConsistencyLevel(entity.ClBounded))
+			testVectorField, entity.L2, 2, sp, WithIgnoreGrowing(), WithForTuning(), WithSearchQueryConsistencyLevel(entity.ClBounded))
 		s.NoError(err)
 		s.Require().Equal(1, len(r))
 		result := r[0]
diff --git a/client/options_test.go b/client/options_test.go
index 0a0bed1..a70d04c 100644
--- a/client/options_test.go
+++ b/client/options_test.go
@@ -78,6 +78,7 @@ func TestMakeSearchQueryOption(t *testing.T) {
 			ConsistencyLevel:   entity.ClStrong,
 			GuaranteeTimestamp: StrongTimestamp,
 			IgnoreGrowing:      false,
+			ForTuning:          false,
 		}
 		assert.Equal(t, expected, opt)
 	})
@@ -90,6 +91,20 @@ func TestMakeSearchQueryOption(t *testing.T) {
 			ConsistencyLevel:   entity.ClStrong,
 			GuaranteeTimestamp: StrongTimestamp,
 			IgnoreGrowing:      true,
+			ForTuning:          false,
+		}
+		assert.Equal(t, expected, opt)
+	})
+
+	t.Run("for tuning", func(t *testing.T) {
+		opt, err := makeSearchQueryOption(c.Name, WithForTuning())
+		assert.Nil(t, err)
+		assert.NotNil(t, opt)
+		expected := &SearchQueryOption{
+			ConsistencyLevel:   entity.ClStrong,
+			GuaranteeTimestamp: StrongTimestamp,
+			IgnoreGrowing:      false,
+			ForTuning:          true,
 		}
 		assert.Equal(t, expected, opt)
 	})
@@ -102,6 +117,7 @@ func TestMakeSearchQueryOption(t *testing.T) {
 			ConsistencyLevel:   entity.ClSession,
 			GuaranteeTimestamp: EventuallyTimestamp,
 			IgnoreGrowing:      false,
+			ForTuning:          false,
 		}
 		assert.Equal(t, expected, opt)
 
@@ -113,6 +129,7 @@ func TestMakeSearchQueryOption(t *testing.T) {
 			ConsistencyLevel:   entity.ClSession,
 			GuaranteeTimestamp: 99,
 			IgnoreGrowing:      false,
+			ForTuning:          false,
 		}
 		assert.Equal(t, expected, opt)
 	})
@@ -125,6 +142,7 @@ func TestMakeSearchQueryOption(t *testing.T) {
 			ConsistencyLevel:   entity.ClBounded,
 			GuaranteeTimestamp: BoundedTimestamp,
 			IgnoreGrowing:      false,
+			ForTuning:          false,
 		}
 		assert.Equal(t, expected, opt)
 	})
@@ -137,6 +155,7 @@ func TestMakeSearchQueryOption(t *testing.T) {
 			ConsistencyLevel:   entity.ClEventually,
 			GuaranteeTimestamp: EventuallyTimestamp,
 			IgnoreGrowing:      false,
+			ForTuning:          false,
 		}
 		assert.Equal(t, expected, opt)
 	})
@@ -149,6 +168,7 @@ func TestMakeSearchQueryOption(t *testing.T) {
 			ConsistencyLevel:   entity.ClCustomized,
 			GuaranteeTimestamp: 100,
 			IgnoreGrowing:      false,
+			ForTuning:          false,
 		}
 		assert.Equal(t, expected, opt)
 	})