Skip to content

Commit a8d3c56

Browse files
authored
Merge pull request #151 from meilisearch/prepare-for-conversion-from-hannoy
Introduce the `Writer::prepare_for_conversion` method
2 parents ee83882 + a8f5188 commit a8d3c56

File tree

7 files changed

+227
-87
lines changed

7 files changed

+227
-87
lines changed

.github/workflows/rust.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Rust CI
22

33
on:
44
push:
5-
branches: ["main"]
5+
branches: ["main", "release-v0.6"]
66
pull_request:
7-
branches: ["main"]
7+
branches: ["main", "release-v0.6"]
88

99
env:
1010
CARGO_TERM_COLOR: always
@@ -24,7 +24,7 @@ jobs:
2424

2525
steps:
2626
- uses: actions/checkout@v1
27-
- uses: dtolnay/rust-toolchain@1.81
27+
- uses: dtolnay/rust-toolchain@1.85
2828
- uses: actions-rs/cargo@v1
2929
with:
3030
command: build
@@ -41,7 +41,7 @@ jobs:
4141
runs-on: ubuntu-latest
4242
steps:
4343
- uses: actions/checkout@v1
44-
- uses: dtolnay/rust-toolchain@1.81
44+
- uses: dtolnay/rust-toolchain@1.85
4545
with:
4646
profile: minimal
4747
components: clippy, rustfmt

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "arroy"
33
description = "Annoy-inspired Approximate Nearest Neighbors in Rust, based on LMDB and optimized for memory usage"
4-
version = "0.6.2"
4+
version = "0.6.3"
55
documentation = "https://docs.rs/arroy"
66
repository = "https://github.com/meilisearch/arroy"
77
keywords = ["ANN-search", "Graph-algorithms", "Vector-Search", "Store"]
@@ -31,9 +31,11 @@ enum-iterator = "2.1.0"
3131

3232
[dev-dependencies]
3333
anyhow = "1.0.95"
34+
approx = "0.5.1"
3435
arbitrary = { version = "1.4.1", features = ["derive"] }
3536
clap = { version = "4.5.24", features = ["derive"] }
3637
env_logger = "0.11.6"
38+
hannoy = "0.0.4"
3739
insta = "1.42.0"
3840
instant-distance = "0.6.1"
3941
proptest = "1.6.0"

src/node.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,24 @@ impl<'a, D: Distance> BytesDecode<'a> for NodeCodec<D> {
188188
[DESCENDANTS_TAG, bytes @ ..] => Ok(Node::Descendants(Descendants {
189189
descendants: Cow::Owned(RoaringBitmap::deserialize_from(bytes)?),
190190
})),
191-
unknown => panic!("What the fuck is an {unknown:?}"),
191+
[unknown_tag, ..] => {
192+
Err(Box::new(InvalidNodeDecoding { unknown_tag: Some(*unknown_tag) }))
193+
}
194+
[] => Err(Box::new(InvalidNodeDecoding { unknown_tag: None })),
195+
}
196+
}
197+
}
198+
199+
#[derive(Debug, thiserror::Error)]
200+
pub struct InvalidNodeDecoding {
201+
unknown_tag: Option<u8>,
202+
}
203+
204+
impl fmt::Display for InvalidNodeDecoding {
205+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
206+
match self.unknown_tag {
207+
Some(unknown_tag) => write!(f, "Invalid node decoding: unknown tag {unknown_tag}"),
208+
None => write!(f, "Invalid node decoding: empty array of bytes"),
192209
}
193210
}
194211
}

src/reader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ impl<'t, D: Distance> Reader<'t, D> {
321321
let key = Key::new(self.index, item);
322322
match self.database.get(rtxn, &key)?.ok_or(Error::missing_key(key))? {
323323
Node::Leaf(_) => {
324-
if opt.candidates.map_or(true, |c| c.contains(item.item)) {
324+
if opt.candidates.is_none_or(|c| c.contains(item.item)) {
325325
nns.push(item.unwrap_item());
326326
}
327327
}

src/tests/binary_quantized.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ fn write_and_retrieve_binary_quantized_vector() {
4444
writer.builder(&mut rng()).n_trees(1).build(&mut wtxn).unwrap();
4545
wtxn.commit().unwrap();
4646

47-
insta::assert_snapshot!(handle, @r#"
47+
insta::assert_snapshot!(handle, @r###"
4848
==================
4949
Dumping index 0
5050
Root: Metadata { dimensions: 16, items: RoaringBitmap<[0]>, roots: [0], distance: "binary quantized euclidean" }
51-
Version: Version { major: 0, minor: 6, patch: 2 }
51+
Version: Version { major: 0, minor: 6, patch: 3 }
5252
Tree 0: Descendants(Descendants { descendants: [0] })
5353
Item 0: Leaf(Leaf { header: NodeHeaderBinaryQuantizedEuclidean { bias: 0.0 }, vector: [-1.0000, -1.0000, 1.0000, -1.0000, 1.0000, 1.0000, -1.0000, 1.0000, -1.0000, -1.0000, "other ..."] })
54-
"#);
54+
"###);
5555
}

0 commit comments

Comments
 (0)