| 117 | |
| 118 | |
| 119 | void registerDataTypeQBit(DataTypeFactory & factory) |
| 120 | { |
| 121 | factory.registerDataType("QBit", create, DataTypeFactory::Case::Sensitive, Documentation{ |
| 122 | .description = R"DOCS_MD( |
| 123 | The `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. |
| 124 | This 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 | |
| 126 | To declare a column of `QBit` type, use the following syntax: |
| 127 | |
| 128 | ```sql |
| 129 | column_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 | |
| 137 | Using the `QBit` type in table column definition: |
| 138 | |
| 139 | ```sql |
| 140 | CREATE TABLE test (id UInt32, vec QBit(Float32, 8)) ENGINE = Memory; |
| 141 | INSERT INTO test VALUES (1, [1, 2, 3, 4, 5, 6, 7, 8]), (2, [9, 10, 11, 12, 13, 14, 15, 16]); |
| 142 | SELECT 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 |
| 157 | CREATE TABLE test (id UInt32, vec QBit(Float32, 8)) ENGINE = Memory; |
| 158 | INSERT INTO test VALUES (1, [0, 0, 0, 0, 0, 0, 0, 0]); |
| 159 | INSERT INTO test VALUES (1, [-0, -0, -0, -0, -0, -0, -0, -0]); |
| 160 | SELECT bin(vec.1) FROM test; |
| 161 | ``` |
| 162 | |
| 163 | ```text |
| 164 | ┌─bin(tupleElement(vec, 1))─┐ |
| 165 | │ 00000000 │ |
| 166 | │ 11111111 │ |
| 167 | └───────────────────────────┘ |
| 168 | ``` |
| 169 | |
| 170 | The 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} |
no test coverage detected