Skip to content

Commit

Permalink
fix: restore from latest snapshot (#204)
Browse files Browse the repository at this point in the history
* fix: restore from latest snapshot

* chore: update readme

* chore: update readme

* chore: bump v0.5.2
  • Loading branch information
numb3r3 authored Nov 3, 2022
1 parent 2462afa commit 3f886f1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,27 @@ The query will be performed on the field if the condition is satisfied. The foll
}
```

## Dump and Load

By default, the hnsw index is in memory. You can dump the index to `data_path` by calling `.dump()`:

```python

from annlite import AnnLite

ann = AnnLite(128, metric='cosine', data_path="/path/to/data_path")
ann.index(docs)
ann.dump()
```

And you can restore the hnsw index from `data_path` if it exists:

```python
new_ann = AnnLite(128, metric='cosine', data_path="/path/to/data_path")
```

If you didn't dump the hnsw index, the index will be rebuilt from scratch. This will take a while.

## Supported distance metrics

The annlite supports the following distance metrics:
Expand Down
4 changes: 3 additions & 1 deletion annlite/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,10 @@ def snapshot_path(self):
paths = list(
(self.data_path / f'snapshot-{self.params_hash}').glob(f'*-SNAPSHOT')
)

if paths:
return paths[0]
paths = sorted(paths, key=lambda x: x.name)
return paths[-1]
return None

@property
Expand Down

0 comments on commit 3f886f1

Please sign in to comment.