| 153 | } |
| 154 | |
| 155 | bool test_query() { |
| 156 | IndexFixture f("test_query"); |
| 157 | if (!f.init()) return false; |
| 158 | |
| 159 | auto target_emb = random_embedding(); |
| 160 | f.add(1, "target", target_emb); |
| 161 | for (int i = 2; i <= 10; ++i) f.add(i, "other"); |
| 162 | |
| 163 | auto results = f.query(target_emb, 1); |
| 164 | if (results.empty() || results[0] != 1) return false; |
| 165 | |
| 166 | f.del(1); |
| 167 | results = f.query(target_emb, 10); |
| 168 | for (int id : results) { |
| 169 | if (id == 1) return false; |
| 170 | } |
| 171 | |
| 172 | return true; |
| 173 | } |
| 174 | |
| 175 | bool test_compact() { |
| 176 | IndexFixture f("test_compact"); |