2022-01-11 00:03:38 +08:00
|
|
|
// Licensed to the LF AI & Data foundation under one
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
// distributed with this work for additional information
|
|
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
// "License"); you may not use this file except in compliance
|
2021-04-19 10:09:43 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2022-01-11 00:03:38 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 10:09:43 +08:00
|
|
|
//
|
2022-01-11 00:03:38 +08:00
|
|
|
// 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.
|
2021-04-19 10:09:43 +08:00
|
|
|
|
2021-06-22 15:28:04 +08:00
|
|
|
package indexparamcheck
|
2021-03-13 09:57:22 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
2023-02-26 11:31:49 +08:00
|
|
|
|
|
|
|
"github.com/cockroachdb/errors"
|
2021-03-13 09:57:22 +08:00
|
|
|
)
|
|
|
|
|
2021-11-01 22:43:48 +08:00
|
|
|
// ConfAdapterMgr manages the conf adapter.
|
2021-03-13 09:57:22 +08:00
|
|
|
type ConfAdapterMgr interface {
|
2021-11-01 22:43:48 +08:00
|
|
|
// GetAdapter gets the conf adapter by the index type.
|
2021-03-13 09:57:22 +08:00
|
|
|
GetAdapter(indexType string) (ConfAdapter, error)
|
|
|
|
}
|
|
|
|
|
2021-11-01 22:43:48 +08:00
|
|
|
// ConfAdapterMgrImpl implements ConfAdapter.
|
2021-03-13 09:57:22 +08:00
|
|
|
type ConfAdapterMgrImpl struct {
|
2021-04-08 09:51:04 +08:00
|
|
|
adapters map[IndexType]ConfAdapter
|
2021-11-21 00:39:13 +08:00
|
|
|
once sync.Once
|
2021-03-13 09:57:22 +08:00
|
|
|
}
|
|
|
|
|
2021-11-01 22:43:48 +08:00
|
|
|
// GetAdapter gets the conf adapter by the index type.
|
2021-03-13 09:57:22 +08:00
|
|
|
func (mgr *ConfAdapterMgrImpl) GetAdapter(indexType string) (ConfAdapter, error) {
|
2021-11-21 00:39:13 +08:00
|
|
|
mgr.once.Do(mgr.registerConfAdapter)
|
2021-03-13 09:57:22 +08:00
|
|
|
|
|
|
|
adapter, ok := mgr.adapters[indexType]
|
|
|
|
if ok {
|
|
|
|
return adapter, nil
|
|
|
|
}
|
|
|
|
return nil, errors.New("Can not find conf adapter: " + indexType)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mgr *ConfAdapterMgrImpl) registerConfAdapter() {
|
2023-03-14 23:21:56 +08:00
|
|
|
mgr.adapters[IndexRaftIvfFlat] = newIVFConfAdapter()
|
2023-03-31 11:22:22 +08:00
|
|
|
mgr.adapters[IndexRaftIvfPQ] = newRaftIVFPQConfAdapter()
|
2021-04-08 09:51:04 +08:00
|
|
|
mgr.adapters[IndexFaissIDMap] = newBaseConfAdapter()
|
|
|
|
mgr.adapters[IndexFaissIvfFlat] = newIVFConfAdapter()
|
|
|
|
mgr.adapters[IndexFaissIvfPQ] = newIVFPQConfAdapter()
|
|
|
|
mgr.adapters[IndexFaissIvfSQ8] = newIVFSQConfAdapter()
|
|
|
|
mgr.adapters[IndexFaissBinIDMap] = newBinIDMAPConfAdapter()
|
|
|
|
mgr.adapters[IndexFaissBinIvfFlat] = newBinIVFConfAdapter()
|
|
|
|
mgr.adapters[IndexHNSW] = newHNSWConfAdapter()
|
2022-09-21 20:16:51 +08:00
|
|
|
mgr.adapters[IndexDISKANN] = newDISKANNConfAdapter()
|
2021-03-13 09:57:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func newConfAdapterMgrImpl() *ConfAdapterMgrImpl {
|
2021-04-08 09:51:04 +08:00
|
|
|
return &ConfAdapterMgrImpl{
|
|
|
|
adapters: make(map[IndexType]ConfAdapter),
|
|
|
|
}
|
2021-03-13 09:57:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var confAdapterMgr ConfAdapterMgr
|
2023-04-06 19:14:32 +08:00
|
|
|
|
2021-03-13 09:57:22 +08:00
|
|
|
var getConfAdapterMgrOnce sync.Once
|
|
|
|
|
2021-11-01 22:43:48 +08:00
|
|
|
// GetConfAdapterMgrInstance gets the instance of ConfAdapterMgr.
|
2021-03-13 09:57:22 +08:00
|
|
|
func GetConfAdapterMgrInstance() ConfAdapterMgr {
|
|
|
|
getConfAdapterMgrOnce.Do(func() {
|
|
|
|
confAdapterMgr = newConfAdapterMgrImpl()
|
|
|
|
})
|
|
|
|
return confAdapterMgr
|
|
|
|
}
|