@@ -13,8 +13,8 @@ use serde::{Deserialize, Serialize};
13
13
use crate :: {
14
14
comparator:: {
15
15
Centroid16Comparator , Centroid16Comparator1024 , Centroid32Comparator , Centroid4Comparator ,
16
- Centroid8Comparator , Disk1024Comparator , DiskOpenAIComparator , OpenAIComparator ,
17
- Quantized16Comparator , Quantized16Comparator1024 , Quantized32Comparator ,
16
+ Centroid8Comparator , Disk1024Comparator , DiskOpenAIComparator , Memory1024Comparator ,
17
+ OpenAIComparator , Quantized16Comparator , Quantized16Comparator1024 , Quantized32Comparator ,
18
18
Quantized4Comparator , Quantized8Comparator ,
19
19
} ,
20
20
openai:: Model ,
@@ -28,6 +28,7 @@ use crate::{
28
28
} ;
29
29
30
30
pub type OpenAIHnsw = Hnsw < OpenAIComparator > ;
31
+ pub type Memory1024Hnsw = Hnsw < Memory1024Comparator > ;
31
32
32
33
#[ derive( Serialize , Deserialize ) ]
33
34
pub enum HnswConfigurationType {
@@ -36,6 +37,7 @@ pub enum HnswConfigurationType {
36
37
SmallQuantizedOpenAi8 ,
37
38
SmallQuantizedOpenAi4 ,
38
39
UnquantizedOpenAi ,
40
+ Unquantized1024 ,
39
41
Quantized1024 ,
40
42
}
41
43
@@ -92,6 +94,7 @@ pub enum HnswConfiguration {
92
94
DiskOpenAIComparator ,
93
95
> ,
94
96
) ,
97
+ Unquantized1024 ( Model , Memory1024Hnsw ) ,
95
98
UnquantizedOpenAi ( Model , OpenAIHnsw ) ,
96
99
Quantized1024By16 (
97
100
Model ,
@@ -115,6 +118,7 @@ impl HnswConfiguration {
115
118
HnswConfiguration :: SmallQuantizedOpenAi4 ( _, q) => Some ( q. quantization_statistics ( ) ) ,
116
119
HnswConfiguration :: Quantized1024By16 ( _, q) => Some ( q. quantization_statistics ( ) ) ,
117
120
HnswConfiguration :: UnquantizedOpenAi ( _, _) => None ,
121
+ HnswConfiguration :: Unquantized1024 ( _, _) => None ,
118
122
}
119
123
}
120
124
@@ -138,6 +142,9 @@ impl HnswConfiguration {
138
142
HnswConfiguration :: Quantized1024By16 ( model, _) => {
139
143
( HnswConfigurationType :: Quantized1024 , model)
140
144
}
145
+ HnswConfiguration :: Unquantized1024 ( model, _) => {
146
+ ( HnswConfigurationType :: Unquantized1024 , model)
147
+ }
141
148
} ;
142
149
let version = 1 ;
143
150
@@ -156,6 +163,7 @@ impl HnswConfiguration {
156
163
HnswConfiguration :: SmallQuantizedOpenAi8 ( m, _) => * m,
157
164
HnswConfiguration :: SmallQuantizedOpenAi4 ( m, _) => * m,
158
165
HnswConfiguration :: Quantized1024By16 ( m, _) => * m,
166
+ HnswConfiguration :: Unquantized1024 ( m, _) => * m,
159
167
}
160
168
}
161
169
@@ -168,6 +176,7 @@ impl HnswConfiguration {
168
176
HnswConfiguration :: SmallQuantizedOpenAi8 ( _model, q) => q. vector_count ( ) ,
169
177
HnswConfiguration :: SmallQuantizedOpenAi4 ( _model, q) => q. vector_count ( ) ,
170
178
HnswConfiguration :: Quantized1024By16 ( _, q) => q. vector_count ( ) ,
179
+ HnswConfiguration :: Unquantized1024 ( _, q) => q. vector_count ( ) ,
171
180
}
172
181
}
173
182
@@ -182,7 +191,8 @@ impl HnswConfiguration {
182
191
HnswConfiguration :: UnquantizedOpenAi ( _model, h) => h. search ( v, search_parameters) ,
183
192
HnswConfiguration :: SmallQuantizedOpenAi8 ( _, q) => q. search ( v, search_parameters) ,
184
193
HnswConfiguration :: SmallQuantizedOpenAi4 ( _, q) => q. search ( v, search_parameters) ,
185
- HnswConfiguration :: Quantized1024By16 ( _, _q) => {
194
+ HnswConfiguration :: Quantized1024By16 ( _, _)
195
+ | HnswConfiguration :: Unquantized1024 ( _, _) => {
186
196
panic ! ( ) ;
187
197
}
188
198
}
@@ -195,9 +205,8 @@ impl HnswConfiguration {
195
205
) -> Vec < ( VectorId , f32 ) > {
196
206
match self {
197
207
HnswConfiguration :: Quantized1024By16 ( _, q) => q. search ( v, search_parameters) ,
198
- _ => {
199
- panic ! ( ) ;
200
- }
208
+ HnswConfiguration :: Unquantized1024 ( _, h) => h. search ( v, search_parameters) ,
209
+ _ => panic ! ( ) ,
201
210
}
202
211
}
203
212
@@ -225,6 +234,7 @@ impl HnswConfiguration {
225
234
HnswConfiguration :: Quantized1024By16 ( _, q) => {
226
235
q. improve_index ( build_parameters, progress)
227
236
}
237
+ HnswConfiguration :: Unquantized1024 ( _, h) => h. improve_index ( build_parameters, progress) ,
228
238
}
229
239
}
230
240
@@ -253,6 +263,9 @@ impl HnswConfiguration {
253
263
HnswConfiguration :: Quantized1024By16 ( _, q) => {
254
264
q. improve_index_at ( layer, build_parameters, progress)
255
265
}
266
+ HnswConfiguration :: Unquantized1024 ( _, h) => {
267
+ h. improve_index_at ( layer, build_parameters, progress)
268
+ }
256
269
}
257
270
}
258
271
@@ -280,6 +293,9 @@ impl HnswConfiguration {
280
293
HnswConfiguration :: Quantized1024By16 ( _, q) => {
281
294
q. improve_neighbors ( optimization_parameters, last_recall)
282
295
}
296
+ HnswConfiguration :: Unquantized1024 ( _, h) => {
297
+ h. improve_neighbors ( optimization_parameters, last_recall)
298
+ }
283
299
}
284
300
}
285
301
@@ -308,6 +324,9 @@ impl HnswConfiguration {
308
324
HnswConfiguration :: Quantized1024By16 ( _, q) => {
309
325
q. promote_at_layer ( layer_from_top, build_parameters, & mut progress)
310
326
}
327
+ HnswConfiguration :: Unquantized1024 ( _, h) => {
328
+ h. promote_at_layer ( layer_from_top, build_parameters, & mut progress)
329
+ }
311
330
}
312
331
}
313
332
@@ -319,6 +338,7 @@ impl HnswConfiguration {
319
338
HnswConfiguration :: SmallQuantizedOpenAi8 ( _model, q) => q. zero_neighborhood_size ( ) ,
320
339
HnswConfiguration :: SmallQuantizedOpenAi4 ( _model, q) => q. zero_neighborhood_size ( ) ,
321
340
HnswConfiguration :: Quantized1024By16 ( _model, q) => q. zero_neighborhood_size ( ) ,
341
+ HnswConfiguration :: Unquantized1024 ( _, h) => h. zero_neighborhood_size ( ) ,
322
342
}
323
343
}
324
344
pub fn threshold_nn (
@@ -346,7 +366,12 @@ impl HnswConfiguration {
346
366
}
347
367
HnswConfiguration :: Quantized1024By16 ( _, q) => {
348
368
Either :: Right ( Either :: Right ( Either :: Right ( Either :: Right ( Either :: Right (
349
- q. threshold_nn ( threshold, search_parameters) ,
369
+ Either :: Left ( q. threshold_nn ( threshold, search_parameters) ) ,
370
+ ) ) ) ) )
371
+ }
372
+ HnswConfiguration :: Unquantized1024 ( _, h) => {
373
+ Either :: Right ( Either :: Right ( Either :: Right ( Either :: Right ( Either :: Right (
374
+ Either :: Right ( h. threshold_nn ( threshold, search_parameters) ) ,
350
375
) ) ) ) )
351
376
}
352
377
}
@@ -372,6 +397,9 @@ impl HnswConfiguration {
372
397
HnswConfiguration :: Quantized1024By16 ( _, q) => {
373
398
q. stochastic_recall ( optimization_parameters)
374
399
}
400
+ HnswConfiguration :: Unquantized1024 ( _, h) => {
401
+ h. stochastic_recall ( optimization_parameters)
402
+ }
375
403
}
376
404
}
377
405
@@ -387,6 +415,7 @@ impl HnswConfiguration {
387
415
}
388
416
HnswConfiguration :: UnquantizedOpenAi ( _, h) => h. build_parameters ,
389
417
HnswConfiguration :: Quantized1024By16 ( _, q) => q. build_parameters_for_improve_index ( ) ,
418
+ HnswConfiguration :: Unquantized1024 ( _, h) => h. build_parameters ,
390
419
}
391
420
}
392
421
@@ -398,6 +427,7 @@ impl HnswConfiguration {
398
427
| HnswConfiguration :: SmallQuantizedOpenAi4 ( _, _)
399
428
| HnswConfiguration :: UnquantizedOpenAi ( _, _) => 1536 ,
400
429
HnswConfiguration :: Quantized1024By16 ( _, _) => 1024 ,
430
+ HnswConfiguration :: Unquantized1024 ( _, _) => 1024 ,
401
431
}
402
432
}
403
433
}
@@ -416,6 +446,7 @@ impl Serializable for HnswConfiguration {
416
446
HnswConfiguration :: SmallQuantizedOpenAi8 ( _, qhnsw) => qhnsw. serialize ( & path) ?,
417
447
HnswConfiguration :: SmallQuantizedOpenAi4 ( _, qhnsw) => qhnsw. serialize ( & path) ?,
418
448
HnswConfiguration :: Quantized1024By16 ( _, qhnsw) => qhnsw. serialize ( & path) ?,
449
+ HnswConfiguration :: Unquantized1024 ( _, hnsw) => hnsw. serialize ( & path) ?,
419
450
}
420
451
let state_path: PathBuf = path. as_ref ( ) . join ( "state.json" ) ;
421
452
let mut state_file = OpenOptions :: new ( )
@@ -473,6 +504,9 @@ impl Serializable for HnswConfiguration {
473
504
QuantizedHnsw :: deserialize ( path, params) ?,
474
505
)
475
506
}
507
+ HnswConfigurationType :: Unquantized1024 => {
508
+ HnswConfiguration :: Unquantized1024 ( state. model , Hnsw :: deserialize ( path, params) ?)
509
+ }
476
510
} )
477
511
}
478
512
}
0 commit comments