Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/ext/vec1/test/vec1bqcos.test # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / ext / vec1 / test / vec1bqcos.test` 107 lines ยท 2889 bytes Raw Blame History 1 # 2026-10-18 2 # 3 # The author disclaims copyright to this source code. In place of 4 # a legal notice, here is a blessing: 5 # 6 # May you do good and not evil. 7 # May you find forgiveness for yourself and forgive others. 8 # May you share freely, never taking more than you give. 9 # 10 #*********************************************************************** 11 # 12 # Test recall of binary-quantized ("bq") indexes. 13 # 14 15 source [file join [file dirname [info script]] vec1_common.tcl] 16 set testprefix vec1bqcos 17 18 vec1_load db 19 expr srand(0) 20 21 set N 20000 ;# Number of vectors in the table 22 set D 256 ;# Dimensions per vector 23 set NQ 100 ;# Number of queries 24 set NB 64 ;# Number of buckets 25 26 # Return a normally distributed random value. 27 proc gauss {} { 28 set u1 [expr {1.0 - rand()}] 29 set u2 [expr {rand()}] 30 expr {sqrt(-2.0 * log($u1)) * cos(6.`283185307179586` * $u2)} 31 } 32 33 # Generate the common offset vector. 34 set lOffset [list] 35 for {set ii 0} {$ii < $D} {incr ii} { 36 lappend lOffset [gauss] 37 } 38 39 # Return a unit-length vector equal to the common offset plus 40 # gaussian noise. 41 proc offset_vector {} { 42 global lOffset 43 set lVec [list] 44 set sum 0.0 45 foreach o $lOffset { 46 set x [expr {$o + [gauss]}] 47 lappend lVec $x 48 set sum [expr {$sum + $x*$x}] 49 } 50 set norm [expr {sqrt($sum)}] 51 set lRet [list] 52 foreach x $lVec { 53 lappend lRet [expr {$x / $norm}] 54 } 55 binary format f* $lRet 56 } 57 db func offset_vector offset_vector 58 59 do_execsql_test 1.0 { 60 CREATE VIRTUAL TABLE t USING vec1(v); 61 CREATE TABLE q(id INTEGER PRIMARY KEY, v BLOB); 62 WITH s(i) AS ( 63 SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i=0} { incr hits } 98 } 99 } 100 set recall [expr {double($hits) / (10 * $NQ)}] 101 set fmt [format " {%s} recall@10 = %.3f" $extra $recall] 102 do_test 2.$tn.2.$fmt { 103 expr {$recall > 0.25} 104 } 1 105 } 106 107 finish_test