mirror of
https://gitee.com/milvus-io/milvus.git
synced 2026-01-07 19:31:51 +08:00
issue: https://github.com/milvus-io/milvus/issues/27704 Add inverted index for some data types in Milvus. This index type can save a lot of memory compared to loading all data into RAM and speed up the term query and range query. Supported: `INT8`, `INT16`, `INT32`, `INT64`, `FLOAT`, `DOUBLE`, `BOOL` and `VARCHAR`. Not supported: `ARRAY` and `JSON`. Note: - The inverted index for `VARCHAR` is not designed to serve full-text search now. We will treat every row as a whole keyword instead of tokenizing it into multiple terms. - The inverted index don't support retrieval well, so if you create inverted index for field, those operations which depend on the raw data will fallback to use chunk storage, which will bring some performance loss. For example, comparisons between two columns and retrieval of output fields. The inverted index is very easy to be used. Taking below collection as an example: ```python fields = [ FieldSchema(name="pk", dtype=DataType.VARCHAR, is_primary=True, auto_id=False, max_length=100), FieldSchema(name="int8", dtype=DataType.INT8), FieldSchema(name="int16", dtype=DataType.INT16), FieldSchema(name="int32", dtype=DataType.INT32), FieldSchema(name="int64", dtype=DataType.INT64), FieldSchema(name="float", dtype=DataType.FLOAT), FieldSchema(name="double", dtype=DataType.DOUBLE), FieldSchema(name="bool", dtype=DataType.BOOL), FieldSchema(name="varchar", dtype=DataType.VARCHAR, max_length=1000), FieldSchema(name="random", dtype=DataType.DOUBLE), FieldSchema(name="embeddings", dtype=DataType.FLOAT_VECTOR, dim=dim), ] schema = CollectionSchema(fields) collection = Collection("demo", schema) ``` Then we can simply create inverted index for field via: ```python index_type = "INVERTED" collection.create_index("int8", {"index_type": index_type}) collection.create_index("int16", {"index_type": index_type}) collection.create_index("int32", {"index_type": index_type}) collection.create_index("int64", {"index_type": index_type}) collection.create_index("float", {"index_type": index_type}) collection.create_index("double", {"index_type": index_type}) collection.create_index("bool", {"index_type": index_type}) collection.create_index("varchar", {"index_type": index_type}) ``` Then, term query and range query on the field can be speed up automatically by the inverted index: ```python result = collection.query(expr='int64 in [1, 2, 3]', output_fields=["pk"]) result = collection.query(expr='int64 < 5', output_fields=["pk"]) result = collection.query(expr='int64 > 2997', output_fields=["pk"]) result = collection.query(expr='1 < int64 < 5', output_fields=["pk"]) ``` --------- Signed-off-by: longjiquan <jiquan.long@zilliz.com>
74 lines
3.2 KiB
C++
74 lines
3.2 KiB
C++
// 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
|
|
// 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
|
|
|
|
#include "knowhere/comp/index_param.h"
|
|
|
|
namespace milvus::index {
|
|
constexpr const char* OPERATOR_TYPE = "operator_type";
|
|
constexpr const char* RANGE_VALUE = "range_value";
|
|
constexpr const char* LOWER_BOUND_VALUE = "lower_bound_value";
|
|
constexpr const char* LOWER_BOUND_INCLUSIVE = "lower_bound_inclusive";
|
|
constexpr const char* UPPER_BOUND_VALUE = "upper_bound_value";
|
|
constexpr const char* UPPER_BOUND_INCLUSIVE = "upper_bound_inclusive";
|
|
constexpr const char* PREFIX_VALUE = "prefix_value";
|
|
// below configurations will be persistent, do not edit them.
|
|
constexpr const char* MARISA_TRIE_INDEX = "marisa_trie_index";
|
|
constexpr const char* MARISA_STR_IDS = "marisa_trie_str_ids";
|
|
|
|
constexpr const char* INDEX_TYPE = "index_type";
|
|
constexpr const char* METRIC_TYPE = "metric_type";
|
|
|
|
// scalar index type
|
|
constexpr const char* ASCENDING_SORT = "STL_SORT";
|
|
constexpr const char* MARISA_TRIE = "Trie";
|
|
constexpr const char* INVERTED_INDEX_TYPE = "INVERTED";
|
|
|
|
// index meta
|
|
constexpr const char* COLLECTION_ID = "collection_id";
|
|
constexpr const char* PARTITION_ID = "partition_id";
|
|
constexpr const char* SEGMENT_ID = "segment_id";
|
|
constexpr const char* FIELD_ID = "field_id";
|
|
constexpr const char* INDEX_BUILD_ID = "index_build_id";
|
|
constexpr const char* INDEX_ID = "index_id";
|
|
constexpr const char* INDEX_VERSION = "index_version";
|
|
constexpr const char* INDEX_ENGINE_VERSION = "index_engine_version";
|
|
|
|
// VecIndex file metas
|
|
constexpr const char* DISK_ANN_PREFIX_PATH = "index_prefix";
|
|
constexpr const char* DISK_ANN_RAW_DATA_PATH = "data_path";
|
|
|
|
// DiskAnn build params
|
|
constexpr const char* DISK_ANN_MAX_DEGREE = "max_degree";
|
|
constexpr const char* DISK_ANN_SEARCH_LIST_SIZE = "search_list_size";
|
|
constexpr const char* DISK_ANN_PQ_CODE_BUDGET = "pq_code_budget_gb";
|
|
constexpr const char* DISK_ANN_BUILD_DRAM_BUDGET = "build_dram_budget_gb";
|
|
constexpr const char* DISK_ANN_BUILD_THREAD_NUM = "num_build_thread";
|
|
constexpr const char* DISK_ANN_PQ_DIMS = "disk_pq_dims";
|
|
constexpr const char* DISK_ANN_THREADS_NUM = "num_threads";
|
|
|
|
// DiskAnn prepare params
|
|
constexpr const char* DISK_ANN_LOAD_THREAD_NUM = "num_load_thread";
|
|
constexpr const char* DISK_ANN_SEARCH_CACHE_BUDGET = "search_cache_budget_gb";
|
|
constexpr const char* DISK_ANN_PREPARE_WARM_UP = "warm_up";
|
|
constexpr const char* DISK_ANN_PREPARE_USE_BFS_CACHE = "use_bfs_cache";
|
|
|
|
// DiskAnn query params
|
|
constexpr const char* DISK_ANN_QUERY_LIST = "search_list";
|
|
constexpr const char* DISK_ANN_QUERY_BEAMWIDTH = "beamwidth";
|
|
} // namespace milvus::index
|