Skip to content

Commit

Permalink
Docs: TypeScript docs factual errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ashvardanian committed Jul 30, 2023
1 parent 02b23f0 commit fe8103c
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 71 deletions.
4 changes: 2 additions & 2 deletions javascript/lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ void Index::Add(Napi::CallbackInfo const& ctx) {
if (ctx.Length() < 2 || !ctx[0].IsNumber() || !ctx[1].IsTypedArray())
return Napi::TypeError::New(env, "Expects an integral key and a float vector").ThrowAsJavaScriptException();

Napi::Number label_js = ctx[0].As<Napi::Number>();
Napi::Number key_js = ctx[0].As<Napi::Number>();
Napi::Float32Array vector_js = ctx[1].As<Napi::Float32Array>();

using key_t = typename index_dense_t::key_t;
key_t key = label_js.Uint32Value();
key_t key = key_js.Uint32Value();
float const* vector = vector_js.Data();
std::size_t dimensions = static_cast<std::size_t>(vector_js.ElementLength());
if (dimensions != native_->dimensions())
Expand Down
87 changes: 87 additions & 0 deletions javascript/usearch.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@

/** Search result object. */
export interface SearchResults {
/** The labels of the nearest neighbors found, size n*k. */
labels: BigUint64Array,
/** The disances of the nearest negihbors found, size n*k. */
distances: Float32Array,
/** The disances of the nearest negihbors found, size n*k. */
count: number
}

/** K-Approximate Nearest Neighbors search index. */
export class Index {

/**
* Constructs a new index.
*
* @param {number} dimensions
* @param {string} metric
* @param {string} quantization
* @param {number} capacity
* @param {number} connectivity
* @param {number} expansion_add
* @param {number} expansion_search
*/
constructor(...args);

/**
* Returns the dimensionality of vectors.
* @return {number} The dimensionality of vectors.
*/
dimensions(): number;

/**
* Returns the number of vectors currently indexed.
* @return {number} The number of vectors currently indexed.
*/
size(): number;

/**
* Returns index capacity.
* @return {numbers} The capacity of index.
*/
capacity(): number;

/**
* Returns connectivity.
* @return {number} The connectivity of index.
*/
connectivity(): number;

/**
* Write index to a file.
* @param {string} path File path to write.
*/
save(path: string): void;

/**
* Load index from a file.
* @param {string} path File path to read.
*/
load(path: string): void;

/**
* View index from a file, without loading into RAM.
* @param {string} path File path to read.
*/
load(path: string): void;

/**
* Add n vectors of dimension d to the index.
*
* @param {BigUint64Array} keys Input identifiers for every vector.
* @param {Float32Array} mat Input matrix, matrix of size n * d.
*/
add(keys: BigUint64Array, mat: Float32Array): void;

/**
* Query n vectors of dimension d to the index. Return at most k vectors for each.
* If there are not enough results for a query, the result array is padded with -1s.
*
* @param {Float32Array} mat Input vectors to search, matrix of size n * d.
* @param {number} k The number of nearest neighbors to search for.
* @return {SearchResults} Output of the search result.
*/
search(mat: Float32Array, k: number): SearchResults;
}
69 changes: 0 additions & 69 deletions usearch.d.ts

This file was deleted.

0 comments on commit fe8103c

Please sign in to comment.