-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #303
- v2.17.2
- v2.17.1
- v2.17.0
- v2.16.10
- v2.16.9
- v2.16.8
- v2.16.7
- v2.16.6
- v2.16.5
- v2.16.4
- v2.16.3
- v2.16.2
- v2.16.1
- v2.16.0
- v2.15.3
- v2.15.2
- v2.15.1
- v2.15.0
- v2.14.0
- v2.13.5
- v2.13.4
- v2.13.3
- v2.13.2
- v2.13.1
- v2.13.0
- v2.12.0
- v2.11.7
- v2.11.6
- v2.11.5
- v2.11.4
- v2.11.3
- v2.11.2
- v2.11.1
- v2.11.0
- v2.10.5
- v2.10.4
- v2.10.3
- v2.10.2
- v2.10.1
- v2.10.0
- v2.9.2
- v2.9.1
- v2.9.0
- v2.8.16
- v2.8.15
- v2.8.14
- v2.8.13
- v2.8.12
- v2.8.11
- v2.8.10
- v2.8.9
1 parent
cf1b58f
commit b761680
Showing
3 changed files
with
70 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,88 @@ | ||
# USearch for JavaScript | ||
|
||
USearch is a high-performance library for building and querying vector search indexes, optimized for Node.js and WASM environments. | ||
|
||
## Installation | ||
|
||
USearch is available both for Node.js backend runtime and WASM frontend runtime. | ||
For the first option, use the conventional `npm install`: | ||
For Node.js environments, install USearch using `npm`: | ||
|
||
```sh | ||
npm install usearch | ||
``` | ||
|
||
For latter: | ||
For front-end applications using WASM, use the Wasmer package manager: | ||
|
||
```sh | ||
wasmer install unum/usearch | ||
``` | ||
|
||
## Quickstart | ||
|
||
Create an index, add vectors, and perform searches with ease: | ||
|
||
```js | ||
var index = new usearch.Index({ metric: 'cos', connectivity: 16n, dimensions: 3n }) | ||
index.add(42n, new Float32Array([0.2, 0.6, 0.4])) | ||
var results = index.search(new Float32Array([0.2, 0.6, 0.4]), 10n) | ||
const usearch = require('usearch'); | ||
const index = new usearch.Index({ metric: 'cos', connectivity: 16, dimensions: 3 }); | ||
index.add(42n, new Float32Array([0.2, 0.6, 0.4])); | ||
const results = index.search(new Float32Array([0.2, 0.6, 0.4]), 10); | ||
|
||
assert(index.size() === 1); | ||
assert.deepEqual(results.keys, new BigUint64Array([42n])); | ||
assert.deepEqual(results.distances, new Float32Array([0])); | ||
|
||
assert.equal(index.size(), 1n) | ||
assert.deepEqual(results.keys, new BigUint64Array([42n])) | ||
assert.deepEqual(results.distances, new Float32Array([0])) | ||
index.remove(42n); | ||
``` | ||
|
||
## Serialization | ||
|
||
Persist and restore your index with serialization methods: | ||
|
||
```js | ||
index.save('index.usearch'); // Save the index to a file | ||
index.load('index.usearch'); // Load the index from a file | ||
index.view('index.usearch'); // View the index from a file without loading into memory | ||
``` | ||
|
||
## Advanced Index Configuration | ||
|
||
Customize your index with additional configuration options: | ||
|
||
```js | ||
const index = new usearch.Index({ | ||
dimensions: 128, | ||
metric: 'ip', | ||
quantization: 'f32', | ||
connectivity: 10, | ||
expansion_add: 5, | ||
expansion_search: 3, | ||
multi: true | ||
}); | ||
``` | ||
|
||
## Batch Operations | ||
|
||
Process multiple vectors at once for efficiency. | ||
For performance reasons we prefer a flattened `TypedArray` over an Array of Arrays: | ||
|
||
```js | ||
const keys = new BigUint64Array([15n, 16n]); | ||
const vectors = new Float32Array([10, 20, 10, 25]); | ||
index.add(keys, vectors); | ||
``` | ||
|
||
Retrieve batch search results: | ||
|
||
```js | ||
const batchResults = index.search(vectors, 2); | ||
const firstMatch = batchResults.get(0); | ||
``` | ||
|
||
## Index Introspection | ||
|
||
Inspect and interact with the index: | ||
|
||
```js | ||
index.save('index.usearch') | ||
index.load('index.usearch') | ||
index.view('index.usearch') | ||
const dimensions = index.dimensions(); // Get the number of dimensions | ||
const containsKey = index.contains(42n); // Check if a key is in the index | ||
const count = index.count(42n); // Get the count of vectors for a key | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters