| 102 | |
| 103 | #[tokio::test] |
| 104 | async fn test_vector_index_operations() { |
| 105 | let index = VectorIndex::new(); |
| 106 | |
| 107 | let id1 = MemoryId::new(); |
| 108 | let id2 = MemoryId::new(); |
| 109 | |
| 110 | // Insert two vectors |
| 111 | index.insert(id1.clone(), vec![1.0, 0.0, 0.0]).await; |
| 112 | index.insert(id2.clone(), vec![0.0, 1.0, 0.0]).await; |
| 113 | |
| 114 | // Search with a vector close to id1 |
| 115 | let results = index |
| 116 | .search(&[0.9, 0.1, 0.0], 10, 0.0) |
| 117 | .await |
| 118 | .expect("search ok"); |
| 119 | assert_eq!(results.len(), 2); |
| 120 | // The first result should be closer to id1 |
| 121 | assert_eq!(results[0].0, id1); |
| 122 | assert!(results[0].1 > results[1].1); |
| 123 | |
| 124 | // Remove id1 |
| 125 | index.remove(&id1).await; |
| 126 | let results = index |
| 127 | .search(&[1.0, 0.0, 0.0], 10, 0.0) |
| 128 | .await |
| 129 | .expect("search ok"); |
| 130 | assert_eq!(results.len(), 1); |
| 131 | assert_eq!(results[0].0, id2); |
| 132 | } |
| 133 | |
| 134 | #[tokio::test] |
| 135 | async fn test_vector_index_threshold() { |