usearch 0.1.7 → 0.1.8

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.
package/Cargo.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "usearch"
3
- version = "0.1.7"
3
+ version = "0.1.8"
4
4
  authors = ["Ashot Vardanian <1983160+ashvardanian@users.noreply.github.com>"]
5
5
  description = "The Mighty Tiny Vector Search Engine with Automatic Quantization and Hardware Acceleration"
6
6
  edition = "2021"
package/README.md CHANGED
@@ -44,33 +44,86 @@ Compact, yet Powerful<br/>
44
44
 
45
45
  ## Usage
46
46
 
47
+ There are two usage patters:
48
+
49
+ - Bare-bones with `usearch/usearch.hpp`, only available in C++.
50
+ - Full-fat version with it's own threads, mutexes, type-punning, quantization, that is available both in C++ and is wrapped for higher-level bindings.
51
+
47
52
  ### C++
48
53
 
49
54
  To use in a C++ project simply copy the `include/usearch/usearch.hpp` header into your project.
55
+ Alternatively fetch it with CMake:
56
+
57
+ ```cmake
58
+ FetchContent_Declare(usearch GIT_REPOSITORY https://github.com/unum-cloud/usearch.git)
59
+ FetchContent_MakeAvailable(usearch)
60
+ ```
61
+
62
+ The simple usage example would require including the `unum::usearch` namespace and choosing the right "distance" function.
63
+ That can be one of the following templates:
64
+
65
+ - `cos_gt<float>` for "Cosine" or "Angular" distance.
66
+ - `ip_gt<float>` for "Inner Product" or "Dot Product" distance.
67
+ - `l2_squared_gt<float>` for the squared "L2" or "Euclidean" distance.
68
+ - `jaccard_gt<int>` for "Jaccard" distance between two ordered sets of unique elements.
69
+ - `bit_hamming_gt<uint>` for "Hamming" distance, as the number of shared bits in hashes.
70
+ - `pearson_correlation_gt<float>` for "Pearson" correlation between probability distributions.
71
+ - `haversine_gt<float>` for "Haversine" or "Great Circle" distance between coordinates.
72
+
73
+ That list is easily extendible, and can include similarity measures for vectors that have a different number of elements/dimensions.
74
+ The minimal example would be.
50
75
 
51
76
  ```c++
52
77
  using namespace unum::usearch;
53
78
 
54
79
  index_gt<cos_gt<float>> index;
55
80
  float vec[3] = {0.1, 0.3, 0.2};
81
+
82
+ index.reserve(10);
56
83
  index.add(/* label: */ 42, /* vector: */ {&vec, 3});
57
84
  index.search(
58
- /* query: */ {&vec, 3}, 10 /* results */,
59
- /* callback: */ [](std::size_t label, float distance) { });
85
+ /* query: */ {&vec, 3}, /* top */ 5 /* results */,
86
+ /* with callback: */ [](std::size_t label, float distance) { });
60
87
 
61
88
  index.save("index.usearch"); // Serializing to disk
62
89
  index.load("index.usearch"); // Reconstructing from disk
63
90
  index.view("index.usearch"); // Memory-mapping from disk
64
91
  ```
65
92
 
66
- Alternatively fetch it with CMake:
93
+ The `add` is thread-safe for concurrent index construction.
67
94
 
68
- ```cmake
69
- FetchContent_Declare(usearch GIT_REPOSITORY https://github.com/unum-cloud/usearch.git)
70
- FetchContent_MakeAvailable(usearch)
71
- ```
95
+ ### Python
96
+
97
+ Python bindings are implemented with [`pybind/pybind11`](https://github.com/pybind/pybind11).
98
+ Assuming the presence of Global Interpreter Lock in Python, on large insertions we spawn threads in the C++ layer.
72
99
 
100
+ ```sh
101
+ $ pip install usearch
73
102
 
103
+ import numpy as np
104
+ import usearch
105
+
106
+ index = usearch.Index(
107
+ dim=256, # Define the number of dimensions in input vectors
108
+ metric='cos', # Choose the "metric" or "distance", default = 'ip', optional
109
+ dtype='f16', # Quantize to 'f16' or 'i8q100' if needed, default = 'f32', optional
110
+ connectivity=16, # How frequent should the connections in the graph be, optional
111
+ expansion_add=128, # Control the recall of indexing, optional
112
+ expansion_search=64, # Control the quality of search, optional
113
+ )
114
+
115
+ n = 100
116
+ labels = np.array(range(n), dtype=np.longlong)
117
+ vectors = np.random.uniform(0, 0.3, (n, index.ndim)).astype(np.float32)
118
+
119
+ # You can avoid copying the data
120
+ # Handy when build 1B+ indexes of memory-mapped files
121
+ index.add(labels, vectors, copy=True)
122
+ assert len(index) == n
123
+
124
+ # You can search a batch at once
125
+ matches, distances, counts = index.search(vectors, 10)
126
+ ```
74
127
 
75
128
  ## Features
76
129
 
@@ -78,7 +131,6 @@ FetchContent_MakeAvailable(usearch)
78
131
 
79
132
  ## Performance
80
133
 
81
-
82
134
  ## TODO
83
135
 
84
136
  - JavaScript: Allow calling from "worker threads".
package/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.7
1
+ 0.1.8
@@ -19,7 +19,7 @@ public class IndexTest {
19
19
  public void test() {
20
20
  String path = "./tmp/";
21
21
  deleteDirectoryFiles(path);
22
- new Index("cos", "f32", 1, 10, 1, 1, 1);
22
+ // new Index("cos", "f32", 1, 10, 1, 1, 1);
23
23
  System.out.println("Java Tests Passed!");
24
24
  }
25
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "usearch",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "The Mighty Tiny Vector Search Engine with Automatic Quantization and Hardware Acceleration",
5
5
  "author": "Ashot Vardanian",
6
6
  "license": "Apache 2.0",
package/python/lib.cpp CHANGED
@@ -198,6 +198,12 @@ PYBIND11_MODULE(usearch, m) {
198
198
  py::arg("count") = 10 //
199
199
  );
200
200
 
201
+ i.def("__len__", &native_index_t::size);
202
+ i.def_property_readonly("size", &native_index_t::size);
203
+ i.def_property_readonly("ndim", &native_index_t::dimensions);
204
+ i.def_property_readonly("connectivity", &native_index_t::connectivity);
205
+ i.def_property_readonly("capacity", &native_index_t::capacity);
206
+
201
207
  i.def("save", &save_index, py::arg("path"));
202
208
  i.def("load", &load_index, py::arg("path"));
203
209
  i.def("view", &view_index, py::arg("path"));