faiss-node
Advanced tools
Comparing version 0.2.3 to 0.3.0
@@ -1,2 +0,2 @@ | ||
const { IndexFlatL2 } = require('faiss-node'); | ||
const { IndexFlatL2 } = require('../'); | ||
@@ -28,2 +28,6 @@ const dimension = 2; | ||
console.log(results1.labels); | ||
console.log(results1.distances); | ||
console.log(results1.distances); | ||
const newIndex = new IndexFlatL2(dimension); | ||
newIndex.mergeFrom(index); | ||
console.log(newIndex.ntotal()); |
@@ -58,2 +58,7 @@ /** Searh result object. */ | ||
static read(fname: string): IndexFlatL2; | ||
/** | ||
* Merge the current index with another IndexFlatL2 instance. | ||
* @param {IndexFlatL2} otherIndex The other IndexFlatL2 instance to merge from. | ||
*/ | ||
mergeFrom(otherIndex: IndexFlatL2): void; | ||
} |
{ | ||
"name": "faiss-node", | ||
"version": "0.2.3", | ||
"version": "0.3.0", | ||
"description": "Node.js bindings for faiss", | ||
@@ -26,3 +26,3 @@ "main": "lib/index.js", | ||
"test": "jest", | ||
"doc": "typedoc" | ||
"doc": "typedoc --includeVersion" | ||
}, | ||
@@ -29,0 +29,0 @@ "repository": { |
@@ -60,2 +60,7 @@ # faiss-node | ||
console.log(results1.distances); // [ 0, 1, 1, 4 ] | ||
// Merge index | ||
const newIndex = new IndexFlatL2(dimension); | ||
newIndex.mergeFrom(index); | ||
console.log(newIndex.ntotal()); // 4 | ||
``` | ||
@@ -62,0 +67,0 @@ |
@@ -136,2 +136,52 @@ const { IndexFlatL2 } = require('../lib'); | ||
}); | ||
describe("#merge", () => { | ||
const index1 = new IndexFlatL2(2); | ||
beforeAll(() => { | ||
index1.add([1, 0]); | ||
index1.add([1, 2]); | ||
index1.add([1, 3]); | ||
index1.add([1, 1]); | ||
}); | ||
const index2 = new IndexFlatL2(2); | ||
beforeAll(() => { | ||
index2.mergeFrom(index1); | ||
}); | ||
it("throws an error if the number of arguments is not 1", () => { | ||
expect(() => { index2.mergeFrom() }).toThrow('Expected 1 argument, but got 0.'); | ||
expect(() => { index2.mergeFrom(index1, 2) }).toThrow('Expected 1 argument, but got 2.'); | ||
}); | ||
it("throws an error if argument is not an object", () => { | ||
expect(() => { index2.mergeFrom(1) }).toThrow('Invalid argument type, must be an object.'); | ||
expect(() => { index2.mergeFrom("string") }).toThrow('Invalid argument type, must be an object.'); | ||
}); | ||
it("throws an error if argument is not an instance of IndexFlatL2", () => { | ||
expect(() => { index2.mergeFrom({}) }).toThrow('Invalid argument'); | ||
expect(() => { index2.mergeFrom({"foo": "bar"}) }).toThrow('Invalid argument'); | ||
}); | ||
it("throws an error if merging index has different dimensions", () => { | ||
const index3 = new IndexFlatL2(3); | ||
expect(() => { index2.mergeFrom(index3) }).toThrow('The merging index must have the same dimension.'); | ||
}); | ||
it("returns search results on merged index", () => { | ||
expect(index2.search([1, 0], 1)).toMatchObject({ | ||
distances: [0], | ||
labels: [0], | ||
}); | ||
expect(index2.search([1, 0], 4)).toMatchObject({ | ||
distances: [0, 1, 4, 9], | ||
labels: [0, 3, 1, 2], | ||
}); | ||
expect(index2.search([1, 1], 4)).toMatchObject({ | ||
distances: [0, 1, 1, 4], | ||
labels: [3, 0, 1, 2], | ||
}); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33860
255
69