Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge 0.7.0 into master #436

Merged
merged 57 commits into from
Feb 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
48bbed6
add throw statement to errors in BruteforceSearch
yoshoku Mar 21, 2022
5f074d5
remove unnecessary new operators
yoshoku Mar 21, 2022
eae971a
Merge pull request #375 from yoshoku/fix_errors
yurymalkov Mar 22, 2022
d51c312
chore(ALGO_PARAMS.md): Fix typo
PLNech May 2, 2022
492e15e
Highlight code
korzhenevski Jun 2, 2022
fb3a699
fix global linkage
MasterAler Jun 8, 2022
fb1885b
Merge pull request #380 from korzhenevski/patch-1
yurymalkov Jun 14, 2022
1431632
Merge pull request #383 from MasterAler/develop
yurymalkov Jun 16, 2022
632da8f
add missing quote
jlmelville Jul 30, 2022
d3197c5
initialize fields in constructor
jlmelville Jul 30, 2022
296b687
Merge pull request #395 from jlmelville/doc/py-quote-readme
yurymalkov Aug 2, 2022
25c7383
direct member initialize fields
jlmelville Aug 4, 2022
fdb1632
Merge pull request #396 from jlmelville/bug/ctor-init
yurymalkov Aug 5, 2022
406731d
Add rust implementation
jianshu93 Aug 9, 2022
765c4ab
Filter elements with an optional filtering function.
kishorenc Aug 15, 2022
ad3440c
Filter function should be sent the label and not the internal ID.
kishorenc Aug 19, 2022
4f6dcc3
Ensure that results are not empty when reading from top results.
kishorenc Aug 19, 2022
0fc42b0
Merge pull request #401 from jianshu93/patch-1
yurymalkov Aug 21, 2022
c5be3f5
Update port git_tester.py on Windows
dyashuni Aug 21, 2022
1c833a7
Make allowAllIds static.
kishorenc Aug 25, 2022
aaee13a
Use functor for filtering.
kishorenc Aug 26, 2022
b87f623
Explicitly check for filter functor being default.
kishorenc Aug 27, 2022
e8da5a0
Refactoring
dyashuni Aug 27, 2022
74bf4a3
Add cpp tests to CI
dyashuni Aug 27, 2022
e97b37c
Merge pull request #406 from dyashuni/add_tests_to_ci
yurymalkov Aug 28, 2022
bdd0220
Use shutil
dyashuni Aug 28, 2022
f0dedf3
Remove duplicate assignment.
kishorenc Aug 28, 2022
de22860
Merge branch 'develop' into filter-elements
kishorenc Aug 28, 2022
e4705fd
Add search with filter test to CI.
kishorenc Aug 28, 2022
7f419ea
Remove constexpr for functor in test.
kishorenc Aug 28, 2022
f7d3366
USE_SSE with msvc compilers
alxvth Aug 29, 2022
23f5351
Remove inclusion of cpu_x86.h
alxvth Aug 29, 2022
e8b3e44
Add cpp tests for Windows in CI
dyashuni Aug 28, 2022
6fa8cd0
Merge pull request #404 from dyashuni/windows_tester
dyashuni Sep 2, 2022
a3e399a
Merge pull request #409 from dyashuni/cpp_windows_tests
dyashuni Sep 2, 2022
1fe7baf
Add check for is_filter_disabled.
kishorenc Sep 6, 2022
c9897b0
Add assert header.
kishorenc Sep 6, 2022
5c14e05
Merge pull request #402 from typesense/filter-elements
dyashuni Sep 6, 2022
c481fd4
Merge branch 'develop' into fix/cpu_x86_include
dyashuni Sep 6, 2022
1f49ffe
Merge pull request #408 from alxvth/fix/cpu_x86_include
dyashuni Sep 6, 2022
6d28ec0
Refactoring (#410)
dyashuni Sep 18, 2022
4ab1d61
Remove some code duplication in bindings (#416)
dyashuni Sep 20, 2022
687ca85
Update python recall test (#415)
dyashuni Sep 20, 2022
983cea9
Python: filter elements with an optional filtering function (#417)
gtsoukas Nov 9, 2022
3e006ea
Replace deleted elements at addition (#418)
dyashuni Jan 12, 2023
28681fc
Getters for max elements, element count and num deleted. (#431)
kishorenc Jan 14, 2023
978f713
Fix insufficient results during filtering. (#430)
kishorenc Jan 14, 2023
d86f8f9
Refactoring of project structure (#432)
dyashuni Jan 15, 2023
225b519
Add warning that python filter works slow in multi-threaded mode
Jan 14, 2023
32f4b02
Add comments with warnings that filter works slow in python in multit…
Jan 15, 2023
2175362
Merge pull request #433 from dyashuni/filter_warning
yurymalkov Jan 15, 2023
2c6f244
Merge pull request #379 from PLNech/patch-1
yurymalkov Jan 15, 2023
dd266bc
preliminary release notes
Jan 15, 2023
d35f428
Add construction speed logging
Jan 17, 2023
68a3387
fix a misprint
yurymalkov Jan 18, 2023
488ab52
Add cpp examples (#435)
dyashuni Jan 30, 2023
dd1bdb7
Merge pull request #434 from nmslib/v07release
yurymalkov Jan 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactoring of project structure (#432)
* Refactor file structure, update readme and examples

* Update Makefile

* Update git tester

* Remove redundant updates_test.cpp, apply suggested changes to example file

* Return back python3 in Makefile
  • Loading branch information
dyashuni authored Jan 15, 2023
commit d86f8f941aa6eec2bbdddc51a3591d4ddd62d974
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

- name: Test
timeout-minutes: 15
run: python -m unittest discover -v --start-directory python_bindings/tests --pattern "*_test*.py"
run: python -m unittest discover -v --start-directory tests/python --pattern "bindings_test*.py"

test_cpp:
runs-on: ${{matrix.os}}
Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:
- name: Prepare test data
run: |
pip install numpy
cd examples
cd tests/cpp/
python update_gen_data.py
shell: bash

Expand Down
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
SET( CMAKE_CXX_FLAGS "-Ofast -lrt -DNDEBUG -std=c++11 -DHAVE_CXX0X -openmp -march=native -fpic -w -fopenmp -ftree-vectorize" )
endif()

add_executable(test_updates examples/updates_test.cpp)
add_executable(test_updates tests/cpp/updates_test.cpp)
target_link_libraries(test_updates hnswlib)

add_executable(searchKnnCloserFirst_test examples/searchKnnCloserFirst_test.cpp)
add_executable(searchKnnCloserFirst_test tests/cpp/searchKnnCloserFirst_test.cpp)
target_link_libraries(searchKnnCloserFirst_test hnswlib)

add_executable(searchKnnWithFilter_test examples/searchKnnWithFilter_test.cpp)
add_executable(searchKnnWithFilter_test tests/cpp/searchKnnWithFilter_test.cpp)
target_link_libraries(searchKnnWithFilter_test hnswlib)

add_executable(multiThreadLoad_test examples/multiThreadLoad_test.cpp)
add_executable(multiThreadLoad_test tests/cpp/multiThreadLoad_test.cpp)
target_link_libraries(multiThreadLoad_test hnswlib)

add_executable(multiThread_replace_test examples/multiThread_replace_test.cpp)
add_executable(multiThread_replace_test tests/cpp/multiThread_replace_test.cpp)
target_link_libraries(multiThread_replace_test hnswlib)

add_executable(main main.cpp sift_1b.cpp)
add_executable(main tests/cpp/main.cpp tests/cpp/sift_1b.cpp)
target_link_libraries(main hnswlib)
endif()
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dist:
python3 -m build --sdist

test:
python3 -m unittest discover --start-directory python_bindings/tests --pattern "*_test*.py"
python3 -m unittest discover --start-directory tests/python --pattern "bindings_test*.py"

clean:
rm -rf *.egg-info build dist tmp var tests/__pycache__ hnswlib.cpython*.so
Expand Down
107 changes: 5 additions & 102 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ Properties of `hnswlib.Index` that support reading and writing:


#### Python bindings examples
[See more examples here](examples/EXAMPLES.md)
```python
import hnswlib
import numpy as np
Expand Down Expand Up @@ -229,104 +230,6 @@ labels, distances = p.knn_query(data, k=1)
print("Recall for two batches:", np.mean(labels.reshape(-1) == np.arange(len(data))), "\n")
```

An example with a filter:
```python
import hnswlib
import numpy as np

dim = 16
num_elements = 10000

# Generating sample data
data = np.float32(np.random.random((num_elements, dim)))

# Declaring index
hnsw_index = hnswlib.Index(space='l2', dim=dim) # possible options are l2, cosine or ip

# Initiating index
# max_elements - the maximum number of elements, should be known beforehand
# (probably will be made optional in the future)
#
# ef_construction - controls index search speed/build speed tradeoff
# M - is tightly connected with internal dimensionality of the data
# strongly affects the memory consumption

hnsw_index.init_index(max_elements=num_elements, ef_construction=100, M=16)

# Controlling the recall by setting ef:
# higher ef leads to better accuracy, but slower search
hnsw_index.set_ef(10)

# Set number of threads used during batch search/construction
# By default using all available cores
hnsw_index.set_num_threads(4)

print("Adding %d elements" % (len(data)))
# Added elements will have consecutive ids
hnsw_index.add_items(data, ids=np.arange(num_elements))

print("Querying only even elements")
# Define filter function that allows only even ids
filter_function = lambda idx: idx%2 == 0
# Query the elements for themselves and search only for even elements:
labels, distances = hnsw_index.knn_query(data, k=1, filter=filter_function)
# labels contain only elements with even id
```

An example with replacing of deleted elements:
```python
import hnswlib
import numpy as np

dim = 16
num_elements = 1_000
max_num_elements = 2 * num_elements

# Generating sample data
labels1 = np.arange(0, num_elements)
data1 = np.float32(np.random.random((num_elements, dim))) # batch 1
labels2 = np.arange(num_elements, 2 * num_elements)
data2 = np.float32(np.random.random((num_elements, dim))) # batch 2
labels3 = np.arange(2 * num_elements, 3 * num_elements)
data3 = np.float32(np.random.random((num_elements, dim))) # batch 3

# Declaring index
hnsw_index = hnswlib.Index(space='l2', dim=dim)

# Initiating index
# max_elements - the maximum number of elements, should be known beforehand
# (probably will be made optional in the future)
#
# ef_construction - controls index search speed/build speed tradeoff
# M - is tightly connected with internal dimensionality of the data
# strongly affects the memory consumption

# Enable replacing of deleted elements
hnsw_index.init_index(max_elements=max_num_elements, ef_construction=200, M=16, allow_replace_deleted=True)

# Controlling the recall by setting ef:
# higher ef leads to better accuracy, but slower search
hnsw_index.set_ef(10)

# Set number of threads used during batch search/construction
# By default using all available cores
hnsw_index.set_num_threads(4)

# Add batch 1 and 2 data
hnsw_index.add_items(data1, labels1)
hnsw_index.add_items(data2, labels2) # Note: maximum number of elements is reached

# Delete data of batch 2
for label in labels2:
hnsw_index.mark_deleted(label)

# Replace deleted elements
# Maximum number of elements is reached therefore we cannot add new items,
# but we can replace the deleted ones by using replace_deleted=True
hnsw_index.add_items(data3, labels3, replace_deleted=True)
# hnsw_index contains the data of batch 1 and batch 3 only
```

### Bindings installation

You can install from sources:
Expand All @@ -346,9 +249,9 @@ Contributions are highly welcome!

Please make pull requests against the `develop` branch.

When making changes please run tests (and please add a test to `python_bindings/tests` in case there is new functionality):
When making changes please run tests (and please add a test to `tests/python` in case there is new functionality):
```bash
python -m unittest discover --start-directory python_bindings/tests --pattern "*_test*.py"
python -m unittest discover --start-directory tests/python --pattern "bindings_test*.py"
```


Expand All @@ -373,7 +276,7 @@ https://github.com/dbaranchuk/ivf-hnsw
### 200M SIFT test reproduction
To download and extract the bigann dataset (from root directory):
```bash
python3 download_bigann.py
python tests/cpp/download_bigann.py
```
To compile:
```bash
Expand All @@ -393,7 +296,7 @@ The size of the BigANN subset (in millions) is controlled by the variable **subs
### Updates test
To generate testing data (from root directory):
```bash
cd examples
cd tests/cpp
python update_gen_data.py
```
To compile (from root directory):
Expand Down
Loading