(no description set)
This commit is contained in:
@@ -136,6 +136,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_knn_k_never_exceeds_sqlite_vec_limit() {
|
fn test_knn_k_never_exceeds_sqlite_vec_limit() {
|
||||||
|
// Brute-force: no combination of valid inputs should exceed 4096.
|
||||||
for limit in [1, 10, 50, 100, 500, 1000, 1500, 2000, 5000] {
|
for limit in [1, 10, 50, 100, 500, 1000, 1500, 2000, 5000] {
|
||||||
for max_chunks in [1, 2, 5, 10, 50, 100, 200, 500, 1000] {
|
for max_chunks in [1, 2, 5, 10, 50, 100, 200, 500, 1000] {
|
||||||
let k = compute_knn_k(limit, max_chunks);
|
let k = compute_knn_k(limit, max_chunks);
|
||||||
@@ -149,33 +150,37 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_knn_k_reproduces_original_bug_scenario() {
|
fn test_knn_k_reproduces_original_bug_scenario() {
|
||||||
|
// The original bug: limit=1500 (RECALL_CAP) with multiplier >= 8
|
||||||
|
// produced k=10_000 which exceeded sqlite-vec's 4096 cap.
|
||||||
let k = compute_knn_k(1500, 1);
|
let k = compute_knn_k(1500, 1);
|
||||||
assert!(
|
assert!(k <= SQLITE_VEC_KNN_MAX, "k={k} exceeded 4096 at RECALL_CAP with 1 chunk");
|
||||||
k <= SQLITE_VEC_KNN_MAX,
|
|
||||||
"k={k} exceeded 4096 at RECALL_CAP with 1 chunk"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_knn_k_small_limit_uses_minimum_multiplier() {
|
fn test_knn_k_small_limit_uses_minimum_multiplier() {
|
||||||
|
// With 1 chunk, multiplier clamps to minimum of 8.
|
||||||
let k = compute_knn_k(10, 1);
|
let k = compute_knn_k(10, 1);
|
||||||
assert_eq!(k, 80);
|
assert_eq!(k, 80);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_knn_k_high_chunks_caps_multiplier() {
|
fn test_knn_k_high_chunks_caps_multiplier() {
|
||||||
|
// With 200 chunks, multiplier = (200*3/2 + 1) = 301 → clamped to 200.
|
||||||
|
// limit=10 * 200 = 2000 < 4096.
|
||||||
let k = compute_knn_k(10, 200);
|
let k = compute_knn_k(10, 200);
|
||||||
assert_eq!(k, 2000);
|
assert_eq!(k, 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_knn_k_zero_max_chunks_treated_as_one() {
|
fn test_knn_k_zero_max_chunks_treated_as_one() {
|
||||||
|
// max_chunks_per_doc=0 → unsigned_abs().max(1) = 1
|
||||||
let k = compute_knn_k(10, 0);
|
let k = compute_knn_k(10, 0);
|
||||||
assert_eq!(k, 80);
|
assert_eq!(k, 80); // multiplier clamp(8, 200) → 8
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_knn_k_negative_max_chunks_uses_absolute() {
|
fn test_knn_k_negative_max_chunks_uses_absolute() {
|
||||||
|
// Defensive: negative values use unsigned_abs
|
||||||
let k = compute_knn_k(10, -5);
|
let k = compute_knn_k(10, -5);
|
||||||
assert_eq!(k, compute_knn_k(10, 5));
|
assert_eq!(k, compute_knn_k(10, 5));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user