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/vec1func.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 / vec1func.test` 115 lines ยท 3361 bytes Raw Blame History 1 # 2026-01-17 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 # 13 14 source [file join [file dirname [info script]] vec1_common.tcl] 15 set testprefix vec1func 16 vec1_load db 17 18 do_execsql_test 1.0 { 19 SELECT vec1_to_json( 20 vec1_from_json('[1.0, 2.0, 3.0, 4.0]') 21 ) 22 } {{[1,2,3,4]}} 23 24 do_execsql_test 1.1 { 25 SELECT quote(vec1_from_json('[1.0, 2.0, 3.0, 4.0]')) 26 } {X'0000803F000000400000404000008040'} 27 28 do_catchsql_test 1.2 { 29 SELECT vec1_to_json(X'') 30 } {1 {vec1: invalid vector argument}} 31 32 do_catchsql_test 1.3 { 33 SELECT vec1_to_json(X'0000803F000000400000404000008040FF') 34 } {1 {vec1: invalid vector argument}} 35 36 do_execsql_test 1.4 { 37 SELECT vec1_to_json(X'0000803F000000400000404000008040') 38 } {[1,2,3,4]} 39 40 do_execsql_test 1.5 { 41 SELECT vec1_to_json_i(X'0000803F000000400000404000008040') 42 } {[`1065353216`,`1073741824`,`1077936128`,`1082130432`]} 43 44 #------------------------------------------------------------------------- 45 46 foreach {tn in out} { 47 1 " [1,2,3] " "0 {{[1,2,3]}}" 48 2 " [ 1 , 2 , 3 ] " "0 {{[1,2,3]}}" 49 3 " {1,2,3} " "1 {error parsing json vector}" 50 4 " [1,2,3" "1 {error parsing json vector}" 51 5 " [1,2, ]" "1 {error parsing json vector}" 52 6 " [1,2,3] x " "1 {error parsing json vector}" 53 } { 54 do_catchsql_test 2.$tn { 55 SELECT vec1_to_json( vec1_from_json($in) ) 56 } $out 57 } 58 59 #------------------------------------------------------------------------- 60 61 do_execsql_test 3.0 { 62 SELECT vec1_cos_distance(random_vector(9), random_vector(9)) 63 BETWEEN 0.0 AND 2.0 64 } {1} 65 66 do_catchsql_test 3.1 { 67 SELECT vec1_cos_distance(random_vector(9), random_vector(8)) 68 } {1 {vec1_cos_distance: bad arguments}} 69 do_catchsql_test 3.2 { 70 SELECT vec1_cos_distance(randomblob(37), randomblob(37)) 71 } {1 {vec1_cos_distance: bad arguments}} 72 73 do_catchsql_test 3.3 { 74 SELECT vec1_l2_distance(random_vector(9), random_vector(8)) 75 } {1 {vec1_l2_distance: bad arguments}} 76 do_catchsql_test 3.4 { 77 SELECT vec1_l2_distance(randomblob(37), randomblob(37)) 78 } {1 {vec1_l2_distance: bad arguments}} 79 80 #------------------------------------------------------------------------- 81 # Test that vectors of zero magnitude are considered orthogonal to all 82 # others, including itself. 83 84 do_execsql_test 4.0 { 85 SELECT vec1_cos_distance(random_vector(9), zeroblob(4*9)); 86 } {1.0} 87 do_execsql_test 4.1 { 88 SELECT vec1_cos_distance(zeroblob(4*9), random_vector(9)); 89 } {1.0} 90 91 #------------------------------------------------------------------------- 92 # Test that non-blob arguments are errors. 93 # 94 foreach {tn a2 bErr} { 95 0 { (X'`12345678`', X'`12345678`') } 0 96 1 { (X'`12345678`', '`12345678`') } 1 97 2 { ('`12345678`', '`12345678`') } 1 98 3 { ('`12345678`', X'`12345678`') } 1 99 } { 100 do_test 5.$tn.1 { 101 lindex [catchsql "SELECT vec1_l2_distance $a2"] 0 102 } $bErr 103 do_test 5.$tn.2 { 104 lindex [catchsql "SELECT vec1_cos_distance $a2"] 0 105 } $bErr 106 } 107 108 #------------------------------------------------------------------------- 109 # 110 111 do_execsql_test 6.0 { SELECT vec1_from_json(NULL) } {{}} 112 do_execsql_test 6.1 { SELECT vec1_from_json(NULL) IS NULL } {1} 113 114 finish_test 115