@kanonak-protocol/sdk 3.50.0 → 3.51.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/dist/search/SearchIndex.d.ts +10 -2
- package/dist/search/index.js +3 -3
- package/package.json +2 -2
|
@@ -9,10 +9,18 @@ export interface SearchHit {
|
|
|
9
9
|
export interface BuildOptions {
|
|
10
10
|
/**
|
|
11
11
|
* Directory to persist/reuse the embedding cache. When set, an unchanged
|
|
12
|
-
* catalog reuses cached vectors instead of re-embedding.
|
|
13
|
-
* `~/.kanonak/search` when `cache` is true.
|
|
12
|
+
* catalog reuses cached vectors instead of re-embedding.
|
|
14
13
|
*/
|
|
15
14
|
cacheDir?: string;
|
|
15
|
+
/** Progress callback during embedding: (resources embedded so far, total). */
|
|
16
|
+
onProgress?: (done: number, total: number) => void;
|
|
17
|
+
/**
|
|
18
|
+
* Only index subjects passing this predicate (e.g. workspace-local
|
|
19
|
+
* resources, excluding imported vocabulary). Embed-text is still resolved
|
|
20
|
+
* against the FULL catalog, so type labels and the rdfs.Resource floor
|
|
21
|
+
* still apply. Default: index everything.
|
|
22
|
+
*/
|
|
23
|
+
include?: (subject: SubjectKanonak) => boolean;
|
|
16
24
|
}
|
|
17
25
|
export interface BuildResult {
|
|
18
26
|
/** Number of resources indexed. */
|
package/dist/search/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as p}from"../chunk-2WQR7OHH.js";import"../chunk-3NEUHF7E.js";import"../chunk-DC774EQL.js";import"../chunk-NIGFQYVA.js";import"../chunk-H2LEQLVD.js";import{d as m,g as x}from"../chunk-N224PFBI.js";import{a as d,f as S}from"../chunk-Q4DKP5DO.js";import{a as v}from"../chunk-FQHALFRR.js";import"../chunk-64TVBQFR.js";import{c as j}from"../chunk-W6T7MOKY.js";import"../chunk-FUUTGGJS.js";import{homedir as P}from"os";import{join as k}from"path";import{existsSync as B,mkdirSync as C,readFileSync as D,writeFileSync as O}from"fs";import{createHash as z}from"crypto";var f="Xenova/all-MiniLM-L6-v2",w="q8",b=32,g=null;async function K(){return g||(g=(async()=>{let t;try{t=await import("@huggingface/transformers")}catch(i){throw new Error(`Semantic search requires the embedding runtime, which is an optional dependency.
|
|
2
2
|
Install it with:
|
|
3
3
|
npm install @huggingface/transformers
|
|
4
|
-
(underlying import error: ${i.message})`)}let{pipeline:
|
|
4
|
+
(underlying import error: ${i.message})`)}let{pipeline:r,env:n}=t;n.cacheDir=k(P(),".kanonak","models");let e=await r("feature-extraction",f,{dtype:w});return async i=>(await e(i,{pooling:"mean",normalize:!0})).tolist()})()),g}function H(t,r){let n=0;for(let e=0;e<t.length;e++)n+=t[e]*r[e];return n}function U(t,r){return r?t.version?r.version?v(t.version,r.version)>0:!0:!1:!0}function F(t,r){let n=p(t,r),e=[n.label],i=x(r);if(i.length>0){let s=S(t,i[0]),c=s?p(t,s).label:i[0].name;c&&e.push(`\u2014 a ${c}.`)}return n.summary&&e.push(n.summary),e.join(" ")}function M(t){let r=new Map;for(let n of t){if(!(n instanceof j))continue;let e=m(n);if(!e)continue;let i=d(e),s=r.get(i);(!s||U(e,m(s)))&&r.set(i,n)}return[...r.values()].sort((n,e)=>{let i=m(n)?d(m(n)):n.name,s=m(e)?d(m(e)):e.name;return i.localeCompare(s)})}var y=class{entries=[];get size(){return this.entries.length}async build(r,n={}){let e=M(r);if(n.include&&(e=e.filter(n.include)),e.length===0)return this.entries=[],{size:0,cached:!1};let i=e.map(o=>F(r,o)),s=n.cacheDir,c;if(s){let o=z("sha256").update(f+"|"+w+`
|
|
5
5
|
`+i.join(`
|
|
6
|
-
`)).digest("hex").slice(0,32);
|
|
6
|
+
`)).digest("hex").slice(0,32);c=k(s,`index-${o}.json`);let u=T(c);if(u&&u.model===f&&u.vectors.length===e.length)return this.entries=e.map((h,E)=>({subject:h,namespace:h.namespace||"",vector:u.vectors[E]})),{size:this.entries.length,cached:!0}}let a=await K(),l=[];for(let o=0;o<i.length;o+=b){let u=await a(i.slice(o,o+b));for(let h of u)l.push(h);n.onProgress?.(Math.min(o+b,i.length),i.length)}return this.entries=e.map((o,u)=>({subject:o,namespace:o.namespace||"",vector:l[u]})),c&&q(c,{model:f,vectors:l}),{size:this.entries.length,cached:!1}}async query(r,n){if(this.entries.length===0)return[];let e=await K(),[i]=await e([r]),s=n?.scope;return this.entries.filter(a=>!s||a.namespace.startsWith(s)).map(a=>({subject:a.subject,score:H(i,a.vector)})).sort((a,l)=>l.score-a.score).slice(0,n?.limit??20)}};function T(t){try{return B(t)?JSON.parse(D(t,"utf-8")):null}catch{return null}}function q(t,r){try{C(k(t,".."),{recursive:!0}),O(t,JSON.stringify(r))}catch{}}export{y as SearchIndex,F as embedTextFor};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kanonak-protocol/sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.51.0",
|
|
4
4
|
"description": "Kanonak Protocol SDK - Document repository and parsing implementations for TypeScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
"yaml-parser"
|
|
122
122
|
],
|
|
123
123
|
"dependencies": {
|
|
124
|
-
"@kanonak-protocol/types": "^3.
|
|
124
|
+
"@kanonak-protocol/types": "^3.51.0",
|
|
125
125
|
"ignore": "^7.0.5",
|
|
126
126
|
"js-yaml": "^4.1.0",
|
|
127
127
|
"yaml": "^2.7.0"
|