Skip to content

Commit

Permalink
Disable multiple vector fields (#12691)
Browse files Browse the repository at this point in the history
Signed-off-by: dragondriver <jiquan.long@zilliz.com>
  • Loading branch information
longjiquan committed Dec 6, 2021
1 parent 58c5b60 commit a2a1f9d
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 1 deletion.
4 changes: 4 additions & 0 deletions internal/proxy/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,10 @@ func (cct *createCollectionTask) PreExecute(ctx context.Context) error {
}
}

if err := validateMultipleVectorFields(cct.schema); err != nil {
return err
}

return nil
}

Expand Down
45 changes: 44 additions & 1 deletion internal/proxy/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,23 @@ func constructCollectionSchemaWithAllType(
AutoID: false,
}

if enableMultipleVectorFields {
return &schemapb.CollectionSchema{
Name: collectionName,
Description: "",
AutoID: false,
Fields: []*schemapb.FieldSchema{
b,
i32,
i64,
f,
d,
fVec,
bVec,
},
}
}

return &schemapb.CollectionSchema{
Name: collectionName,
Description: "",
Expand All @@ -189,7 +206,7 @@ func constructCollectionSchemaWithAllType(
f,
d,
fVec,
bVec,
// bVec,
},
}
}
Expand Down Expand Up @@ -1114,6 +1131,32 @@ func TestCreateCollectionTask(t *testing.T) {
task.CreateCollectionRequest.Schema = binaryTooLargeDimSchema
err = task.PreExecute(ctx)
assert.Error(t, err)

schema = proto.Clone(schemaBackup).(*schemapb.CollectionSchema)
schema.Fields = append(schema.Fields, &schemapb.FieldSchema{
FieldID: 0,
Name: "second_vector",
IsPrimaryKey: false,
Description: "",
DataType: schemapb.DataType_FloatVector,
TypeParams: []*commonpb.KeyValuePair{
{
Key: "dim",
Value: strconv.Itoa(128),
},
},
IndexParams: nil,
AutoID: false,
})
twoVecFieldsSchema, err := proto.Marshal(schema)
assert.NoError(t, err)
task.CreateCollectionRequest.Schema = twoVecFieldsSchema
err = task.PreExecute(ctx)
if enableMultipleVectorFields {
assert.NoError(t, err)
} else {
assert.Error(t, err)
}
})
}

Expand Down
25 changes: 25 additions & 0 deletions internal/proxy/validate_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"github.com/milvus-io/milvus/internal/proto/schemapb"
)

const enableMultipleVectorFields = false

func isAlpha(c uint8) bool {
if (c < 'A' || c > 'Z') && (c < 'a' || c > 'z') {
return false
Expand Down Expand Up @@ -343,3 +345,26 @@ func validateSchema(coll *schemapb.CollectionSchema) error {

return nil
}

func validateMultipleVectorFields(schema *schemapb.CollectionSchema) error {
vecExist := false
var vecName string

for i := range schema.Fields {
name := schema.Fields[i].Name
dType := schema.Fields[i].DataType
isVec := (dType == schemapb.DataType_BinaryVector || dType == schemapb.DataType_FloatVector)
if isVec && vecExist && !enableMultipleVectorFields {
return fmt.Errorf(
"multiple vector fields is not supported, fields name: %s, %s",
vecName,
name,
)
} else if isVec {
vecExist = true
vecName = name
}
}

return nil
}
36 changes: 36 additions & 0 deletions internal/proxy/validate_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,3 +372,39 @@ func TestValidateSchema(t *testing.T) {
pf3.IndexParams = ip3Good
assert.Nil(t, validateSchema(coll))
}

func TestValidateMultipleVectorFields(t *testing.T) {
// case1, no vector field
schema1 := &schemapb.CollectionSchema{}
assert.NoError(t, validateMultipleVectorFields(schema1))

// case2, only one vector field
schema2 := &schemapb.CollectionSchema{
Fields: []*schemapb.FieldSchema{
{
Name: "case2",
DataType: schemapb.DataType_FloatVector,
},
},
}
assert.NoError(t, validateMultipleVectorFields(schema2))

// case3, multiple vectors
schema3 := &schemapb.CollectionSchema{
Fields: []*schemapb.FieldSchema{
{
Name: "case3_f",
DataType: schemapb.DataType_FloatVector,
},
{
Name: "case3_b",
DataType: schemapb.DataType_BinaryVector,
},
},
}
if enableMultipleVectorFields {
assert.NoError(t, validateMultipleVectorFields(schema3))
} else {
assert.Error(t, validateMultipleVectorFields(schema3))
}
}
2 changes: 2 additions & 0 deletions tests/python_client/testcases/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ def test_collection_only_vector_field(self, field):
self.collection_schema_wrap.init_collection_schema([field], check_task=CheckTasks.err_res, check_items=error)

@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.skip("https://github.com/milvus-io/milvus/issues/12680")
def test_collection_multi_float_vectors(self):
"""
target: test collection with multi float vectors
Expand All @@ -436,6 +437,7 @@ def test_collection_multi_float_vectors(self):
check_items={exp_name: c_name, exp_schema: schema})

@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.skip("https://github.com/milvus-io/milvus/issues/12680")
def test_collection_mix_vectors(self):
"""
target: test collection with mix vectors
Expand Down
1 change: 1 addition & 0 deletions tests/python_client/testcases/test_insert_20.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ def test_insert_without_connection(self):
collection_w.insert(data=data, check_task=CheckTasks.err_res, check_items=error)

@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.skip("https://github.com/milvus-io/milvus/issues/12680")
@pytest.mark.parametrize("vec_fields", [[cf.gen_float_vec_field(name="float_vector1")],
[cf.gen_binary_vec_field()],
[cf.gen_binary_vec_field(), cf.gen_binary_vec_field("binary_vec")]])
Expand Down
6 changes: 6 additions & 0 deletions tests/python_client/testcases/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ def test_query_output_float_vec_field(self):
check_items={exp_res: res, "with_vec": True})

@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.skip("https://github.com/milvus-io/milvus/issues/12680")
@pytest.mark.parametrize("vec_fields", [[cf.gen_float_vec_field(name="float_vector1")]])
def test_query_output_multi_float_vec_field(self, vec_fields):
"""
Expand All @@ -557,6 +558,7 @@ def test_query_output_multi_float_vec_field(self, vec_fields):
check_items={exp_res: res, "with_vec": True})

@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.skip("https://github.com/milvus-io/milvus/issues/12680")
@pytest.mark.parametrize("vec_fields", [[cf.gen_binary_vec_field()],
[cf.gen_binary_vec_field(), cf.gen_binary_vec_field("binary_vec1")]])
def test_query_output_mix_float_binary_field(self, vec_fields):
Expand Down Expand Up @@ -642,6 +644,7 @@ def test_query_invalid_output_fields(self):
check_items=error)

@pytest.mark.tags(CaseLabel.L0)
@pytest.mark.skip("https://github.com/milvus-io/milvus/issues/12680")
def test_query_output_fields_simple_wildcard(self):
"""
target: test query output_fields with simple wildcard (* and %)
Expand Down Expand Up @@ -673,6 +676,7 @@ def test_query_output_fields_simple_wildcard(self):
check_items={exp_res: res3, "with_vec": True})

@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.skip("https://github.com/milvus-io/milvus/issues/12680")
def test_query_output_fields_part_scale_wildcard(self):
"""
target: test query output_fields with part wildcard
Expand All @@ -697,6 +701,7 @@ def test_query_output_fields_part_scale_wildcard(self):
check_items={exp_res: res2})

@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.skip("https://github.com/milvus-io/milvus/issues/12680")
def test_query_output_fields_part_vector_wildcard(self):
"""
target: test query output_fields with part wildcard
Expand All @@ -721,6 +726,7 @@ def test_query_output_fields_part_vector_wildcard(self):
check_items={exp_res: res2, "with_vec": True})

@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.skip("https://github.com/milvus-io/milvus/issues/12680")
@pytest.mark.parametrize("output_fields", [["*%"], ["**"], ["*", "@"]])
def test_query_invalid_wildcard(self, output_fields):
"""
Expand Down

0 comments on commit a2a1f9d

Please sign in to comment.