@@ -85,6 +85,7 @@ pub mod ffi {
85
85
pub fn view ( self : & NativeIndex , path : & str ) -> Result < ( ) > ;
86
86
pub fn reset ( self : & NativeIndex ) -> Result < ( ) > ;
87
87
pub fn memory_usage ( self : & NativeIndex ) -> usize ;
88
+ pub fn hardware_acceleration ( self : & NativeIndex ) -> * const c_char ;
88
89
89
90
pub fn save_to_buffer ( self : & NativeIndex , buffer : & mut [ u8 ] ) -> Result < ( ) > ;
90
91
pub fn load_from_buffer ( self : & NativeIndex , buffer : & [ u8 ] ) -> Result < ( ) > ;
@@ -202,6 +203,15 @@ impl Index {
202
203
self . inner . change_expansion_search ( n)
203
204
}
204
205
206
+ /// Retrieves the hardware acceleration information.
207
+ pub fn hardware_acceleration ( & self ) -> String {
208
+ use core:: ffi:: CStr ;
209
+ unsafe {
210
+ let c_str = CStr :: from_ptr ( self . inner . hardware_acceleration ( ) ) ;
211
+ c_str. to_string_lossy ( ) . into_owned ( )
212
+ }
213
+ }
214
+
205
215
/// Performs k-Approximate Nearest Neighbors (kANN) Search for closest vectors to the provided query.
206
216
///
207
217
/// # Arguments
@@ -438,6 +448,81 @@ mod tests {
438
448
use crate :: new_index;
439
449
use crate :: Index ;
440
450
451
+ use std:: env;
452
+
453
+ #[ test]
454
+ fn print_specs ( ) {
455
+ print ! ( "--------------------------------------------------\n " ) ;
456
+ println ! ( "OS: {}" , env:: consts:: OS ) ;
457
+ println ! (
458
+ "Rust version: {}" ,
459
+ env:: var( "RUST_VERSION" ) . unwrap_or_else( |_| "unknown" . into( ) )
460
+ ) ;
461
+
462
+ // Create indexes with different configurations
463
+ let f64_index = Index :: new ( & IndexOptions {
464
+ dimensions : 256 ,
465
+ metric : MetricKind :: Cos ,
466
+ quantization : ScalarKind :: F64 ,
467
+ ..Default :: default ( )
468
+ } )
469
+ . unwrap ( ) ;
470
+
471
+ let f32_index = Index :: new ( & IndexOptions {
472
+ dimensions : 256 ,
473
+ metric : MetricKind :: Cos ,
474
+ quantization : ScalarKind :: F32 ,
475
+ ..Default :: default ( )
476
+ } )
477
+ . unwrap ( ) ;
478
+
479
+ let f16_index = Index :: new ( & IndexOptions {
480
+ dimensions : 256 ,
481
+ metric : MetricKind :: Cos ,
482
+ quantization : ScalarKind :: F16 ,
483
+ ..Default :: default ( )
484
+ } )
485
+ . unwrap ( ) ;
486
+
487
+ let i8_index = Index :: new ( & IndexOptions {
488
+ dimensions : 256 ,
489
+ metric : MetricKind :: Cos ,
490
+ quantization : ScalarKind :: I8 ,
491
+ ..Default :: default ( )
492
+ } )
493
+ . unwrap ( ) ;
494
+
495
+ let b1_index = Index :: new ( & IndexOptions {
496
+ dimensions : 256 ,
497
+ metric : MetricKind :: Hamming ,
498
+ quantization : ScalarKind :: B1 ,
499
+ ..Default :: default ( )
500
+ } )
501
+ . unwrap ( ) ;
502
+
503
+ println ! (
504
+ "f64 hardware acceleration: {}" ,
505
+ f64_index. hardware_acceleration( )
506
+ ) ;
507
+ println ! (
508
+ "f32 hardware acceleration: {}" ,
509
+ f32_index. hardware_acceleration( )
510
+ ) ;
511
+ println ! (
512
+ "f16 hardware acceleration: {}" ,
513
+ f16_index. hardware_acceleration( )
514
+ ) ;
515
+ println ! (
516
+ "i8 hardware acceleration: {}" ,
517
+ i8_index. hardware_acceleration( )
518
+ ) ;
519
+ println ! (
520
+ "b1 hardware acceleration: {}" ,
521
+ b1_index. hardware_acceleration( )
522
+ ) ;
523
+ print ! ( "--------------------------------------------------\n " ) ;
524
+ }
525
+
441
526
#[ test]
442
527
fn test_add_get_vector ( ) {
443
528
let mut options = IndexOptions :: default ( ) ;
@@ -494,17 +579,17 @@ mod tests {
494
579
let mut found_slice = [ 0.0 as f32 ; 4 ] ;
495
580
assert_eq ! ( index. get( id1, & mut found_slice) . unwrap( ) , 1 ) ;
496
581
assert ! ( index. remove( id1) . is_ok( ) ) ;
497
-
582
+
498
583
assert ! ( index. add( id2, & second) . is_ok( ) ) ;
499
584
let mut found_slice = [ 0.0 as f32 ; 4 ] ;
500
585
assert_eq ! ( index. get( id2, & mut found_slice) . unwrap( ) , 1 ) ;
501
586
assert ! ( index. remove( id2) . is_ok( ) ) ;
502
-
587
+
503
588
assert ! ( index. add( id3, & second) . is_ok( ) ) ;
504
589
let mut found_slice = [ 0.0 as f32 ; 4 ] ;
505
590
assert_eq ! ( index. get( id3, & mut found_slice) . unwrap( ) , 1 ) ;
506
591
assert ! ( index. remove( id3) . is_ok( ) ) ;
507
-
592
+
508
593
assert ! ( index. add( id4, & second) . is_ok( ) ) ;
509
594
let mut found_slice = [ 0.0 as f32 ; 4 ] ;
510
595
assert_eq ! ( index. get( id4, & mut found_slice) . unwrap( ) , 1 ) ;
@@ -532,6 +617,7 @@ mod tests {
532
617
let first: [ f32 ; 5 ] = [ 0.2 , 0.1 , 0.2 , 0.1 , 0.3 ] ;
533
618
let second: [ f32 ; 5 ] = [ 0.3 , 0.2 , 0.4 , 0.0 , 0.1 ] ;
534
619
620
+ print ! ( "--------------------------------------------------\n " ) ;
535
621
println ! (
536
622
"before add, memory_usage: {} \
537
623
cap: {} \
@@ -566,6 +652,7 @@ mod tests {
566
652
let results = index. search ( & first, 10 ) . unwrap ( ) ;
567
653
println ! ( "{:?}" , results) ;
568
654
assert_eq ! ( results. keys. len( ) , 2 ) ;
655
+ print ! ( "--------------------------------------------------\n " ) ;
569
656
570
657
// Validate serialization
571
658
assert ! ( index. save( "index.rust.usearch" ) . is_ok( ) ) ;
0 commit comments