1 module faiss.index_scalar_quantizer; 2 3 import faiss.common; 4 import faiss.index; 5 6 /** 7 * Copyright (c) Facebook, Inc. and its affiliates. 8 * 9 * This source code is licensed under the MIT license found in the 10 * LICENSE file in the root directory of this source tree. 11 */ 12 13 // Copyright 2004-present Facebook. All Rights Reserved. 14 // -*- c -*- 15 16 extern (C): 17 18 enum FaissQuantizerType 19 { 20 QT_8bit = 0, ///< 8 bits per component 21 QT_4bit = 1, ///< 4 bits per component 22 QT_8bit_uniform = 2, ///< same, shared range for all dimensions 23 QT_4bit_uniform = 3, 24 QT_fp16 = 4, 25 QT_8bit_direct = 5, ///< fast indexing of uint8s 26 QT_6bit = 6 ///< 6 bits per component 27 } 28 29 // forward declaration 30 31 /** Opaque type for IndexScalarQuantizer */ 32 33 struct FaissIndex_H; 34 alias FaissIndexScalarQuantizer = FaissIndex_H; 35 int faiss_IndexScalarQuantizer_new (FaissIndexScalarQuantizer** p_index); 36 int faiss_IndexScalarQuantizer_new_with ( 37 FaissIndexScalarQuantizer** p_index, 38 idx_t d, 39 FaissQuantizerType qt, 40 FaissMetricType metric); 41 42 FaissIndexScalarQuantizer* faiss_IndexScalarQuantizer_cast (FaissIndex*); 43 44 void faiss_IndexScalarQuantizer_free (FaissIndexScalarQuantizer* obj); 45 46 /** Opaque type for IndexIVFScalarQuantizer */ 47 alias FaissIndexIVFScalarQuantizer = FaissIndex_H; 48 49 FaissIndexIVFScalarQuantizer* faiss_IndexIVFScalarQuantizer_cast (FaissIndex*); 50 51 void faiss_IndexIVFScalarQuantizer_free (FaissIndexIVFScalarQuantizer* obj); 52 53 int faiss_IndexIVFScalarQuantizer_new (FaissIndexIVFScalarQuantizer** p_index); 54 55 int faiss_IndexIVFScalarQuantizer_new_with ( 56 FaissIndexIVFScalarQuantizer** p_index, 57 FaissIndex* quantizer, 58 idx_t d, 59 size_t nlist, 60 FaissQuantizerType qt); 61 62 int faiss_IndexIVFScalarQuantizer_new_with_metric ( 63 FaissIndexIVFScalarQuantizer** p_index, 64 FaissIndex* quantizer, 65 size_t d, 66 size_t nlist, 67 FaissQuantizerType qt, 68 FaissMetricType metric, 69 int encode_residual); 70 71 /// number of possible key values 72 size_t faiss_IndexIVFScalarQuantizer_nlist (const(FaissIndexIVFScalarQuantizer)*); 73 /// number of probes at query time 74 size_t faiss_IndexIVFScalarQuantizer_nprobe (const(FaissIndexIVFScalarQuantizer)*); 75 void faiss_IndexIVFScalarQuantizer_set_nprobe (FaissIndexIVFScalarQuantizer*, size_t); 76 /// quantizer that maps vectors to inverted lists 77 FaissIndex* faiss_IndexIVFScalarQuantizer_quantizer (const(FaissIndexIVFScalarQuantizer)*); 78 79 /// whether object owns the quantizer 80 int faiss_IndexIVFScalarQuantizer_own_fields (const(FaissIndexIVFScalarQuantizer)*); 81 void faiss_IndexIVFScalarQuantizer_set_own_fields (FaissIndexIVFScalarQuantizer*, int); 82 83 int faiss_IndexIVFScalarQuantizer_add_core ( 84 FaissIndexIVFScalarQuantizer* index, 85 idx_t n, 86 const(float)* x, 87 const(idx_t)* xids, 88 const(idx_t)* precomputed_idx); 89 90 int faiss_IndexIVFScalarQuantizer_train_residual ( 91 FaissIndexIVFScalarQuantizer* index, 92 idx_t n, 93 const(float)* x); 94