deglib 0.3.0__tar.gz → 0.3.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {deglib-0.3.0 → deglib-0.3.1}/CMakeLists.txt +12 -3
- {deglib-0.3.0/src/deglib.egg-info → deglib-0.3.1}/PKG-INFO +47 -28
- {deglib-0.3.0 → deglib-0.3.1}/README.md +46 -27
- {deglib-0.3.0 → deglib-0.3.1}/lib/bench/include/benchmark.h +10 -13
- {deglib-0.3.0 → deglib-0.3.1}/lib/bench/include/dataset.h +13 -15
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/builder.h +11 -11
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/deglib.h +1 -17
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/distance/evp_ip.h +144 -31
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/distance/fp16_ip.h +134 -39
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/distance/fp16_l2.h +158 -46
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/distance/fp32_ip.h +130 -38
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/distance/fp32_l2.h +153 -41
- deglib-0.3.1/lib/deglib/include/deglib/distance/int4_ip.h +198 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/distance/int4_l2.h +58 -83
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/distance/int8_ip.h +41 -108
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/distance/int8_l2.h +38 -228
- deglib-0.3.1/lib/deglib/include/deglib/distance/tail_mask.h +123 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/distance/uint4_ip.h +51 -73
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/distance/uint4_l2.h +57 -66
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/distance/uint7_ip.h +33 -52
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/distance/uint7_l2.h +35 -54
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/distance/uint8_ip.h +43 -112
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/distance/uint8_l2.h +20 -26
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/distances.h +184 -136
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/graph/dynamic_graph.h +202 -115
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/graph/internal_graph.h +578 -434
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/graph/readonly_graph.h +115 -69
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/graph/sizebounded_graph.h +206 -132
- deglib-0.3.1/lib/deglib/include/deglib/graph.h +1364 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/optimization/flas/fast_linear_assignment_sorter.h +119 -50
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/optimization/flas/fast_linear_assignment_sorter_mt.h +78 -7
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/optimization.h +21 -10
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/search/kmeans.h +51 -79
- deglib-0.3.1/lib/deglib/include/deglib/search/pareto_line.h +690 -0
- deglib-0.3.1/lib/deglib/include/deglib/search/recall_table.h +968 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/search/reranker.h +256 -148
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/search/result_list.h +47 -25
- deglib-0.3.1/lib/deglib/include/deglib/search/searcher.h +1515 -0
- deglib-0.3.1/lib/deglib/include/deglib/search.h +18 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/transformation/mips.h +24 -12
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/transformation/scalar/common.h +24 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/transformation/scalar/int4.h +88 -10
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/transformation/scalar/int8.h +74 -2
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/transformation/scalar/uint4.h +83 -3
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/transformation/scalar/uint7.h +98 -22
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/transformation/scalar/uint8.h +82 -2
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/transformation.h +64 -49
- deglib-0.3.1/lib/deglib/include/deglib/tuning.h +1212 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/test/CMakeLists.txt +3 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/test/src/common/test_helpers.h +13 -25
- {deglib-0.3.0 → deglib-0.3.1}/pyproject.toml +1 -1
- {deglib-0.3.0 → deglib-0.3.1}/setup.py +4 -4
- deglib-0.3.1/src/deg_cpp/bindings_distances.cpp +191 -0
- deglib-0.3.1/src/deg_cpp/bindings_graph.cpp +865 -0
- deglib-0.3.1/src/deg_cpp/bindings_optimization.cpp +35 -0
- deglib-0.3.1/src/deg_cpp/bindings_search.cpp +571 -0
- deglib-0.3.1/src/deg_cpp/bindings_transformation.cpp +749 -0
- deglib-0.3.1/src/deg_cpp/bindings_tuning.cpp +196 -0
- deglib-0.3.1/src/deg_cpp/deglib_cpp.cpp +16 -0
- deglib-0.3.1/src/deglib/__init__.py +45 -0
- {deglib-0.3.0 → deglib-0.3.1}/src/deglib/builder.py +221 -75
- {deglib-0.3.0 → deglib-0.3.1}/src/deglib/distances.py +8 -8
- deglib-0.3.1/src/deglib/graph.py +1161 -0
- {deglib-0.3.0 → deglib-0.3.1}/src/deglib/optimization.py +47 -13
- deglib-0.3.1/src/deglib/search.py +908 -0
- {deglib-0.3.0 → deglib-0.3.1}/src/deglib/transformation.py +48 -0
- deglib-0.3.1/src/deglib/tuning.py +244 -0
- {deglib-0.3.0 → deglib-0.3.1/src/deglib.egg-info}/PKG-INFO +47 -28
- {deglib-0.3.0 → deglib-0.3.1}/src/deglib.egg-info/SOURCES.txt +16 -1
- {deglib-0.3.0 → deglib-0.3.1}/tests/test_builder.py +53 -49
- deglib-0.3.1/tests/test_deglib.py +608 -0
- {deglib-0.3.0 → deglib-0.3.1}/tests/test_distances.py +2 -1
- {deglib-0.3.0 → deglib-0.3.1}/tests/test_filter.py +4 -3
- {deglib-0.3.0 → deglib-0.3.1}/tests/test_graph.py +265 -124
- {deglib-0.3.0 → deglib-0.3.1}/tests/test_l2_normalize.py +3 -3
- deglib-0.3.1/tests/test_pareto_line.py +225 -0
- {deglib-0.3.0 → deglib-0.3.1}/tests/test_presort.py +1 -3
- deglib-0.3.1/tests/test_recall_table.py +249 -0
- {deglib-0.3.0 → deglib-0.3.1}/tests/test_rerank.py +53 -14
- {deglib-0.3.0 → deglib-0.3.1}/tests/test_rotation_transform.py +34 -35
- {deglib-0.3.0 → deglib-0.3.1}/tests/test_scalar_quantizer.py +3 -3
- deglib-0.3.1/tests/test_searcher.py +700 -0
- {deglib-0.3.0 → deglib-0.3.1}/tests/test_transformation.py +3 -3
- {deglib-0.3.0 → deglib-0.3.1}/tests/test_transformation_graph.py +68 -40
- deglib-0.3.1/tests/test_tuning.py +314 -0
- deglib-0.3.0/lib/deglib/include/deglib/distance/int4_ip.h +0 -241
- deglib-0.3.0/lib/deglib/include/deglib/graph.h +0 -1393
- deglib-0.3.0/lib/deglib/include/deglib/search/searcher.h +0 -925
- deglib-0.3.0/lib/deglib/include/deglib/search.h +0 -14
- deglib-0.3.0/src/deg_cpp/deglib_cpp.cpp +0 -2661
- deglib-0.3.0/src/deglib/__init__.py +0 -125
- deglib-0.3.0/src/deglib/graph.py +0 -799
- deglib-0.3.0/src/deglib/search.py +0 -396
- deglib-0.3.0/tests/test_searcher.py +0 -477
- {deglib-0.3.0 → deglib-0.3.1}/LICENSE +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/MANIFEST.in +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/CMakeLists.txt +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/bench/CMakeLists.txt +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/bench/include/build.h +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/bench/include/file_io.h +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/bench/include/logging.h +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/bench/include/repository.h +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/bench/include/stopwatch.h +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/cmake_modules/DetectCPUFeatures.cmake +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/CMakeLists.txt +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/analysis.h +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/concurrent.h +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/config.h +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/distance/fp16.h +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/distance/fp32.h +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/distance/int4.h +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/distance/int8.h +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/distance/residual_mode.h +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/distance/uint4.h +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/distance/uint8.h +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/filter.h +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/graph/intrusive_list.h +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/graph/mutable_graph.h +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/graph/visited_list_pool.h +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/optimization/flas/junker_volgenant_solver.h +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/optimization/pruning.h +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/serialization.h +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/transformation/evp.h +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/transformation/normalize.h +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/transformation/rotation.h +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/transformation/scalar/fp16.h +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/utils/cpu.h +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/utils/memory.h +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/deglib/include/deglib/utils/random.h +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/lib/test/src/unit/graph/test_dynamic_graph_common.h +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/setup.cfg +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/src/deglib/analysis.py +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/src/deglib/cpu.py +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/src/deglib/utils.py +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/src/deglib.egg-info/dependency_links.txt +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/src/deglib.egg-info/requires.txt +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/src/deglib.egg-info/top_level.txt +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/tests/test_analysis.py +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/tests/test_cpu.py +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/tests/test_evp_quantizer.py +0 -0
- {deglib-0.3.0 → deglib-0.3.1}/tests/test_scalar_quantizer_int4.py +0 -0
|
@@ -8,8 +8,8 @@ if(DEFINED PYTHON_EXECUTABLE)
|
|
|
8
8
|
endif()
|
|
9
9
|
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
|
|
10
10
|
|
|
11
|
-
# Add
|
|
12
|
-
find_package(
|
|
11
|
+
# Add nanobind
|
|
12
|
+
find_package(nanobind CONFIG REQUIRED)
|
|
13
13
|
|
|
14
14
|
# disable benchmark and test building
|
|
15
15
|
set(ENABLE_BENCHMARKS OFF CACHE BOOL "Disable benchmarks" FORCE)
|
|
@@ -26,7 +26,16 @@ endif()
|
|
|
26
26
|
|
|
27
27
|
# Add cpp-deglib
|
|
28
28
|
add_subdirectory(${DEGLIB_CPP_DIR} deglib_cpp_build)
|
|
29
|
-
|
|
29
|
+
nanobind_add_module(
|
|
30
|
+
deglib_cpp NOMINSIZE
|
|
31
|
+
src/deg_cpp/deglib_cpp.cpp
|
|
32
|
+
src/deg_cpp/bindings_distances.cpp
|
|
33
|
+
src/deg_cpp/bindings_optimization.cpp
|
|
34
|
+
src/deg_cpp/bindings_transformation.cpp
|
|
35
|
+
src/deg_cpp/bindings_search.cpp
|
|
36
|
+
src/deg_cpp/bindings_graph.cpp
|
|
37
|
+
src/deg_cpp/bindings_tuning.cpp
|
|
38
|
+
)
|
|
30
39
|
|
|
31
40
|
# Specify the include directories
|
|
32
41
|
include_directories(${DEGLIB_CPP_DIR}/deglib/include)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: deglib
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Summary: Python bindings for the Dynamic Exploration Graph library by Nico Hezel
|
|
5
5
|
Author: Nico Hezel
|
|
6
6
|
Author-email: Bruno Schilling <bruno.schilling@htw-berlin.de>
|
|
@@ -69,13 +69,25 @@ To build and install the package directly from the repository:
|
|
|
69
69
|
```bash
|
|
70
70
|
cd python/
|
|
71
71
|
uv venv
|
|
72
|
-
uv pip install setuptools==83.0.0
|
|
72
|
+
uv pip install setuptools==83.0.0 nanobind==3.1.0 build==1.5.0 wheel==0.48.0
|
|
73
73
|
uv run python setup.py copy_build_files
|
|
74
74
|
uv pip install . --no-build-isolation
|
|
75
75
|
```
|
|
76
76
|
|
|
77
77
|
---
|
|
78
78
|
|
|
79
|
+
See [python/API.md](API.md) for the full API reference and [docs/python_metric_quantization_matrix.md](../docs/python_metric_quantization_matrix.md) for the complete metric/quantization behavior matrix.
|
|
80
|
+
|
|
81
|
+
## API Layers: High-Level vs. Low-Level
|
|
82
|
+
|
|
83
|
+
Top-level `deglib` intentionally exports only the **High-Level API** and core result/config types:
|
|
84
|
+
- `deglib.build`, `deglib.presort`, `deglib.compress`, `deglib.reranker`, `deglib.reranker_with_data`, `deglib.searcher`, `deglib.load_graph`
|
|
85
|
+
- `deglib.DynamicExplorationGraph`, `deglib.Searcher`, `deglib.Reranker`, `deglib.SearchResults`, `deglib.Metric`, `deglib.OptimizationTarget`
|
|
86
|
+
|
|
87
|
+
All **Low-Level / Expert APIs** live in submodules (`deglib.graph.create_empty`, `deglib.builder.GraphBuilder`, `deglib.optimization.prune_non_mrng_edges`, `deglib.transformation.make_*`, `deglib.search.RecallTable`, `deglib.cpu.InstructionSet`, `deglib.analysis.analyze_graph`, `deglib.tuning.predict_*`).
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
79
91
|
## Quickstart & Examples
|
|
80
92
|
|
|
81
93
|
### Basic Usage
|
|
@@ -93,11 +105,12 @@ query = np.random.random(dims).astype(np.float32)
|
|
|
93
105
|
# 2. Build index directly from data (multithreaded & optimized by default)
|
|
94
106
|
graph = deglib.build(data, edges_per_vertex=32, show_progress=True)
|
|
95
107
|
|
|
96
|
-
# 3. Query top-k nearest neighbors
|
|
97
|
-
|
|
108
|
+
# 3. Query top-k nearest neighbors (returns SearchResults with zero-copy .indices/.distances and telemetry)
|
|
109
|
+
res = graph.search(query, k=10, eps_or_ef=0.1)
|
|
98
110
|
|
|
99
|
-
print("Nearest neighbors:", indices)
|
|
100
|
-
print("Distances:", distances)
|
|
111
|
+
print("Nearest neighbors:", res.indices)
|
|
112
|
+
print("Distances:", res.distances)
|
|
113
|
+
print("Distance evals:", res.graph_distance_count, "| Hops:", res.graph_hop_count)
|
|
101
114
|
```
|
|
102
115
|
|
|
103
116
|
---
|
|
@@ -108,12 +121,12 @@ All search graphs are represented by `DynamicExplorationGraph`, backed by one of
|
|
|
108
121
|
|
|
109
122
|
1. **Fixed-Capacity Mutable (`SizeBoundedGraph`)**: Memory is preallocated for a fixed maximum capacity. Fast and memory-efficient for static/batch datasets.
|
|
110
123
|
```python
|
|
111
|
-
graph = deglib.create_empty(capacity=10_000, dim=128, edges_per_vertex=32, metric=deglib.Metric.FP32_L2)
|
|
124
|
+
graph = deglib.graph.create_empty(capacity=10_000, dim=128, edges_per_vertex=32, metric=deglib.Metric.FP32_L2)
|
|
112
125
|
```
|
|
113
126
|
|
|
114
127
|
2. **Chunk-Allocated Mutable (`DynamicGraph`)**: Dynamically allocates memory in chunks (e.g. 1024 vertices per chunk). Ideal for streaming datasets where total capacity is unknown.
|
|
115
128
|
```python
|
|
116
|
-
graph = deglib.create_dynamic_empty(dim=128, edges_per_vertex=32, metric=deglib.Metric.FP32_L2, chunk_size=1024)
|
|
129
|
+
graph = deglib.graph.create_dynamic_empty(dim=128, edges_per_vertex=32, metric=deglib.Metric.FP32_L2, chunk_size=1024)
|
|
117
130
|
```
|
|
118
131
|
|
|
119
132
|
3. **Read-Only Deployment (`ReadOnlyGraph`)**: Stripped of mutation structures for minimal memory footprint and maximum query throughput.
|
|
@@ -130,13 +143,13 @@ All search graphs are represented by `DynamicExplorationGraph`, backed by one of
|
|
|
130
143
|
graph.save_graph("index.deg")
|
|
131
144
|
|
|
132
145
|
# Load as compact, optimized read-only graph for production search
|
|
133
|
-
readonly_graph = deglib.
|
|
146
|
+
readonly_graph = deglib.load_graph("index.deg")
|
|
134
147
|
|
|
135
148
|
# Load as dynamic graph supporting further insertions and deletions
|
|
136
|
-
dynamic_graph = deglib.load_dynamic_graph("index.deg")
|
|
149
|
+
dynamic_graph = deglib.graph.load_dynamic_graph("index.deg")
|
|
137
150
|
|
|
138
151
|
# Load as fixed-capacity mutable graph
|
|
139
|
-
mutable_graph = deglib.load_mutable_graph("index.deg")
|
|
152
|
+
mutable_graph = deglib.graph.load_mutable_graph("index.deg")
|
|
140
153
|
```
|
|
141
154
|
|
|
142
155
|
---
|
|
@@ -156,7 +169,7 @@ max_capacity = 10_000
|
|
|
156
169
|
edges_per_vertex = 32
|
|
157
170
|
|
|
158
171
|
# 1. Create empty mutable graph
|
|
159
|
-
graph = deglib.create_empty(max_capacity, dims, edges_per_vertex, metric=Metric.FP32_L2)
|
|
172
|
+
graph = deglib.graph.create_empty(max_capacity, dims, edges_per_vertex, metric=Metric.FP32_L2)
|
|
160
173
|
|
|
161
174
|
# 2. Initialize builder
|
|
162
175
|
builder = GraphBuilder(graph, optimization_target=OptimizationTarget.StreamingData, seed=42)
|
|
@@ -184,7 +197,8 @@ from deglib.search import Filter, rerank
|
|
|
184
197
|
allowed_ids = np.array([1, 5, 10, 42, 99], dtype=np.int32)
|
|
185
198
|
search_filter = Filter(allowed_ids)
|
|
186
199
|
|
|
187
|
-
|
|
200
|
+
res = graph.search(query, k=5, eps_or_ef=0.1, filter_labels=search_filter)
|
|
201
|
+
indices, distances = res.indices, res.distances
|
|
188
202
|
|
|
189
203
|
# Exact distance reranking across candidates
|
|
190
204
|
queries = np.random.random((10, dims)).astype(np.float32)
|
|
@@ -209,15 +223,17 @@ DEG supports exploratory search directly from existing vertex labels (single or
|
|
|
209
223
|
|
|
210
224
|
```python
|
|
211
225
|
# Explore graph starting from entry vertex label 105
|
|
212
|
-
|
|
226
|
+
exp_res = graph.explore(entry_external_label=105, k=10, eps_or_ef=0.1, include_entry=False)
|
|
227
|
+
explored_labels, distances = exp_res.indices, exp_res.distances
|
|
213
228
|
|
|
214
229
|
# Batch exploration from multiple entry vertices in parallel
|
|
215
230
|
batch_entries = np.array([105, 210, 315], dtype=np.uint32)
|
|
216
|
-
|
|
231
|
+
batch_exp = graph.explore(batch_entries, k=10, eps_or_ef=0.1, threads=4)
|
|
232
|
+
batch_labels, batch_distances = batch_exp.indices, batch_exp.distances
|
|
217
233
|
|
|
218
234
|
# Retrieve graph neighbors directly
|
|
219
235
|
neighbors = graph.get_neighbors(105)
|
|
220
|
-
batch_neighbors = graph.
|
|
236
|
+
batch_neighbors = graph.get_neighbors(batch_entries, threads=4) # shape: (3, edges_per_vertex)
|
|
221
237
|
```
|
|
222
238
|
|
|
223
239
|
---
|
|
@@ -237,23 +253,26 @@ query = np.random.randn(dims).astype(np.float32)
|
|
|
237
253
|
# 1. Pre-sort with FLAS and build exploration graph in FP32
|
|
238
254
|
graph = deglib.build(
|
|
239
255
|
data,
|
|
240
|
-
metric=
|
|
256
|
+
metric="cosine",
|
|
241
257
|
edges_per_vertex=32,
|
|
242
258
|
presort=True,
|
|
243
259
|
optimize=False,
|
|
244
260
|
show_progress=True,
|
|
245
261
|
)
|
|
246
262
|
|
|
247
|
-
# 2.
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
263
|
+
# 2. Extract FP16 reranker from FP32 graph and create compressed 8-bit Searcher
|
|
264
|
+
reranker = deglib.reranker(graph, compress="16bit")
|
|
265
|
+
searcher = deglib.searcher(
|
|
266
|
+
graph,
|
|
267
|
+
compress="8bit",
|
|
268
|
+
reranker=reranker,
|
|
251
269
|
)
|
|
252
270
|
|
|
253
271
|
# 3. Query search (query is automatically quantized and top candidates are reranked)
|
|
254
|
-
|
|
255
|
-
print("Top-10 nearest neighbor indices:", indices)
|
|
256
|
-
print("Top-10 exact distances:", distances)
|
|
272
|
+
res = searcher.search(query, k=10, eps_or_ef=0.1, rerank_factor=1.5, return_distances=True)
|
|
273
|
+
print("Top-10 nearest neighbor indices:", res.indices)
|
|
274
|
+
print("Top-10 exact distances:", res.distances)
|
|
275
|
+
print("Graph dists:", res.graph_distance_count, "| Rerank dists:", res.rerank_distance_count)
|
|
257
276
|
```
|
|
258
277
|
|
|
259
278
|
---
|
|
@@ -276,13 +295,13 @@ Controls the topology optimization strategy:
|
|
|
276
295
|
|
|
277
296
|
```python
|
|
278
297
|
# Mode 1: Relative distance margin (default: eps_or_ef=0.1)
|
|
279
|
-
|
|
298
|
+
res = searcher.search(query, k=10, eps_or_ef=0.1, return_distances=True)
|
|
280
299
|
|
|
281
300
|
# Mode 2: Fixed candidate pool (HNSW-style)
|
|
282
|
-
|
|
301
|
+
res_ef = searcher.search(query, k=10, eps_or_ef=128, return_distances=True)
|
|
283
302
|
|
|
284
303
|
# Optional: hard per-query budget of graph distance computations (0 = unlimited)
|
|
285
|
-
indices = searcher.search(query, k=10, eps_or_ef=128, max_distance_computation_count=700)
|
|
304
|
+
indices = searcher.search(query, k=10, eps_or_ef=128, max_distance_computation_count=700).indices
|
|
286
305
|
```
|
|
287
306
|
|
|
288
307
|
### Supported Metrics & Data Types
|
|
@@ -332,7 +351,7 @@ If you want to contribute, modify C++ bindings, run tests, or build release pack
|
|
|
332
351
|
# 1. Setup virtual environment and dependencies (using uv)
|
|
333
352
|
cd python/
|
|
334
353
|
uv venv
|
|
335
|
-
uv pip install setuptools==83.0.0
|
|
354
|
+
uv pip install setuptools==83.0.0 nanobind==3.1.0 build==1.5.0 wheel==0.48.0
|
|
336
355
|
uv run python setup.py copy_build_files
|
|
337
356
|
|
|
338
357
|
# 2. Install in editable mode
|
|
@@ -41,13 +41,25 @@ To build and install the package directly from the repository:
|
|
|
41
41
|
```bash
|
|
42
42
|
cd python/
|
|
43
43
|
uv venv
|
|
44
|
-
uv pip install setuptools==83.0.0
|
|
44
|
+
uv pip install setuptools==83.0.0 nanobind==3.1.0 build==1.5.0 wheel==0.48.0
|
|
45
45
|
uv run python setup.py copy_build_files
|
|
46
46
|
uv pip install . --no-build-isolation
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
---
|
|
50
50
|
|
|
51
|
+
See [python/API.md](API.md) for the full API reference and [docs/python_metric_quantization_matrix.md](../docs/python_metric_quantization_matrix.md) for the complete metric/quantization behavior matrix.
|
|
52
|
+
|
|
53
|
+
## API Layers: High-Level vs. Low-Level
|
|
54
|
+
|
|
55
|
+
Top-level `deglib` intentionally exports only the **High-Level API** and core result/config types:
|
|
56
|
+
- `deglib.build`, `deglib.presort`, `deglib.compress`, `deglib.reranker`, `deglib.reranker_with_data`, `deglib.searcher`, `deglib.load_graph`
|
|
57
|
+
- `deglib.DynamicExplorationGraph`, `deglib.Searcher`, `deglib.Reranker`, `deglib.SearchResults`, `deglib.Metric`, `deglib.OptimizationTarget`
|
|
58
|
+
|
|
59
|
+
All **Low-Level / Expert APIs** live in submodules (`deglib.graph.create_empty`, `deglib.builder.GraphBuilder`, `deglib.optimization.prune_non_mrng_edges`, `deglib.transformation.make_*`, `deglib.search.RecallTable`, `deglib.cpu.InstructionSet`, `deglib.analysis.analyze_graph`, `deglib.tuning.predict_*`).
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
51
63
|
## Quickstart & Examples
|
|
52
64
|
|
|
53
65
|
### Basic Usage
|
|
@@ -65,11 +77,12 @@ query = np.random.random(dims).astype(np.float32)
|
|
|
65
77
|
# 2. Build index directly from data (multithreaded & optimized by default)
|
|
66
78
|
graph = deglib.build(data, edges_per_vertex=32, show_progress=True)
|
|
67
79
|
|
|
68
|
-
# 3. Query top-k nearest neighbors
|
|
69
|
-
|
|
80
|
+
# 3. Query top-k nearest neighbors (returns SearchResults with zero-copy .indices/.distances and telemetry)
|
|
81
|
+
res = graph.search(query, k=10, eps_or_ef=0.1)
|
|
70
82
|
|
|
71
|
-
print("Nearest neighbors:", indices)
|
|
72
|
-
print("Distances:", distances)
|
|
83
|
+
print("Nearest neighbors:", res.indices)
|
|
84
|
+
print("Distances:", res.distances)
|
|
85
|
+
print("Distance evals:", res.graph_distance_count, "| Hops:", res.graph_hop_count)
|
|
73
86
|
```
|
|
74
87
|
|
|
75
88
|
---
|
|
@@ -80,12 +93,12 @@ All search graphs are represented by `DynamicExplorationGraph`, backed by one of
|
|
|
80
93
|
|
|
81
94
|
1. **Fixed-Capacity Mutable (`SizeBoundedGraph`)**: Memory is preallocated for a fixed maximum capacity. Fast and memory-efficient for static/batch datasets.
|
|
82
95
|
```python
|
|
83
|
-
graph = deglib.create_empty(capacity=10_000, dim=128, edges_per_vertex=32, metric=deglib.Metric.FP32_L2)
|
|
96
|
+
graph = deglib.graph.create_empty(capacity=10_000, dim=128, edges_per_vertex=32, metric=deglib.Metric.FP32_L2)
|
|
84
97
|
```
|
|
85
98
|
|
|
86
99
|
2. **Chunk-Allocated Mutable (`DynamicGraph`)**: Dynamically allocates memory in chunks (e.g. 1024 vertices per chunk). Ideal for streaming datasets where total capacity is unknown.
|
|
87
100
|
```python
|
|
88
|
-
graph = deglib.create_dynamic_empty(dim=128, edges_per_vertex=32, metric=deglib.Metric.FP32_L2, chunk_size=1024)
|
|
101
|
+
graph = deglib.graph.create_dynamic_empty(dim=128, edges_per_vertex=32, metric=deglib.Metric.FP32_L2, chunk_size=1024)
|
|
89
102
|
```
|
|
90
103
|
|
|
91
104
|
3. **Read-Only Deployment (`ReadOnlyGraph`)**: Stripped of mutation structures for minimal memory footprint and maximum query throughput.
|
|
@@ -102,13 +115,13 @@ All search graphs are represented by `DynamicExplorationGraph`, backed by one of
|
|
|
102
115
|
graph.save_graph("index.deg")
|
|
103
116
|
|
|
104
117
|
# Load as compact, optimized read-only graph for production search
|
|
105
|
-
readonly_graph = deglib.
|
|
118
|
+
readonly_graph = deglib.load_graph("index.deg")
|
|
106
119
|
|
|
107
120
|
# Load as dynamic graph supporting further insertions and deletions
|
|
108
|
-
dynamic_graph = deglib.load_dynamic_graph("index.deg")
|
|
121
|
+
dynamic_graph = deglib.graph.load_dynamic_graph("index.deg")
|
|
109
122
|
|
|
110
123
|
# Load as fixed-capacity mutable graph
|
|
111
|
-
mutable_graph = deglib.load_mutable_graph("index.deg")
|
|
124
|
+
mutable_graph = deglib.graph.load_mutable_graph("index.deg")
|
|
112
125
|
```
|
|
113
126
|
|
|
114
127
|
---
|
|
@@ -128,7 +141,7 @@ max_capacity = 10_000
|
|
|
128
141
|
edges_per_vertex = 32
|
|
129
142
|
|
|
130
143
|
# 1. Create empty mutable graph
|
|
131
|
-
graph = deglib.create_empty(max_capacity, dims, edges_per_vertex, metric=Metric.FP32_L2)
|
|
144
|
+
graph = deglib.graph.create_empty(max_capacity, dims, edges_per_vertex, metric=Metric.FP32_L2)
|
|
132
145
|
|
|
133
146
|
# 2. Initialize builder
|
|
134
147
|
builder = GraphBuilder(graph, optimization_target=OptimizationTarget.StreamingData, seed=42)
|
|
@@ -156,7 +169,8 @@ from deglib.search import Filter, rerank
|
|
|
156
169
|
allowed_ids = np.array([1, 5, 10, 42, 99], dtype=np.int32)
|
|
157
170
|
search_filter = Filter(allowed_ids)
|
|
158
171
|
|
|
159
|
-
|
|
172
|
+
res = graph.search(query, k=5, eps_or_ef=0.1, filter_labels=search_filter)
|
|
173
|
+
indices, distances = res.indices, res.distances
|
|
160
174
|
|
|
161
175
|
# Exact distance reranking across candidates
|
|
162
176
|
queries = np.random.random((10, dims)).astype(np.float32)
|
|
@@ -181,15 +195,17 @@ DEG supports exploratory search directly from existing vertex labels (single or
|
|
|
181
195
|
|
|
182
196
|
```python
|
|
183
197
|
# Explore graph starting from entry vertex label 105
|
|
184
|
-
|
|
198
|
+
exp_res = graph.explore(entry_external_label=105, k=10, eps_or_ef=0.1, include_entry=False)
|
|
199
|
+
explored_labels, distances = exp_res.indices, exp_res.distances
|
|
185
200
|
|
|
186
201
|
# Batch exploration from multiple entry vertices in parallel
|
|
187
202
|
batch_entries = np.array([105, 210, 315], dtype=np.uint32)
|
|
188
|
-
|
|
203
|
+
batch_exp = graph.explore(batch_entries, k=10, eps_or_ef=0.1, threads=4)
|
|
204
|
+
batch_labels, batch_distances = batch_exp.indices, batch_exp.distances
|
|
189
205
|
|
|
190
206
|
# Retrieve graph neighbors directly
|
|
191
207
|
neighbors = graph.get_neighbors(105)
|
|
192
|
-
batch_neighbors = graph.
|
|
208
|
+
batch_neighbors = graph.get_neighbors(batch_entries, threads=4) # shape: (3, edges_per_vertex)
|
|
193
209
|
```
|
|
194
210
|
|
|
195
211
|
---
|
|
@@ -209,23 +225,26 @@ query = np.random.randn(dims).astype(np.float32)
|
|
|
209
225
|
# 1. Pre-sort with FLAS and build exploration graph in FP32
|
|
210
226
|
graph = deglib.build(
|
|
211
227
|
data,
|
|
212
|
-
metric=
|
|
228
|
+
metric="cosine",
|
|
213
229
|
edges_per_vertex=32,
|
|
214
230
|
presort=True,
|
|
215
231
|
optimize=False,
|
|
216
232
|
show_progress=True,
|
|
217
233
|
)
|
|
218
234
|
|
|
219
|
-
# 2.
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
235
|
+
# 2. Extract FP16 reranker from FP32 graph and create compressed 8-bit Searcher
|
|
236
|
+
reranker = deglib.reranker(graph, compress="16bit")
|
|
237
|
+
searcher = deglib.searcher(
|
|
238
|
+
graph,
|
|
239
|
+
compress="8bit",
|
|
240
|
+
reranker=reranker,
|
|
223
241
|
)
|
|
224
242
|
|
|
225
243
|
# 3. Query search (query is automatically quantized and top candidates are reranked)
|
|
226
|
-
|
|
227
|
-
print("Top-10 nearest neighbor indices:", indices)
|
|
228
|
-
print("Top-10 exact distances:", distances)
|
|
244
|
+
res = searcher.search(query, k=10, eps_or_ef=0.1, rerank_factor=1.5, return_distances=True)
|
|
245
|
+
print("Top-10 nearest neighbor indices:", res.indices)
|
|
246
|
+
print("Top-10 exact distances:", res.distances)
|
|
247
|
+
print("Graph dists:", res.graph_distance_count, "| Rerank dists:", res.rerank_distance_count)
|
|
229
248
|
```
|
|
230
249
|
|
|
231
250
|
---
|
|
@@ -248,13 +267,13 @@ Controls the topology optimization strategy:
|
|
|
248
267
|
|
|
249
268
|
```python
|
|
250
269
|
# Mode 1: Relative distance margin (default: eps_or_ef=0.1)
|
|
251
|
-
|
|
270
|
+
res = searcher.search(query, k=10, eps_or_ef=0.1, return_distances=True)
|
|
252
271
|
|
|
253
272
|
# Mode 2: Fixed candidate pool (HNSW-style)
|
|
254
|
-
|
|
273
|
+
res_ef = searcher.search(query, k=10, eps_or_ef=128, return_distances=True)
|
|
255
274
|
|
|
256
275
|
# Optional: hard per-query budget of graph distance computations (0 = unlimited)
|
|
257
|
-
indices = searcher.search(query, k=10, eps_or_ef=128, max_distance_computation_count=700)
|
|
276
|
+
indices = searcher.search(query, k=10, eps_or_ef=128, max_distance_computation_count=700).indices
|
|
258
277
|
```
|
|
259
278
|
|
|
260
279
|
### Supported Metrics & Data Types
|
|
@@ -304,7 +323,7 @@ If you want to contribute, modify C++ bindings, run tests, or build release pack
|
|
|
304
323
|
# 1. Setup virtual environment and dependencies (using uv)
|
|
305
324
|
cd python/
|
|
306
325
|
uv venv
|
|
307
|
-
uv pip install setuptools==83.0.0
|
|
326
|
+
uv pip install setuptools==83.0.0 nanobind==3.1.0 build==1.5.0 wheel==0.48.0
|
|
308
327
|
uv run python setup.py copy_build_files
|
|
309
328
|
|
|
310
329
|
# 2. Install in editable mode
|
|
@@ -34,10 +34,7 @@ namespace deglib::benchmark {
|
|
|
34
34
|
* @param base_gt Optional contiguous BaseGroundTruth buffer
|
|
35
35
|
* @return GraphStats with all computed statistics
|
|
36
36
|
*/
|
|
37
|
-
inline deglib::analysis::GraphStats analyze_graph(
|
|
38
|
-
const deglib::graph::InternalGraph& graph,
|
|
39
|
-
const BaseGroundTruth& base_gt = {}
|
|
40
|
-
) {
|
|
37
|
+
inline deglib::analysis::GraphStats analyze_graph(const deglib::graph::InternalGraph& graph, const BaseGroundTruth& base_gt = {}) {
|
|
41
38
|
auto stats = deglib::analysis::analyze_graph(graph, base_gt.data(), base_gt.rows, base_gt.k);
|
|
42
39
|
|
|
43
40
|
log("Graph Statistics:\n");
|
|
@@ -133,11 +130,11 @@ static float test_approx_anns(
|
|
|
133
130
|
|
|
134
131
|
uint32_t correct = 0;
|
|
135
132
|
const auto& gt = ground_truth[i];
|
|
136
|
-
while (result_queue.empty() == false) {
|
|
137
|
-
const auto& result = result_queue.top();
|
|
133
|
+
while (result_queue.results.empty() == false) {
|
|
134
|
+
const auto& result = result_queue.results.top();
|
|
138
135
|
const auto external_id = graph.getExternalLabel(result.getIdentifier());
|
|
139
136
|
if (std::binary_search(gt.begin(), gt.end(), external_id)) correct++;
|
|
140
|
-
result_queue.pop();
|
|
137
|
+
result_queue.results.pop();
|
|
141
138
|
}
|
|
142
139
|
|
|
143
140
|
corrects[thread_id] += correct;
|
|
@@ -172,11 +169,11 @@ static float test_approx_explore(
|
|
|
172
169
|
|
|
173
170
|
uint32_t correct = 0;
|
|
174
171
|
const auto& gt = ground_truth[i];
|
|
175
|
-
while (result_queue.empty() == false) {
|
|
176
|
-
const auto& result = result_queue.top();
|
|
172
|
+
while (result_queue.results.empty() == false) {
|
|
173
|
+
const auto& result = result_queue.results.top();
|
|
177
174
|
const auto external_id = graph.getExternalLabel(result.getIdentifier());
|
|
178
175
|
if (std::binary_search(gt.begin(), gt.end(), external_id)) correct++;
|
|
179
|
-
result_queue.pop();
|
|
176
|
+
result_queue.results.pop();
|
|
180
177
|
}
|
|
181
178
|
|
|
182
179
|
corrects[thread_id] += correct;
|
|
@@ -212,11 +209,11 @@ static std::vector<float> estimate_recall(
|
|
|
212
209
|
total += result_queue.size();
|
|
213
210
|
|
|
214
211
|
size_t local_correct = 0;
|
|
215
|
-
while (result_queue.empty() == false) {
|
|
216
|
-
const auto internal_index = result_queue.top().getIdentifier();
|
|
212
|
+
while (result_queue.results.empty() == false) {
|
|
213
|
+
const auto internal_index = result_queue.results.top().getIdentifier();
|
|
217
214
|
const auto external_id = graph.getExternalLabel(internal_index);
|
|
218
215
|
if (std::binary_search(gt.begin(), gt.end(), external_id)) local_correct++;
|
|
219
|
-
result_queue.pop();
|
|
216
|
+
result_queue.results.pop();
|
|
220
217
|
}
|
|
221
218
|
correct += local_correct;
|
|
222
219
|
});
|
|
@@ -179,12 +179,8 @@ struct BaseGroundTruth {
|
|
|
179
179
|
size_t rows = 0;
|
|
180
180
|
size_t k = 0;
|
|
181
181
|
|
|
182
|
-
const uint32_t* data() const noexcept {
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
bool empty() const noexcept {
|
|
186
|
-
return !buffer || rows == 0 || k == 0;
|
|
187
|
-
}
|
|
182
|
+
const uint32_t* data() const noexcept { return reinterpret_cast<const uint32_t*>(buffer.get()); }
|
|
183
|
+
bool empty() const noexcept { return !buffer || rows == 0 || k == 0; }
|
|
188
184
|
};
|
|
189
185
|
|
|
190
186
|
class Dataset {
|
|
@@ -211,7 +207,8 @@ class Dataset {
|
|
|
211
207
|
std::string base_groundtruth_half_file() const { return (files_dir_ / info_.base_groundtruth_half_file).string(); }
|
|
212
208
|
|
|
213
209
|
std::string groundtruth_file(size_t nb) const {
|
|
214
|
-
return (files_dir_ / fmt::format("{}_groundtruth_top{}_nb{}_{}.ivecs", info_.name(), DatasetInfo::GROUNDTRUTH_TOPK, nb, info_.metric.to_string()))
|
|
210
|
+
return (files_dir_ / fmt::format("{}_groundtruth_top{}_nb{}_{}.ivecs", info_.name(), DatasetInfo::GROUNDTRUTH_TOPK, nb, info_.metric.to_string()))
|
|
211
|
+
.string();
|
|
215
212
|
}
|
|
216
213
|
std::string groundtruth_file_full() const { return groundtruth_file(info_.base_count); }
|
|
217
214
|
std::string groundtruth_file_half() const { return groundtruth_file(info_.base_count / 2); }
|
|
@@ -702,7 +699,7 @@ inline bool generate_base_groundtruth_files(
|
|
|
702
699
|
|
|
703
700
|
if (quality_mode == GraphQualityMode::Approximated && !graph_path.empty() && file_exists(graph_path)) {
|
|
704
701
|
fmt::print("Computing base ground truth (ANNS graph exploration) using {} -> {}\n", graph_path, out_file);
|
|
705
|
-
const auto graph = deglib::
|
|
702
|
+
const auto graph = deglib::DynamicExplorationGraph::load_readonly(graph_path.c_str());
|
|
706
703
|
const std::string tmp_file = out_file + ".tmp";
|
|
707
704
|
auto out = std::ofstream(tmp_file, std::ios::out | std::ios::binary);
|
|
708
705
|
if (!out.is_open()) {
|
|
@@ -722,12 +719,10 @@ inline bool generate_base_groundtruth_files(
|
|
|
722
719
|
std::fill(row, row + topk, (std::numeric_limits<uint32_t>::max)());
|
|
723
720
|
return;
|
|
724
721
|
}
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
row[j] = graph.getExternalLabel(result_queue.top().getIdentifier());
|
|
730
|
-
result_queue.pop();
|
|
722
|
+
auto result_queue = graph.explore(ext_label, topk, 0, 0.1f, /*include_entry=*/false);
|
|
723
|
+
for (uint32_t j = 0; j < topk; ++j) {
|
|
724
|
+
if (j < result_queue.indices.size()) {
|
|
725
|
+
row[j] = result_queue.indices[j];
|
|
731
726
|
} else {
|
|
732
727
|
row[j] = (std::numeric_limits<uint32_t>::max)();
|
|
733
728
|
}
|
|
@@ -749,7 +744,10 @@ inline bool generate_base_groundtruth_files(
|
|
|
749
744
|
return true;
|
|
750
745
|
}
|
|
751
746
|
|
|
752
|
-
fmt::print(
|
|
747
|
+
fmt::print(
|
|
748
|
+
"Computing base ground truth (linear search, metric: {}) -> {} (total: {} queries, base limit: {})...\n", info.metric.to_string(), out_file,
|
|
749
|
+
total_queries, base_limit
|
|
750
|
+
);
|
|
753
751
|
const std::string tmp_file = out_file + ".tmp";
|
|
754
752
|
auto out = std::ofstream(tmp_file, std::ios::out | std::ios::binary);
|
|
755
753
|
if (!out.is_open()) {
|
|
@@ -584,10 +584,10 @@ class EvenRegularGraphBuilder {
|
|
|
584
584
|
// find good neighbor candidates for the new vertex
|
|
585
585
|
auto distrib = deglib::random::DeterministicUniformIntDistribution<uint32_t>(0, uint32_t(graph.size() - 1));
|
|
586
586
|
const std::vector<uint32_t> entry_vertex_indices = {distrib(this->rnd_)};
|
|
587
|
-
auto
|
|
587
|
+
auto ws = graph.search_intern(
|
|
588
588
|
entry_vertex_indices, new_vertex_feature, std::max(uint32_t(this->extend_k_), edges_per_vertex * 2), this->extend_eps_
|
|
589
589
|
); // need 2x otherwise it might lock during neighbor selection
|
|
590
|
-
const auto candidates = topListAscending(
|
|
590
|
+
const auto candidates = topListAscending(ws.results);
|
|
591
591
|
|
|
592
592
|
// their should always be enough neighbors (search candidates), otherwise the graph would be broken
|
|
593
593
|
if (candidates.size() < edges_per_vertex) {
|
|
@@ -725,9 +725,9 @@ class EvenRegularGraphBuilder {
|
|
|
725
725
|
|
|
726
726
|
// find good neighbors for the new vertex
|
|
727
727
|
const auto entry_vertex_indices = graph.getEntryVertexIndices();
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
const auto results = topListAscending(
|
|
728
|
+
thread_local deglib::graph::SearchWorkspace ws;
|
|
729
|
+
graph.search_intern(ws, entry_vertex_indices, new_vertex_feature, std::max(uint32_t(this->extend_k_), edges_per_vertex), this->extend_eps_);
|
|
730
|
+
const auto results = topListAscending(ws.results);
|
|
731
731
|
|
|
732
732
|
// their should always be enough neighbors (search results), otherwise the graph would be broken
|
|
733
733
|
if (results.size() < edges_per_vertex) {
|
|
@@ -1231,8 +1231,8 @@ class EvenRegularGraphBuilder {
|
|
|
1231
1231
|
// their subgraph and would therefore connect the two potential subgraphs.
|
|
1232
1232
|
{
|
|
1233
1233
|
const auto vertex2_feature = graph.getFeatureVector(vertex2);
|
|
1234
|
-
const
|
|
1235
|
-
auto
|
|
1234
|
+
const uint32_t entry_vertex_indices[2] = {vertex3, vertex4};
|
|
1235
|
+
auto ws = graph.search_intern(entry_vertex_indices, vertex2_feature, improve_k_, this->improve_eps_);
|
|
1236
1236
|
|
|
1237
1237
|
// find a good new vertex3
|
|
1238
1238
|
float best_gain = total_gain;
|
|
@@ -1241,7 +1241,7 @@ class EvenRegularGraphBuilder {
|
|
|
1241
1241
|
|
|
1242
1242
|
// We use the descending order to find the worst swap combination with the best gain
|
|
1243
1243
|
// Sometimes the gain between the two best combinations is the same, its better to use one with the bad edges to make later improvements easier
|
|
1244
|
-
for (auto&& result : topListDescending(
|
|
1244
|
+
for (auto&& result : topListDescending(ws.results)) {
|
|
1245
1245
|
const uint32_t new_vertex3 = result.getIdentifier();
|
|
1246
1246
|
|
|
1247
1247
|
// vertex1 and vertex2 got tested in the recursive call before and vertex4 got just disconnected from vertex2
|
|
@@ -1302,9 +1302,9 @@ class EvenRegularGraphBuilder {
|
|
|
1302
1302
|
// two vertices are already connected to vertex4.
|
|
1303
1303
|
if (vertex1 == vertex4) {
|
|
1304
1304
|
// find a good (not yet connected) vertex for vertex1/vertex4
|
|
1305
|
-
const
|
|
1305
|
+
const uint32_t entry_vertex_indices[2] = {vertex2, vertex3};
|
|
1306
1306
|
const auto vertex4_feature = graph.getFeatureVector(vertex4);
|
|
1307
|
-
auto
|
|
1307
|
+
auto ws = graph.search_intern(entry_vertex_indices, vertex4_feature, improve_k_, this->improve_eps_);
|
|
1308
1308
|
|
|
1309
1309
|
float best_gain = 0;
|
|
1310
1310
|
uint32_t best_selected_neighbor = 0;
|
|
@@ -1312,7 +1312,7 @@ class EvenRegularGraphBuilder {
|
|
|
1312
1312
|
float best_new_neighbor_dist = 0;
|
|
1313
1313
|
uint32_t best_good_vertex = 0;
|
|
1314
1314
|
float best_good_vertex_dist = 0;
|
|
1315
|
-
for (auto&& result : topListAscending(
|
|
1315
|
+
for (auto&& result : topListAscending(ws.results)) {
|
|
1316
1316
|
const auto good_vertex = result.getIdentifier();
|
|
1317
1317
|
|
|
1318
1318
|
// the new vertex should not be connected to vertex4 yet
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
#include "deglib/search.h"
|
|
11
11
|
#include "deglib/search/searcher.h"
|
|
12
12
|
#include "deglib/transformation.h"
|
|
13
|
+
#include "deglib/tuning.h"
|
|
13
14
|
#include "deglib/utils/memory.h"
|
|
14
15
|
#include "deglib/utils/random.h"
|
|
15
16
|
|
|
@@ -109,21 +110,4 @@ inline DynamicExplorationGraph load_mutable_graph(const char* path_graph, const
|
|
|
109
110
|
return DynamicExplorationGraph::load_mutable(path_graph, new_max_size);
|
|
110
111
|
}
|
|
111
112
|
|
|
112
|
-
/**
|
|
113
|
-
* Create a high-performance Searcher over a DynamicExplorationGraph facade.
|
|
114
|
-
* Convenience overloads that forward to deglib::search::make_searcher using the graph's internal representation,
|
|
115
|
-
* so end users can pass the public graph type directly.
|
|
116
|
-
*/
|
|
117
|
-
inline std::unique_ptr<deglib::search::Searcher> make_searcher(const DynamicExplorationGraph& graph) {
|
|
118
|
-
return std::make_unique<deglib::search::Searcher>(graph.internal(), graph.getTransformations());
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
inline std::unique_ptr<deglib::search::Searcher> make_searcher(const DynamicExplorationGraph& graph, std::shared_ptr<deglib::search::Reranker> reranker) {
|
|
122
|
-
return std::make_unique<deglib::search::Searcher>(graph.internal(), graph.getTransformations(), std::move(reranker));
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
inline std::unique_ptr<deglib::search::Searcher> make_searcher(const DynamicExplorationGraph& graph, deglib::search::Reranker reranker) {
|
|
126
|
-
return std::make_unique<deglib::search::Searcher>(graph.internal(), graph.getTransformations(), std::move(reranker));
|
|
127
|
-
}
|
|
128
|
-
|
|
129
113
|
} // namespace deglib
|