@the-40-thieves/obsidian-tc-native 1.8.0 → 1.9.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 CHANGED
@@ -23,6 +23,18 @@ function cosineSimilarity(a, b) {
23
23
  return dot / (Math.sqrt(na) * Math.sqrt(nb));
24
24
  }
25
25
 
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`. */
28
+ function cosineBatch(query, docsFlat, dim) {
29
+ if (dim <= 0 || query.length !== dim || docsFlat.length % dim !== 0) return new Float64Array(0);
30
+ const n = docsFlat.length / dim;
31
+ const out = new Float64Array(n);
32
+ for (let i = 0; i < n; i++) {
33
+ out[i] = cosineSimilarity(query, docsFlat.subarray(i * dim, i * dim + dim));
34
+ }
35
+ return out;
36
+ }
37
+
26
38
  /** Lowercase tokenizer over Unicode alphabetic + numbers (matches Rust is_alphanumeric). Mirrors the Rust. */
27
39
  function tokenize(text) {
28
40
  const out = [];
@@ -47,5 +59,6 @@ function bm25Score(tf, docLen, avgDocLen, docFreq, docCount) {
47
59
  }
48
60
 
49
61
  module.exports.cosineSimilarity = cosineSimilarity;
62
+ module.exports.cosineBatch = cosineBatch;
50
63
  module.exports.tokenize = tokenize;
51
64
  module.exports.bm25Score = bm25Score;
package/index.d.ts CHANGED
@@ -4,6 +4,14 @@
4
4
  /** Cosine similarity between two equal-length vectors; 0 for empty/mismatched inputs. */
5
5
  export declare function cosineSimilarity(a: number[], b: Float32Array | number[]): number;
6
6
 
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. */
9
+ export declare function cosineBatch(
10
+ query: number[],
11
+ docsFlat: Float32Array,
12
+ dim: number,
13
+ ): Float64Array;
14
+
7
15
  /** Tokenize text into lowercase alphanumeric terms for BM25 scoring. */
8
16
  export declare function tokenize(text: string): string[];
9
17
 
package/index.js CHANGED
@@ -138,6 +138,9 @@ const impl = native !== null ? native : require("./fallback.js");
138
138
  /** True when the compiled native binary is active; false when on the pure-JS fallback. */
139
139
  module.exports.nativeLoaded = native !== null;
140
140
  module.exports.cosineSimilarity = impl.cosineSimilarity;
141
+ // cosineBatch: present on a freshly built native module; on an older binary (or the JS fallback)
142
+ // impl.cosineBatch resolves from fallback.js. NOT added to isComplete() so an older .node still loads.
143
+ module.exports.cosineBatch = impl.cosineBatch;
141
144
  module.exports.tokenize = impl.tokenize;
142
145
  module.exports.bm25Score = impl.bm25Score;
143
146
  // THE-272: symlink-safe, TOCTOU-free vault I/O. Present only when the compiled native module is
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@the-40-thieves/obsidian-tc-native",
3
- "version": "1.8.0",
3
+ "version": "1.9.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.8.0",
57
- "@the-40-thieves/obsidian-tc-native-linux-arm64-gnu": "1.8.0",
58
- "@the-40-thieves/obsidian-tc-native-linux-x64-musl": "1.8.0",
59
- "@the-40-thieves/obsidian-tc-native-linux-arm64-musl": "1.8.0",
60
- "@the-40-thieves/obsidian-tc-native-darwin-x64": "1.8.0",
61
- "@the-40-thieves/obsidian-tc-native-darwin-arm64": "1.8.0",
62
- "@the-40-thieves/obsidian-tc-native-win32-x64-msvc": "1.8.0",
63
- "@the-40-thieves/obsidian-tc-native-win32-arm64-msvc": "1.8.0"
56
+ "@the-40-thieves/obsidian-tc-native-linux-x64-gnu": "1.9.0",
57
+ "@the-40-thieves/obsidian-tc-native-linux-arm64-gnu": "1.9.0",
58
+ "@the-40-thieves/obsidian-tc-native-linux-x64-musl": "1.9.0",
59
+ "@the-40-thieves/obsidian-tc-native-linux-arm64-musl": "1.9.0",
60
+ "@the-40-thieves/obsidian-tc-native-darwin-x64": "1.9.0",
61
+ "@the-40-thieves/obsidian-tc-native-darwin-arm64": "1.9.0",
62
+ "@the-40-thieves/obsidian-tc-native-win32-x64-msvc": "1.9.0",
63
+ "@the-40-thieves/obsidian-tc-native-win32-arm64-msvc": "1.9.0"
64
64
  }
65
65
  }