Skip to content

Commit

Permalink
add resize
Browse files Browse the repository at this point in the history
  • Loading branch information
uzushino committed Jan 14, 2024
1 parent 1eddf6e commit 6e9e7b9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,40 @@
# voyager-rs

まだ途中 mm
[spotify/voyager](https://github.com/spotify/voyager) bindings for Rust.

```toml
[dependencies]
voyager_rs = { git = "https://github.com/uzushino/voyager_rs" }
```

## Building

```
$ git clone [email protected]:uzushino/voyager-rs.git
$ cd voyager-rs
$ git submodule update
$ cargo test
```

## Example

```rust
let v = Voyager::new();

let v1 = &[1.0, 2.0, 3.0, 4.0, 5.0];
let v2 = &[6.0, 7.0, 8.0, 9.0, 10.0];

v.add_item(v1, Some(1));
v.add_item(v2, Some(2));

let (result, distance) = v.query(v1, 2, None);

assert!(result == vec![1, 2]);
assert!(distance == vec![0.0, 125.0]);
```

## Feature

- [x] add_item
- [x] get_distance
- [x] query
4 changes: 4 additions & 0 deletions src/c/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ float get_distance(IndexVm* vm, float* a, float* b, size_t len) {
std::vector<float> v2(b, b + len);

return vm->index_->GetDistance(v1, v2);
}

void resize(IndexVm* vm, size_t size) {
vm->index_->ResizeIndex(size);
}
4 changes: 4 additions & 0 deletions src/c/index.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ namespace voyager {
return index_->getDistance(v1, v2);
}

void ResizeIndex(size_t size) {
index_->resizeIndex(size);
}

private:
std::shared_ptr<::Index> index_;

Expand Down

0 comments on commit 6e9e7b9

Please sign in to comment.