mirror of https://github.com/milvus-io/milvus.git
enhance: [cherry-pick]check index with data type in knowhere api (#33878)
issue: https://github.com/milvus-io/milvus/issues/22837 related: https://github.com/milvus-io/milvus/pull/33880 Signed-off-by: cqy123456 <qianya.cheng@zilliz.com>pull/33899/head
parent
fd1c7b1a1c
commit
562369627d
|
@ -38,7 +38,8 @@ set(SEGCORE_FILES
|
|||
TimestampIndex.cpp
|
||||
Utils.cpp
|
||||
ConcurrentVector.cpp
|
||||
ReduceUtils.cpp)
|
||||
ReduceUtils.cpp
|
||||
check_vec_index_c.cpp)
|
||||
add_library(milvus_segcore SHARED ${SEGCORE_FILES})
|
||||
|
||||
target_link_libraries(milvus_segcore milvus_query milvus_bitset milvus_exec ${OpenMP_CXX_FLAGS} milvus-storage)
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
// or implied. See the License for the specific language governing permissions and limitations under the License
|
||||
|
||||
#include <string>
|
||||
#include "check_vec_index_c.h"
|
||||
#include "common/Types.h"
|
||||
#include "knowhere/comp/knowhere_check.h"
|
||||
|
||||
bool
|
||||
CheckVecIndexWithDataType(const char* index_type, enum CDataType data_type) {
|
||||
return knowhere::KnowhereCheck::IndexTypeAndDataTypeCheck(
|
||||
std::string(index_type), knowhere::VecType(data_type));
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
// or implied. See the License for the specific language governing permissions and limitations under the License
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "common/type_c.h"
|
||||
bool
|
||||
CheckVecIndexWithDataType(const char* index_type, enum CDataType data_type);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -344,7 +344,12 @@ func fillDimension(field *schemapb.FieldSchema, indexParams map[string]string) e
|
|||
|
||||
func checkTrain(field *schemapb.FieldSchema, indexParams map[string]string) error {
|
||||
indexType := indexParams[common.IndexTypeKey]
|
||||
|
||||
if typeutil.IsVectorType(field.DataType) && indexType != indexparamcheck.AutoIndex {
|
||||
exist := indexparamcheck.CheckVecIndexWithDataTypeExist(indexType, field.DataType)
|
||||
if !exist {
|
||||
return fmt.Errorf("data type %d can't build with this index %s", field.DataType, indexType)
|
||||
}
|
||||
}
|
||||
checker, err := indexparamcheck.GetIndexCheckerMgrInstance().GetChecker(indexType)
|
||||
if err != nil {
|
||||
log.Warn("Failed to get index checker", zap.String(common.IndexTypeKey, indexType))
|
||||
|
|
|
@ -16,10 +16,19 @@
|
|||
|
||||
package indexparamcheck
|
||||
|
||||
/*
|
||||
#cgo pkg-config: milvus_segcore
|
||||
#include "segcore/check_vec_index_c.h"
|
||||
#include <stdlib.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"unsafe"
|
||||
|
||||
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
|
||||
"github.com/milvus-io/milvus/pkg/util/funcutil"
|
||||
)
|
||||
|
||||
|
@ -69,3 +78,11 @@ func setDefaultIfNotExist(params map[string]string, key string, defaultValue str
|
|||
params[key] = defaultValue
|
||||
}
|
||||
}
|
||||
|
||||
func CheckVecIndexWithDataTypeExist(name string, dType schemapb.DataType) bool {
|
||||
cIndexName := C.CString(name)
|
||||
cType := uint32(dType)
|
||||
defer C.free(unsafe.Pointer(cIndexName))
|
||||
check := bool(C.CheckVecIndexWithDataType(cIndexName, cType))
|
||||
return check
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue