@the-40-thieves/obsidian-tc-native 1.10.0 → 1.11.0
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/fallback.js +21 -2
- package/index.d.ts +3 -2
- package/obsidian-tc-native.darwin-arm64.node +0 -0
- package/obsidian-tc-native.darwin-x64.node +0 -0
- package/obsidian-tc-native.linux-arm64-gnu.node +0 -0
- package/obsidian-tc-native.linux-arm64-musl.node +0 -0
- package/obsidian-tc-native.linux-x64-gnu.node +0 -0
- package/obsidian-tc-native.linux-x64-musl.node +0 -0
- package/obsidian-tc-native.win32-arm64-msvc.node +0 -0
- package/obsidian-tc-native.win32-x64-msvc.node +0 -0
- package/package.json +9 -9
package/fallback.js
CHANGED
|
@@ -24,13 +24,32 @@ function cosineSimilarity(a, b) {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
/** Batched cosine: one query vs N concatenated f32 docs of length `dim`; scores in row order.
|
|
27
|
-
* Empty for a bad shape. Mirrors the Rust `cosine_batch`.
|
|
27
|
+
* Empty for a bad shape. Mirrors the Rust `cosine_batch`.
|
|
28
|
+
*
|
|
29
|
+
* THE-504: `query` is a Float32Array (was a plain array); its norm is computed once per batch,
|
|
30
|
+
* and each doc's dot product and norm are computed together in a single pass. */
|
|
28
31
|
function cosineBatch(query, docsFlat, dim) {
|
|
29
32
|
if (dim <= 0 || query.length !== dim || docsFlat.length % dim !== 0) return new Float64Array(0);
|
|
33
|
+
let normQ = 0;
|
|
34
|
+
for (let i = 0; i < dim; i++) {
|
|
35
|
+
const q = query[i] ?? 0;
|
|
36
|
+
normQ += q * q;
|
|
37
|
+
}
|
|
30
38
|
const n = docsFlat.length / dim;
|
|
31
39
|
const out = new Float64Array(n);
|
|
40
|
+
if (normQ === 0) return out;
|
|
41
|
+
const normQSqrt = Math.sqrt(normQ);
|
|
32
42
|
for (let i = 0; i < n; i++) {
|
|
33
|
-
|
|
43
|
+
const base = i * dim;
|
|
44
|
+
let dot = 0;
|
|
45
|
+
let normD = 0;
|
|
46
|
+
for (let j = 0; j < dim; j++) {
|
|
47
|
+
const q = query[j] ?? 0;
|
|
48
|
+
const d = docsFlat[base + j] ?? 0;
|
|
49
|
+
dot += q * d;
|
|
50
|
+
normD += d * d;
|
|
51
|
+
}
|
|
52
|
+
out[i] = normD === 0 ? 0 : dot / (normQSqrt * Math.sqrt(normD));
|
|
34
53
|
}
|
|
35
54
|
return out;
|
|
36
55
|
}
|
package/index.d.ts
CHANGED
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
export declare function cosineSimilarity(a: number[], b: Float32Array | number[]): number;
|
|
6
6
|
|
|
7
7
|
/** Batched cosine: one query vs N concatenated f32 docs of length `dim`; scores in row order
|
|
8
|
-
* (empty for a bad shape). One N-API crossing for a whole candidate set.
|
|
8
|
+
* (empty for a bad shape). One N-API crossing for a whole candidate set. THE-504: `query` is a
|
|
9
|
+
* `Float32Array` (was `number[]`), avoiding a `number[]` -> `Vec<f64>` conversion per call. */
|
|
9
10
|
export declare function cosineBatch(
|
|
10
|
-
query:
|
|
11
|
+
query: Float32Array,
|
|
11
12
|
docsFlat: Float32Array,
|
|
12
13
|
dim: number,
|
|
13
14
|
): Float64Array;
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@the-40-thieves/obsidian-tc-native",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"description": "Native perf module for obsidian-tc — vector ops, BM25, sqlite-vec, V2 clustering hooks",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"publishConfig": {
|
|
@@ -53,13 +53,13 @@
|
|
|
53
53
|
"./package.json": "./package.json"
|
|
54
54
|
},
|
|
55
55
|
"optionalDependencies": {
|
|
56
|
-
"@the-40-thieves/obsidian-tc-native-linux-x64-gnu": "1.
|
|
57
|
-
"@the-40-thieves/obsidian-tc-native-linux-arm64-gnu": "1.
|
|
58
|
-
"@the-40-thieves/obsidian-tc-native-linux-x64-musl": "1.
|
|
59
|
-
"@the-40-thieves/obsidian-tc-native-linux-arm64-musl": "1.
|
|
60
|
-
"@the-40-thieves/obsidian-tc-native-darwin-x64": "1.
|
|
61
|
-
"@the-40-thieves/obsidian-tc-native-darwin-arm64": "1.
|
|
62
|
-
"@the-40-thieves/obsidian-tc-native-win32-x64-msvc": "1.
|
|
63
|
-
"@the-40-thieves/obsidian-tc-native-win32-arm64-msvc": "1.
|
|
56
|
+
"@the-40-thieves/obsidian-tc-native-linux-x64-gnu": "1.11.0",
|
|
57
|
+
"@the-40-thieves/obsidian-tc-native-linux-arm64-gnu": "1.11.0",
|
|
58
|
+
"@the-40-thieves/obsidian-tc-native-linux-x64-musl": "1.11.0",
|
|
59
|
+
"@the-40-thieves/obsidian-tc-native-linux-arm64-musl": "1.11.0",
|
|
60
|
+
"@the-40-thieves/obsidian-tc-native-darwin-x64": "1.11.0",
|
|
61
|
+
"@the-40-thieves/obsidian-tc-native-darwin-arm64": "1.11.0",
|
|
62
|
+
"@the-40-thieves/obsidian-tc-native-win32-x64-msvc": "1.11.0",
|
|
63
|
+
"@the-40-thieves/obsidian-tc-native-win32-arm64-msvc": "1.11.0"
|
|
64
64
|
}
|
|
65
65
|
}
|