Python bindings for the Dynamic Exploration Graph library by Nico Hezel
Project description
deglib: Python bindings for the Dynamic Exploration Graph
Python bindings for the C++ library Dynamic Exploration Graph used in the paper: Fast Approximate Nearest Neighbor Search with a Dynamic Exploration Graph using Continuous Refinement
Table of Contents
Installation
Using pip
pip install deglib
This will install a source package, that needs to compile the C++ code in order to create an optimized version for your system.
Compiling from Source
Create Virtual Environment
# create virtualenv with virtualenvwrapper or venv
mkvirtualenv deglib
# or
python -m venv /path/to/deglib_env && . /path/to/deglib_env/bin/activate
Get the Source
# clone git repository
git clone git@github.com:Visual-Computing/DynamicExplorationGraph.git
cd DynamicExplorationGraph/python
Install the Package from Source
pip install setuptools pybind11 build
python setup.py copy_build_files # copy c++ library to ./lib/
pip install .
This will compile the C++ code and install deglib into your virtual environment, so it may take a while.
Testing
To execute all tests.
pytest
Building Packages
Build packages (sdist and wheels):
python -m build
Note: If you want to publish linux wheels to pypi you have to convert
the wheel to musllinux-/manylinux-wheels.
This can be easily done using cibuildwheel
(if docker is installed):
cibuildwheel --archs auto64 --output-dir dist
Examples
Loading Data
To load a dataset formatted like the TexMex-Datasets:
import deglib
import numpy as np
dataset: np.ndarray = deglib.repository.fvecs_read("path/to/data.fvecs")
num_samples, dims = dataset.shape
The dataset is a numpy array with shape (N, D), where N is the number of feature vectors and D is the number of dimensions of each feature vector.
Building a Graph
graph = deglib.builder.build_from_data(dataset, edges_per_vertex=32, callback="progress")
graph.save_graph("/path/to/graph.deg")
rd_graph = deglib.graph.load_readonly_graph("/path/to/graph.deg")
Searching the Graph
# query can have shape (D,) or (Q, D), where
# D is the dimensionality of the dataset and
# Q is the number of queries.
query = np.random.random((dims,)).astype(np.float32)
result, dists = graph.search(query, eps=0.1, k=10) # get 10 nearest features to query
print('best dataset index:', result[0])
best_match = dataset[result[0]]
For more examples see tests.
Referencing C++ memory
Consider the following example:
feature_vector = graph.get_feature_vector(42)
del graph
print(feature_vector)
This will crash as feature_vector
is holding a reference to memory that is owned by graph
. This can lead to undefined behaviour (most likely segmentation fault).
Be careful to keep objects in memory that are referenced. If you need it use the copy=True
option:
feature_vector = graph.get_feature_vector(10, copy=True)
del graph
print(feature_vector) # no problem
Copying feature vectors will be slower.
Naming
Vertex = Feature Vector
Each vertex in the graph corresponds to a feature vector of the dataset.
Internal Index vs External Label
There are two kinds of indices used in a graph: internal_index
and external_label
. Both are integers and specify
a vertex in a graph.
Internal Indices are dense, which means that every internal_index < len(graph)
can be used.
For example: If you add 100 vertices and remove the vertex with internal_index 42, the last vertex in the graph will
be moved to index 42.
In contrast, external label is a user defined identifier for each added vertex
(see builder.add_entry(external_label, feature_vector)
). Adding or Removing vertices to the graph will keep the
connection between external labels and associated feature vector.
When you create the external labels by starting with 0
and increasing it for each entry by 1
and don't remove
elements from the graph, external labels and internal indices are equal.
# as long as no elements are removed
# external labels and internal indices are equal
for i, vec in enumerate(data):
builder.add_entry(i, vec)
Eps
The eps-search-parameter controls how many nodes are checked during search. Lower eps values like 0.001 are faster but less accurate. Higher eps values like 0.1 are slower but more accurate. Should always be greater 0.
Relative Neighborhood Graph / RNG-conform
TODO
Limitations
- The python wrapper at the moment only supports
float32
anduint8
feature vectors.
Troubleshooting
BuildError: pybind11/typing.h:104:58: error: ‘copy_n’ is not a member of ‘std’
This is a pybind11 bug, that occurs when compiling it with gcc-14. Change the pybind version to 2.12.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file deglib-0.1.0.tar.gz
.
File metadata
- Download URL: deglib-0.1.0.tar.gz
- Upload date:
- Size: 68.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d67bed21fbe066f032bcda5b747349b98b9f97ac30aab341aeab16a70bb99dc |
|
MD5 | 90a70423de5c53419fb6417920eca578 |
|
BLAKE2b-256 | 19daebd52afe2ba33f752101655baa398a0592e72bb2ef3df1a6d472f8874128 |
Provenance
The following attestation bundles were made for deglib-0.1.0.tar.gz
:
Publisher:
BuildAndPublish.yml
on Visual-Computing/DynamicExplorationGraph
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
deglib-0.1.0.tar.gz
- Subject digest:
6d67bed21fbe066f032bcda5b747349b98b9f97ac30aab341aeab16a70bb99dc
- Sigstore transparency entry: 145605628
- Sigstore integration time:
- Predicate type:
File details
Details for the file deglib-0.1.0-cp312-cp312-win_amd64.whl
.
File metadata
- Download URL: deglib-0.1.0-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 242.2 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d2ffc312819806df13abc6a505da5da877e6823444e3aac6e57d8fde792b399 |
|
MD5 | 0acc5e9239f90d9147153c24a82f4006 |
|
BLAKE2b-256 | 63162d03224df3ba37d8b54c25526c7e7a2105fd810b6de2f0a0d69d4b3902c8 |
Provenance
The following attestation bundles were made for deglib-0.1.0-cp312-cp312-win_amd64.whl
:
Publisher:
BuildAndPublish.yml
on Visual-Computing/DynamicExplorationGraph
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
deglib-0.1.0-cp312-cp312-win_amd64.whl
- Subject digest:
6d2ffc312819806df13abc6a505da5da877e6823444e3aac6e57d8fde792b399
- Sigstore transparency entry: 145605644
- Sigstore integration time:
- Predicate type:
File details
Details for the file deglib-0.1.0-cp312-cp312-musllinux_1_2_x86_64.whl
.
File metadata
- Download URL: deglib-0.1.0-cp312-cp312-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.12, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94c29fba7f71d6d9d6dfd0dfd5ba316b0141261243806bb6f8257ad57279b0e0 |
|
MD5 | 2158a4c2d34401ad846e22f3a781b6b1 |
|
BLAKE2b-256 | 2d3099a1fb09ad97278d434e4924446d3633a946320f2ddad0e269319dc6db92 |
Provenance
The following attestation bundles were made for deglib-0.1.0-cp312-cp312-musllinux_1_2_x86_64.whl
:
Publisher:
BuildAndPublish.yml
on Visual-Computing/DynamicExplorationGraph
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
deglib-0.1.0-cp312-cp312-musllinux_1_2_x86_64.whl
- Subject digest:
94c29fba7f71d6d9d6dfd0dfd5ba316b0141261243806bb6f8257ad57279b0e0
- Sigstore transparency entry: 145605631
- Sigstore integration time:
- Predicate type:
File details
Details for the file deglib-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: deglib-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 469.0 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b382e33d8e52141c7fa9bd787c85df240ffc3f60bb4ec5ab972c477e5f5bb4a |
|
MD5 | 81c2fbdce80d96f776aa0f136a30c470 |
|
BLAKE2b-256 | 04836f25e6ad783db8718c994ba0a29e68cc970c7b0bb13d049a8f4cff2ed943 |
Provenance
The following attestation bundles were made for deglib-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
:
Publisher:
BuildAndPublish.yml
on Visual-Computing/DynamicExplorationGraph
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
deglib-0.1.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
- Subject digest:
4b382e33d8e52141c7fa9bd787c85df240ffc3f60bb4ec5ab972c477e5f5bb4a
- Sigstore transparency entry: 145605645
- Sigstore integration time:
- Predicate type:
File details
Details for the file deglib-0.1.0-cp312-cp312-macosx_11_0_x86_64.whl
.
File metadata
- Download URL: deglib-0.1.0-cp312-cp312-macosx_11_0_x86_64.whl
- Upload date:
- Size: 241.1 kB
- Tags: CPython 3.12, macOS 11.0+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2d9222092e5ad8cc0b952b9e35e1d2abc6d5755b8d44d33b03eb6a5a59f4990 |
|
MD5 | e914dfec98a2354cd71f8a5befd48a29 |
|
BLAKE2b-256 | f32cbb2b6e709119b47cc8d4d3c9c71c61a8169a5188dfd82692ffc3d11754fe |
Provenance
The following attestation bundles were made for deglib-0.1.0-cp312-cp312-macosx_11_0_x86_64.whl
:
Publisher:
BuildAndPublish.yml
on Visual-Computing/DynamicExplorationGraph
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
deglib-0.1.0-cp312-cp312-macosx_11_0_x86_64.whl
- Subject digest:
c2d9222092e5ad8cc0b952b9e35e1d2abc6d5755b8d44d33b03eb6a5a59f4990
- Sigstore transparency entry: 145605633
- Sigstore integration time:
- Predicate type:
File details
Details for the file deglib-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
.
File metadata
- Download URL: deglib-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 216.9 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a52968fa5df264e3bb68cd8b7330abbb0e3f671b2698e40c2df80a5b80c837a1 |
|
MD5 | f3a6753ae5a88a232ca44f201e0837df |
|
BLAKE2b-256 | 5fe2a84d18a960b88a999873011ffc1d8c6bcc5956537bbb180b833711934e0d |
Provenance
The following attestation bundles were made for deglib-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
:
Publisher:
BuildAndPublish.yml
on Visual-Computing/DynamicExplorationGraph
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
deglib-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
- Subject digest:
a52968fa5df264e3bb68cd8b7330abbb0e3f671b2698e40c2df80a5b80c837a1
- Sigstore transparency entry: 145605639
- Sigstore integration time:
- Predicate type:
File details
Details for the file deglib-0.1.0-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: deglib-0.1.0-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 241.8 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fdfea0c8d0ea85c97dd79167b3f19143e2e7030dadcda09b9607a8cac222d20a |
|
MD5 | 03d465019ee665c2cc057c520b7a65e9 |
|
BLAKE2b-256 | dfd6c4504a6726a2c5a9f9572039fcbb283b269763ee22cb1f42973e2c963617 |
Provenance
The following attestation bundles were made for deglib-0.1.0-cp311-cp311-win_amd64.whl
:
Publisher:
BuildAndPublish.yml
on Visual-Computing/DynamicExplorationGraph
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
deglib-0.1.0-cp311-cp311-win_amd64.whl
- Subject digest:
fdfea0c8d0ea85c97dd79167b3f19143e2e7030dadcda09b9607a8cac222d20a
- Sigstore transparency entry: 145605636
- Sigstore integration time:
- Predicate type:
File details
Details for the file deglib-0.1.0-cp311-cp311-musllinux_1_2_x86_64.whl
.
File metadata
- Download URL: deglib-0.1.0-cp311-cp311-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.11, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f2412225aede61cb90665ef110d6068606221dae52bb76bc9b7aef9e67b901d |
|
MD5 | 0e0b8d3d1fce1764a7ff20531efcd334 |
|
BLAKE2b-256 | 3bd4ef056580a263457b8338c515997a687cf76d156f4e89162291e0b25f4b17 |
Provenance
The following attestation bundles were made for deglib-0.1.0-cp311-cp311-musllinux_1_2_x86_64.whl
:
Publisher:
BuildAndPublish.yml
on Visual-Computing/DynamicExplorationGraph
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
deglib-0.1.0-cp311-cp311-musllinux_1_2_x86_64.whl
- Subject digest:
0f2412225aede61cb90665ef110d6068606221dae52bb76bc9b7aef9e67b901d
- Sigstore transparency entry: 145605648
- Sigstore integration time:
- Predicate type:
File details
Details for the file deglib-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: deglib-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 469.0 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7950649e81d371b0a45fd6af89fddd687e6a042496cb177959209fa740c59d55 |
|
MD5 | 09ecf7829fac4ee7d68c4f2e2a5217c4 |
|
BLAKE2b-256 | d2c7b14d82993ef875f438b96ae8d9cf2e14218bc549fcbc025ce93295f91e92 |
Provenance
The following attestation bundles were made for deglib-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
:
Publisher:
BuildAndPublish.yml
on Visual-Computing/DynamicExplorationGraph
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
deglib-0.1.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
- Subject digest:
7950649e81d371b0a45fd6af89fddd687e6a042496cb177959209fa740c59d55
- Sigstore transparency entry: 145605647
- Sigstore integration time:
- Predicate type:
File details
Details for the file deglib-0.1.0-cp311-cp311-macosx_11_0_x86_64.whl
.
File metadata
- Download URL: deglib-0.1.0-cp311-cp311-macosx_11_0_x86_64.whl
- Upload date:
- Size: 239.4 kB
- Tags: CPython 3.11, macOS 11.0+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6efb8353d7aa97fc9c31ba68a69f7ff5788efa8b138a9a9d29f332303b493ffd |
|
MD5 | 0bfd0da5311b90620f9ef3122cc4a090 |
|
BLAKE2b-256 | 98c9cbc122859e87aeefb4457361d2368715379983be20db11a12e7074409423 |
Provenance
The following attestation bundles were made for deglib-0.1.0-cp311-cp311-macosx_11_0_x86_64.whl
:
Publisher:
BuildAndPublish.yml
on Visual-Computing/DynamicExplorationGraph
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
deglib-0.1.0-cp311-cp311-macosx_11_0_x86_64.whl
- Subject digest:
6efb8353d7aa97fc9c31ba68a69f7ff5788efa8b138a9a9d29f332303b493ffd
- Sigstore transparency entry: 145605641
- Sigstore integration time:
- Predicate type:
File details
Details for the file deglib-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
.
File metadata
- Download URL: deglib-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 216.2 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1a31fd86b806ba3ac46e6cf58a6455e51a49b48eb40b12c8972577121d665be |
|
MD5 | bc184715d8c410259e41816c7be4782a |
|
BLAKE2b-256 | 4e36c738c5d198701d63245b3c57590c4c2bd595d322ec1f18671146b785cb6f |
Provenance
The following attestation bundles were made for deglib-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
:
Publisher:
BuildAndPublish.yml
on Visual-Computing/DynamicExplorationGraph
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
deglib-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
- Subject digest:
c1a31fd86b806ba3ac46e6cf58a6455e51a49b48eb40b12c8972577121d665be
- Sigstore transparency entry: 145605635
- Sigstore integration time:
- Predicate type: