forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCompressionCodecQuantized.h
More file actions
58 lines (45 loc) · 2.38 KB
/
Copy pathCompressionCodecQuantized.h
File metadata and controls
58 lines (45 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once
#include <Compression/ICompressionCodec.h>
#include <cstddef>
#include <optional>
namespace DB
{
/// Parameters of the `Quantized` column codec.
struct QuantizedCodecParams
{
String method; /// The quantization method
size_t dimensions = 0; /// The vector length
size_t bits = 0; /// Overloaded: the number of leading dimensions kept by the `prefix_*` methods, and nbits per subspace for `product`.
size_t m = 0; /// The number of subspaces, used only by the trained `product` (Product Quantization) method.
};
/// `Quantized(method, dimensions[, bits])` is a column codec for dense vector columns (`Array(Float32)` and friends).
///
/// At the byte level the codec does nothing - the full-precision data is stored verbatim, exactly like `NONE` (hence
/// `isNone() == true`). Its purpose is purely declarative: its presence on a vector column makes
/// `SerializationQuantizedVector` write a compact and data-independent quantized companion stream alongside the
/// full-precision vectors, exposed as a readable subcolumn `<column>.quantized`. Vector search can then rank
/// cheaply over the quantized vectors and rescore the results against the full-precision vectors.
class CompressionCodecQuantized : public ICompressionCodec
{
public:
explicit CompressionCodecQuantized(const QuantizedCodecParams & params_);
uint8_t getMethodByte() const override;
void updateHash(SipHash & hash) const override;
const QuantizedCodecParams & getParams() const { return params; }
protected:
UInt32 doCompressData(const char * source, UInt32 source_size, char * dest) const override;
UInt32 doDecompressData(const char * source, UInt32 source_size, char * dest, UInt32 uncompressed_size) const override;
bool isCompression() const override { return false; }
bool isGenericCompression() const override { return false; }
bool isNone() const override { return true; } /// see the class-level comment
bool isExperimental() const override { return true; }
String getDescription() const override
{
return "Stores a compact quantized companion stream of a dense vector column for fast nearest-neighbour search; "
"the full-precision data is stored uncompressed.";
}
private:
QuantizedCodecParams params;
};
std::optional<QuantizedCodecParams> tryExtractQuantizedCodecParams(const ASTPtr & codec_desc);
}