PageSourceSearch

https://kindredly.ai/js/queryEmbeddingl6fVc4SQ.js

js kindredly.ai collected 2026-10-02 01:14:05 UTC 3,327 bytes, 1 lines download raw bytes

1function I(t,o){if(!t.length||!o.length)return 0;const i=Math.min(t.length,o.length);let r=0,n=0,s=0;for(let c=0;c<i;c++){const l=t[c],d=o[c];r+=l*d,n+=l*l,s+=d*d}const e=Math.sqrt(n)*Math.sqrt(s);return e>0?r/e:0}function m(t){return t.replace(/\s+/g," ").trim()}const S=1;function q(t){return`[label-example-v${S}] ${m(t)}`}const O={cacheEnabled:!0,mode:"document",enableChunking:!1};function M(t){return typeof t=="string"?t:t&&typeof t.extractedText=="string"?t.extractedText:""}function R(t,o){const i=t.filter(s=>typeof s=="string").map(s=>m(s)).filter(Boolean),r=[];let n="";for(const s of i){const e=n.length===0?s:`${n}; ${s}`;if(e.length>o){n.length>0&&r.push(n),n=s;continue}n=e}return n.length>0&&r.push(n),r}function k(t){var E,y,A,w;const o=m(((E=t==null?void 0:t.features)==null?void 0:E.title)||""),i=m(((y=t==null?void 0:t.features)==null?void 0:y.description)||""),r=(A=t==null?void 0:t.features)==null?void 0:A.keywords,n=Array.isArray(r)?r:[],s=.5,e=.25,c=.25,l=200,d=400,h=180,g=18,u=[];o.length>0&&u.push({text:o.slice(0,l),weight:s,source:"title"}),i.length>0&&u.push({text:i.slice(0,d),weight:e,source:"description"});const a=n.filter(f=>typeof f=="string").map(f=>m(f)).filter(Boolean).slice(0,g);if(a.length>0){const f=R(a,h),_=c/f.length;for(const T of f)u.push({text:T,weight:_,source:"keywords"})}if(u.length>0)return u;const x=m(M((w=t==null?void 0:t.features)==null?void 0:w.extractedText)),C=m((t==null?void 0:t.url)||""),b=x||o||C;return b.length===0?[]:(u.push({text:b.slice(0,200),weight:1,source:"fallback"}),u)}function p(t){const o=t.filter(e=>e.weight>0&&Array.isArray(e.embedding)&&e.embedding.length>0);if(o.length===0)return[];const i=Math.min(...o.map(e=>e.embedding.length));if(!Number.isFinite(i)||i<=0)return[];const r=new Array(i).fill(0);let n=0;for(const e of o){n+=e.weight;for(let c=0;c<i;c++)r[c]+=e.embedding[c]*e.weight}if(n>0)for(let e=0;e<i;e++)r[e]=r[e]/n;let s=0;for(let e=0;e<i;e++)s+=r[e]*r[e];if(s=Math.sqrt(s),s>0)for(let e=0;e<i;e++)r[e]=r[e]/s;return r}async function W(t,o,i){const r=!!(i!=null&&i.includeTiming),n={queryEmbedMs:0,queryEmbedCalls:0,queryEmbedCachedCalls:0},s=k(o);if(s.length===0)return{embedding:[],chunks:s,model:null,dimensions:null,cachedAny:!1,stats:n};const e=[];let c=null,l=null,d=!1;for(const g of s){const u=r?performance.now():0,a=await t.generateEmbedding(g.text,{cacheEnabled:!0,mode:"document",enableChunking:!0});r&&(n.queryEmbedMs+=performance.now()-u,n.queryEmbedCalls++,a.cached&&n.queryEmbedCachedCalls++),c||(c=a.model),l||(l=a.dimensions),a.cached&&(d=!0),Array.isArray(a.embedding)&&a.embedding.length>0&&e.push({embedding:a.embedding,weight:g.weight})}return{embedding:p(e),chunks:s,model:c,dimensions:l,cachedAny:d,stats:n}}async function L(t,o){const i=[],r=[];for(const{id:c,info:l}of o){const d=k(l);if(d.length===0)continue;const h=d.map(g=>{const u=r.length;return r.push({id:String(u),text:g.text}),{gid:u,weight:g.weight}});i.push({id:c,chunks:h})}const n=new Map;if(r.length===0)return n;const s=await t.batchEmbeddings(r,{cacheEnabled:!0,mode:"document",enableChunking:!0}),e=[];for(const c of s)e[Number(c.id)]=c.embedding||[];for(const c of i){const l=c.chunks.map(h=>({embedding:e[h.gid]||[],weight:h.weight})),d=p(l);d.length&&n.set(c.id,d)}return n}export{O as A,q as a,k as b,W as c,I as d,L as e,m as n};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.