MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / registerDataTypeQBit

Function registerDataTypeQBit

src/DataTypes/DataTypeQBit.cpp:119–187  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

117
118
119void registerDataTypeQBit(DataTypeFactory & factory)
120{
121 factory.registerDataType("QBit", create, DataTypeFactory::Case::Sensitive, Documentation{
122 .description = R"DOCS_MD(
123The `QBit` data type reorganizes vector storage for faster approximate searches. Instead of storing each vector's elements together, it groups the same binary digit positions across all vectors.
124This stores vectors at full precision while letting you choose the fine-grained quantization level at search time: read fewer bits for less I/O and faster calculations, or more bits for higher accuracy. You get the speed benefits of reduced data transfer and computation from quantization, but all the original data remains available when needed.
125
126To declare a column of `QBit` type, use the following syntax:
127
128```sql
129column_name QBit(element_type, dimension)
130```
131
132* `element_type` – the type of each vector element. The allowed types are `BFloat16`, `Float32` and `Float64`
133* `dimension` – the number of elements in each vector
134
135## Creating QBit {#creating-qbit}
136
137Using the `QBit` type in table column definition:
138
139```sql
140CREATE TABLE test (id UInt32, vec QBit(Float32, 8)) ENGINE = Memory;
141INSERT INTO test VALUES (1, [1, 2, 3, 4, 5, 6, 7, 8]), (2, [9, 10, 11, 12, 13, 14, 15, 16]);
142SELECT vec FROM test ORDER BY id;
143```
144
145```text
146┌─vec──────────────────────┐
147│ [1,2,3,4,5,6,7,8] │
148│ [9,10,11,12,13,14,15,16] │
149└──────────────────────────┘
150```
151
152## QBit subcolumns {#qbit-subcolumns}
153
154`QBit` implements a subcolumn access pattern that allows you to access individual bit planes of the stored vectors. Each bit position can be accessed using the `.N` syntax, where `N` is the bit position:
155
156```sql
157CREATE TABLE test (id UInt32, vec QBit(Float32, 8)) ENGINE = Memory;
158INSERT INTO test VALUES (1, [0, 0, 0, 0, 0, 0, 0, 0]);
159INSERT INTO test VALUES (1, [-0, -0, -0, -0, -0, -0, -0, -0]);
160SELECT bin(vec.1) FROM test;
161```
162
163```text
164┌─bin(tupleElement(vec, 1))─┐
165│ 00000000 │
166│ 11111111 │
167└───────────────────────────┘
168```
169
170The number of accessible subcolumns depends on the element type:
171
172* `BFloat16`: 16 subcolumns (1-16)
173* `Float32`: 32 subcolumns (1-32)
174* `Float64`: 64 subcolumns (1-64)
175
176## Vector search functions {#vector-search-functions}

Callers 1

DataTypeFactoryMethod · 0.85

Calls 1

registerDataTypeMethod · 0.80

Tested by

no test coverage detected