murmur-rag 0.1.2 → 1.0.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.
@@ -1,2 +1,2 @@
1
- import{Ye}from"./embed-2xm309sb.js";class L{constructor(t,e){let s=t._tree,n=Array.from(s.keys());this.set=t,this._type=e,this._path=n.length>0?[{node:s,keys:n}]:[]}next(){let t=this.dive();return this.backtrack(),t}dive(){if(this._path.length===0)return{done:!0,value:void 0};let{node:t,keys:e}=y(this._path);if(y(e)==="")return{done:!1,value:this.result()};let s=t.get(y(e));return this._path.push({node:s,keys:Array.from(s.keys())}),this.dive()}backtrack(){if(this._path.length===0)return;let t=y(this._path).keys;if(t.pop(),t.length>0)return;this._path.pop(),this.backtrack()}key(){return this.set._prefix+this._path.map(({keys:t})=>y(t)).filter((t)=>t!=="").join("")}value(){return y(this._path).node.get("")}result(){switch(this._type){case"VALUES":return this.value();case"KEYS":return this.key();default:return[this.key(),this.value()]}}[Symbol.iterator](){return this}}var y=(t)=>t[t.length-1],G=(t,e,s)=>{let n=new Map;if(e===void 0)return n;let i=e.length+1,r=i+s,c=new Uint8Array(r*i).fill(s+1);for(let o=0;o<i;++o)c[o]=o;for(let o=1;o<r;++o)c[o*i]=o;return Q(t,e,s,n,c,1,i,""),n},Q=(t,e,s,n,i,r,c,o)=>{let d=r*c;t:for(let u of t.keys())if(u===""){let h=i[d-1];if(h<=s)n.set(o,[t.get(u),h])}else{let h=r;for(let a=0;a<u.length;++a,++h){let f=u[a],m=c*h,g=m-c,l=i[m],_=Math.max(0,h-s-1),F=Math.min(c-1,h+s);for(let p=_;p<F;++p){let E=f!==e[p],S=i[g+p]+ +E,x=i[g+p+1]+1,I=i[m+p]+1,j=i[m+p+1]=Math.min(S,x,I);if(j<l)l=j}if(l>s)continue t}Q(t.get(u),e,s,n,i,h,c,o+u)}};class w{constructor(t=new Map,e=""){this._size=void 0,this._tree=t,this._prefix=e}atPrefix(t){if(!t.startsWith(this._prefix))throw Error("Mismatched prefix");let[e,s]=k(this._tree,t.slice(this._prefix.length));if(e===void 0){let[n,i]=R(s);for(let r of n.keys())if(r!==""&&r.startsWith(i)){let c=new Map;return c.set(r.slice(i.length),n.get(r)),new w(c,t)}}return new w(e,t)}clear(){this._size=void 0,this._tree.clear()}delete(t){return this._size=void 0,Z(this._tree,t)}entries(){return new L(this,"ENTRIES")}forEach(t){for(let[e,s]of this)t(e,s,this)}fuzzyGet(t,e){return G(this._tree,t,e)}get(t){let e=A(this._tree,t);return e!==void 0?e.get(""):void 0}has(t){let e=A(this._tree,t);return e!==void 0&&e.has("")}keys(){return new L(this,"KEYS")}set(t,e){if(typeof t!=="string")throw Error("key must be a string");return this._size=void 0,M(this._tree,t).set("",e),this}get size(){if(this._size)return this._size;this._size=0;let t=this.entries();while(!t.next().done)this._size+=1;return this._size}update(t,e){if(typeof t!=="string")throw Error("key must be a string");this._size=void 0;let s=M(this._tree,t);return s.set("",e(s.get(""))),this}fetch(t,e){if(typeof t!=="string")throw Error("key must be a string");this._size=void 0;let s=M(this._tree,t),n=s.get("");if(n===void 0)s.set("",n=e());return n}values(){return new L(this,"VALUES")}[Symbol.iterator](){return this.entries()}static from(t){let e=new w;for(let[s,n]of t)e.set(s,n);return e}static fromObject(t){return w.from(Object.entries(t))}}var k=(t,e,s=[])=>{if(e.length===0||t==null)return[t,s];for(let n of t.keys())if(n!==""&&e.startsWith(n))return s.push([t,n]),k(t.get(n),e.slice(n.length),s);return s.push([t,e]),k(void 0,"",s)},A=(t,e)=>{if(e.length===0||t==null)return t;for(let s of t.keys())if(s!==""&&e.startsWith(s))return A(t.get(s),e.slice(s.length))},M=(t,e)=>{let s=e.length;t:for(let n=0;t&&n<s;){for(let r of t.keys())if(r!==""&&e[n]===r[0]){let c=Math.min(s-n,r.length),o=1;while(o<c&&e[n+o]===r[o])++o;let d=t.get(r);if(o===r.length)t=d;else{let u=new Map;u.set(r.slice(o),d),t.set(e.slice(n,n+o),u),t.delete(r),t=u}n+=o;continue t}let i=new Map;return t.set(e.slice(n),i),i}return t},Z=(t,e)=>{let[s,n]=k(t,e);if(s===void 0)return;if(s.delete(""),s.size===0)B(n);else if(s.size===1){let[i,r]=s.entries().next().value;K(n,i,r)}},B=(t)=>{if(t.length===0)return;let[e,s]=R(t);if(e.delete(s),e.size===0)B(t.slice(0,-1));else if(e.size===1){let[n,i]=e.entries().next().value;if(n!=="")K(t.slice(0,-1),n,i)}},K=(t,e,s)=>{if(t.length===0)return;let[n,i]=R(t);n.set(i+e,s),n.delete(i)},R=(t)=>t[t.length-1],N="or",q="and",H="and_not";class z{constructor(t){if((t===null||t===void 0?void 0:t.fields)==null)throw Error('MiniSearch: option "fields" must be provided');let e=t.autoVacuum==null||t.autoVacuum===!0?C:t.autoVacuum;this._options={...V,...t,autoVacuum:e,searchOptions:{...P,...t.searchOptions||{}},autoSuggestOptions:{...nt,...t.autoSuggestOptions||{}}},this._index=new w,this._documentCount=0,this._documentIds=new Map,this._idToShortId=new Map,this._fieldIds={},this._fieldLength=new Map,this._avgFieldLength=[],this._nextId=0,this._storedFields=new Map,this._dirtCount=0,this._currentVacuum=null,this._enqueuedVacuum=null,this._enqueuedVacuumConditions=D,this.addFields(this._options.fields)}add(t){let{extractField:e,stringifyField:s,tokenize:n,processTerm:i,fields:r,idField:c}=this._options,o=e(t,c);if(o==null)throw Error(`MiniSearch: document does not have ID field "${c}"`);if(this._idToShortId.has(o))throw Error(`MiniSearch: duplicate ID ${o}`);let d=this.addDocumentId(o);this.saveStoredFields(d,t);for(let u of r){let h=e(t,u);if(h==null)continue;let a=n(s(h,u),u),f=this._fieldIds[u],m=new Set(a).size;this.addFieldLength(d,f,this._documentCount-1,m);for(let g of a){let l=i(g,u);if(Array.isArray(l))for(let _ of l)this.addTerm(f,d,_);else if(l)this.addTerm(f,d,l)}}}addAll(t){for(let e of t)this.add(e)}addAllAsync(t,e={}){let{chunkSize:s=10}=e,n={chunk:[],promise:Promise.resolve()},{chunk:i,promise:r}=t.reduce(({chunk:c,promise:o},d,u)=>{if(c.push(d),(u+1)%s===0)return{chunk:[],promise:o.then(()=>new Promise((h)=>setTimeout(h,0))).then(()=>this.addAll(c))};else return{chunk:c,promise:o}},n);return r.then(()=>this.addAll(i))}remove(t){let{tokenize:e,processTerm:s,extractField:n,stringifyField:i,fields:r,idField:c}=this._options,o=n(t,c);if(o==null)throw Error(`MiniSearch: document does not have ID field "${c}"`);let d=this._idToShortId.get(o);if(d==null)throw Error(`MiniSearch: cannot remove document with ID ${o}: it is not in the index`);for(let u of r){let h=n(t,u);if(h==null)continue;let a=e(i(h,u),u),f=this._fieldIds[u],m=new Set(a).size;this.removeFieldLength(d,f,this._documentCount,m);for(let g of a){let l=s(g,u);if(Array.isArray(l))for(let _ of l)this.removeTerm(f,d,_);else if(l)this.removeTerm(f,d,l)}}this._storedFields.delete(d),this._documentIds.delete(d),this._idToShortId.delete(o),this._fieldLength.delete(d),this._documentCount-=1}removeAll(t){if(t)for(let e of t)this.remove(e);else if(arguments.length>0)throw Error("Expected documents to be present. Omit the argument to remove all documents.");else this._index=new w,this._documentCount=0,this._documentIds=new Map,this._idToShortId=new Map,this._fieldLength=new Map,this._avgFieldLength=[],this._storedFields=new Map,this._nextId=0}discard(t){let e=this._idToShortId.get(t);if(e==null)throw Error(`MiniSearch: cannot discard document with ID ${t}: it is not in the index`);this._idToShortId.delete(t),this._documentIds.delete(e),this._storedFields.delete(e),(this._fieldLength.get(e)||[]).forEach((s,n)=>{this.removeFieldLength(e,n,this._documentCount,s)}),this._fieldLength.delete(e),this._documentCount-=1,this._dirtCount+=1,this.maybeAutoVacuum()}maybeAutoVacuum(){if(this._options.autoVacuum===!1)return;let{minDirtFactor:t,minDirtCount:e,batchSize:s,batchWait:n}=this._options.autoVacuum;this.conditionalVacuum({batchSize:s,batchWait:n},{minDirtCount:e,minDirtFactor:t})}discardAll(t){let e=this._options.autoVacuum;try{this._options.autoVacuum=!1;for(let s of t)this.discard(s)}finally{this._options.autoVacuum=e}this.maybeAutoVacuum()}replace(t){let{idField:e,extractField:s}=this._options,n=s(t,e);this.discard(n),this.add(t)}vacuum(t={}){return this.conditionalVacuum(t)}conditionalVacuum(t,e){if(this._currentVacuum){if(this._enqueuedVacuumConditions=this._enqueuedVacuumConditions&&e,this._enqueuedVacuum!=null)return this._enqueuedVacuum;return this._enqueuedVacuum=this._currentVacuum.then(()=>{let s=this._enqueuedVacuumConditions;return this._enqueuedVacuumConditions=D,this.performVacuuming(t,s)}),this._enqueuedVacuum}if(this.vacuumConditionsMet(e)===!1)return Promise.resolve();return this._currentVacuum=this.performVacuuming(t),this._currentVacuum}async performVacuuming(t,e){let s=this._dirtCount;if(this.vacuumConditionsMet(e)){let n=t.batchSize||T.batchSize,i=t.batchWait||T.batchWait,r=1;for(let[c,o]of this._index){for(let[d,u]of o)for(let[h]of u){if(this._documentIds.has(h))continue;if(u.size<=1)o.delete(d);else u.delete(h)}if(this._index.get(c).size===0)this._index.delete(c);if(r%n===0)await new Promise((d)=>setTimeout(d,i));r+=1}this._dirtCount-=s}await null,this._currentVacuum=this._enqueuedVacuum,this._enqueuedVacuum=null}vacuumConditionsMet(t){if(t==null)return!0;let{minDirtCount:e,minDirtFactor:s}=t;return e=e||C.minDirtCount,s=s||C.minDirtFactor,this.dirtCount>=e&&this.dirtFactor>=s}get isVacuuming(){return this._currentVacuum!=null}get dirtCount(){return this._dirtCount}get dirtFactor(){return this._dirtCount/(1+this._documentCount+this._dirtCount)}has(t){return this._idToShortId.has(t)}getStoredFields(t){let e=this._idToShortId.get(t);if(e==null)return;return this._storedFields.get(e)}search(t,e={}){let{searchOptions:s}=this._options,n={...s,...e},i=this.executeQuery(t,e),r=[];for(let[c,{score:o,terms:d,match:u}]of i){let h=d.length||1,a={id:this._documentIds.get(c),score:o*h,terms:Object.keys(u),queryTerms:d,match:u};if(Object.assign(a,this._storedFields.get(c)),n.filter==null||n.filter(a))r.push(a)}if(t===z.wildcard&&n.boostDocument==null)return r;return r.sort(J),r}autoSuggest(t,e={}){e={...this._options.autoSuggestOptions,...e};let s=new Map;for(let{score:i,terms:r}of this.search(t,e)){let c=r.join(" "),o=s.get(c);if(o!=null)o.score+=i,o.count+=1;else s.set(c,{score:i,terms:r,count:1})}let n=[];for(let[i,{score:r,terms:c,count:o}]of s)n.push({suggestion:i,terms:c,score:r/o});return n.sort(J),n}get documentCount(){return this._documentCount}get termCount(){return this._index.size}static loadJSON(t,e){if(e==null)throw Error("MiniSearch: loadJSON should be given the same options used when serializing the index");return this.loadJS(JSON.parse(t),e)}static async loadJSONAsync(t,e){if(e==null)throw Error("MiniSearch: loadJSON should be given the same options used when serializing the index");return this.loadJSAsync(JSON.parse(t),e)}static getDefault(t){if(V.hasOwnProperty(t))return O(V,t);else throw Error(`MiniSearch: unknown option "${t}"`)}static loadJS(t,e){let{index:s,documentIds:n,fieldLength:i,storedFields:r,serializationVersion:c}=t,o=this.instantiateMiniSearch(t,e);o._documentIds=b(n),o._fieldLength=b(i),o._storedFields=b(r);for(let[d,u]of o._documentIds)o._idToShortId.set(u,d);for(let[d,u]of s){let h=new Map;for(let a of Object.keys(u)){let f=u[a];if(c===1)f=f.ds;h.set(parseInt(a,10),b(f))}o._index.set(d,h)}return o}static async loadJSAsync(t,e){let{index:s,documentIds:n,fieldLength:i,storedFields:r,serializationVersion:c}=t,o=this.instantiateMiniSearch(t,e);o._documentIds=await v(n),o._fieldLength=await v(i),o._storedFields=await v(r);for(let[u,h]of o._documentIds)o._idToShortId.set(h,u);let d=0;for(let[u,h]of s){let a=new Map;for(let f of Object.keys(h)){let m=h[f];if(c===1)m=m.ds;a.set(parseInt(f,10),await v(m))}if(++d%1000===0)await Y(0);o._index.set(u,a)}return o}static instantiateMiniSearch(t,e){let{documentCount:s,nextId:n,fieldIds:i,averageFieldLength:r,dirtCount:c,serializationVersion:o}=t;if(o!==1&&o!==2)throw Error("MiniSearch: cannot deserialize an index created with an incompatible version");let d=new z(e);return d._documentCount=s,d._nextId=n,d._idToShortId=new Map,d._fieldIds=i,d._avgFieldLength=r,d._dirtCount=c||0,d._index=new w,d}executeQuery(t,e={}){if(t===z.wildcard)return this.executeWildcardQuery(e);if(typeof t!=="string"){let a={...e,...t,queries:void 0},f=t.queries.map((m)=>this.executeQuery(m,a));return this.combineResults(f,a.combineWith)}let{tokenize:s,processTerm:n,searchOptions:i}=this._options,r={tokenize:s,processTerm:n,...i,...e},{tokenize:c,processTerm:o}=r,h=c(t).flatMap((a)=>o(a)).filter((a)=>!!a).map(st(r)).map((a)=>this.executeQuerySpec(a,r));return this.combineResults(h,r.combineWith)}executeQuerySpec(t,e){let s={...this._options.searchOptions,...e},n=(s.fields||this._options.fields).reduce((g,l)=>({...g,[l]:O(s.boost,l)||1}),{}),{boostDocument:i,weights:r,maxFuzzy:c,bm25:o}=s,{fuzzy:d,prefix:u}={...P.weights,...r},h=this._index.get(t.term),a=this.termResults(t.term,t.term,1,t.termBoost,h,n,i,o),f,m;if(t.prefix)f=this._index.atPrefix(t.term);if(t.fuzzy){let g=t.fuzzy===!0?0.2:t.fuzzy,l=g<1?Math.min(c,Math.round(t.term.length*g)):g;if(l)m=this._index.fuzzyGet(t.term,l)}if(f)for(let[g,l]of f){let _=g.length-t.term.length;if(!_)continue;m===null||m===void 0||m.delete(g);let F=u*g.length/(g.length+0.3*_);this.termResults(t.term,g,F,t.termBoost,l,n,i,o,a)}if(m)for(let g of m.keys()){let[l,_]=m.get(g);if(!_)continue;let F=d*g.length/(g.length+_);this.termResults(t.term,g,F,t.termBoost,l,n,i,o,a)}return a}executeWildcardQuery(t){let e=new Map,s={...this._options.searchOptions,...t};for(let[n,i]of this._documentIds){let r=s.boostDocument?s.boostDocument(i,"",this._storedFields.get(n)):1;e.set(n,{score:r,terms:[],match:{}})}return e}combineResults(t,e=N){if(t.length===0)return new Map;let s=e.toLowerCase(),n=X[s];if(!n)throw Error(`Invalid combination operator: ${e}`);return t.reduce(n)||new Map}toJSON(){let t=[];for(let[e,s]of this._index){let n={};for(let[i,r]of s)n[i]=Object.fromEntries(r);t.push([e,n])}return{documentCount:this._documentCount,nextId:this._nextId,documentIds:Object.fromEntries(this._documentIds),fieldIds:this._fieldIds,fieldLength:Object.fromEntries(this._fieldLength),averageFieldLength:this._avgFieldLength,storedFields:Object.fromEntries(this._storedFields),dirtCount:this._dirtCount,index:t,serializationVersion:2}}termResults(t,e,s,n,i,r,c,o,d=new Map){if(i==null)return d;for(let u of Object.keys(r)){let h=r[u],a=this._fieldIds[u],f=i.get(a);if(f==null)continue;let m=f.size,g=this._avgFieldLength[a];for(let l of f.keys()){if(!this._documentIds.has(l)){this.removeTerm(a,l,e),m-=1;continue}let _=c?c(this._documentIds.get(l),e,this._storedFields.get(l)):1;if(!_)continue;let F=f.get(l),p=this._fieldLength.get(l)[a],E=et(F,m,this._documentCount,p,g,o),S=s*n*h*_*E,x=d.get(l);if(x){x.score+=S,it(x.terms,t);let I=O(x.match,e);if(I)I.push(u);else x.match[e]=[u]}else d.set(l,{score:S,terms:[t],match:{[e]:[u]}})}}return d}addTerm(t,e,s){let n=this._index.fetch(s,U),i=n.get(t);if(i==null)i=new Map,i.set(e,1),n.set(t,i);else{let r=i.get(e);i.set(e,(r||0)+1)}}removeTerm(t,e,s){if(!this._index.has(s)){this.warnDocumentChanged(e,t,s);return}let n=this._index.fetch(s,U),i=n.get(t);if(i==null||i.get(e)==null)this.warnDocumentChanged(e,t,s);else if(i.get(e)<=1)if(i.size<=1)n.delete(t);else i.delete(e);else i.set(e,i.get(e)-1);if(this._index.get(s).size===0)this._index.delete(s)}warnDocumentChanged(t,e,s){for(let n of Object.keys(this._fieldIds))if(this._fieldIds[n]===e){this._options.logger("warn",`MiniSearch: document with ID ${this._documentIds.get(t)} has changed before removal: term "${s}" was not present in field "${n}". Removing a document after it has changed can corrupt the index!`,"version_conflict");return}}addDocumentId(t){let e=this._nextId;return this._idToShortId.set(t,e),this._documentIds.set(e,t),this._documentCount+=1,this._nextId+=1,e}addFields(t){for(let e=0;e<t.length;e++)this._fieldIds[t[e]]=e}addFieldLength(t,e,s,n){let i=this._fieldLength.get(t);if(i==null)this._fieldLength.set(t,i=[]);i[e]=n;let c=(this._avgFieldLength[e]||0)*s+n;this._avgFieldLength[e]=c/(s+1)}removeFieldLength(t,e,s,n){if(s===1){this._avgFieldLength[e]=0;return}let i=this._avgFieldLength[e]*s-n;this._avgFieldLength[e]=i/(s-1)}saveStoredFields(t,e){let{storeFields:s,extractField:n}=this._options;if(s==null||s.length===0)return;let i=this._storedFields.get(t);if(i==null)this._storedFields.set(t,i={});for(let r of s){let c=n(e,r);if(c!==void 0)i[r]=c}}}z.wildcard=Symbol("*");var O=(t,e)=>Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0,X={[N]:(t,e)=>{for(let s of e.keys()){let n=t.get(s);if(n==null)t.set(s,e.get(s));else{let{score:i,terms:r,match:c}=e.get(s);n.score=n.score+i,n.match=Object.assign(n.match,c),W(n.terms,r)}}return t},[q]:(t,e)=>{let s=new Map;for(let n of e.keys()){let i=t.get(n);if(i==null)continue;let{score:r,terms:c,match:o}=e.get(n);W(i.terms,c),s.set(n,{score:i.score+r,terms:i.terms,match:Object.assign(i.match,o)})}return s},[H]:(t,e)=>{for(let s of e.keys())t.delete(s);return t}},tt={k:1.2,b:0.7,d:0.5},et=(t,e,s,n,i,r)=>{let{k:c,b:o,d}=r;return Math.log(1+(s-e+0.5)/(e+0.5))*(d+t*(c+1)/(t+c*(1-o+o*n/i)))},st=(t)=>(e,s,n)=>{let i=typeof t.fuzzy==="function"?t.fuzzy(e,s,n):t.fuzzy||!1,r=typeof t.prefix==="function"?t.prefix(e,s,n):t.prefix===!0,c=typeof t.boostTerm==="function"?t.boostTerm(e,s,n):1;return{term:e,fuzzy:i,prefix:r,termBoost:c}},V={idField:"id",extractField:(t,e)=>t[e],stringifyField:(t,e)=>t.toString(),tokenize:(t)=>t.split(ot),processTerm:(t)=>t.toLowerCase(),fields:void 0,searchOptions:void 0,storeFields:[],logger:(t,e)=>{if(typeof(console===null||console===void 0?void 0:console[t])==="function")console[t](e)},autoVacuum:!0},P={combineWith:N,prefix:!1,fuzzy:!1,maxFuzzy:6,boost:{},weights:{fuzzy:0.45,prefix:0.375},bm25:tt},nt={combineWith:q,prefix:(t,e,s)=>e===s.length-1},T={batchSize:1000,batchWait:10},D={minDirtFactor:0.1,minDirtCount:20},C={...T,...D},it=(t,e)=>{if(!t.includes(e))t.push(e)},W=(t,e)=>{for(let s of e)if(!t.includes(s))t.push(s)},J=({score:t},{score:e})=>e-t,U=()=>new Map,b=(t)=>{let e=new Map;for(let s of Object.keys(t))e.set(parseInt(s,10),t[s]);return e},v=async(t)=>{let e=new Map,s=0;for(let n of Object.keys(t))if(e.set(parseInt(n,10),t[n]),++s%1000===0)await Y(0);return e},Y=(t)=>new Promise((e)=>setTimeout(e,t)),ot=/[\n\r\p{Z}\p{P}]+/u;var rt=(t)=>t.normalize("NFD").replace(/\p{M}/gu,"").toLowerCase();function ct(t){return t.chunks.map((e)=>{let s=t.docs[e.doc];return{...e,url:s?.url??"",title:s?.title??""}})}function It(t){let e=ct(t),s=new z({fields:["title","heading","text"],processTerm:(n)=>rt(n),searchOptions:{prefix:!0,fuzzy:0.15,boost:{title:2,heading:1.5}}});return s.addAll(e.map((n,i)=>({id:i,title:n.title,heading:n.heading,text:n.text}))),{async search(n,{limit:i=6,budgetTokens:r=3000}={}){let c=[],o=0;for(let d of s.search(n,{combineWith:"OR"})){let u=e[Number(d.id)];if(!u)continue;let h=Ye(u.text)+24;if(o+h>r)continue;if(o+=h,c.push(u),c.length>=i)break}return c}}}
1
+ import{Ye}from"./embed-2xm309sb.js";class L{constructor(t,e){let s=t._tree,n=Array.from(s.keys());this.set=t,this._type=e,this._path=n.length>0?[{node:s,keys:n}]:[]}next(){let t=this.dive();return this.backtrack(),t}dive(){if(this._path.length===0)return{done:!0,value:void 0};let{node:t,keys:e}=z(this._path);if(z(e)==="")return{done:!1,value:this.result()};let s=t.get(z(e));return this._path.push({node:s,keys:Array.from(s.keys())}),this.dive()}backtrack(){if(this._path.length===0)return;let t=z(this._path).keys;if(t.pop(),t.length>0)return;this._path.pop(),this.backtrack()}key(){return this.set._prefix+this._path.map(({keys:t})=>z(t)).filter((t)=>t!=="").join("")}value(){return z(this._path).node.get("")}result(){switch(this._type){case"VALUES":return this.value();case"KEYS":return this.key();default:return[this.key(),this.value()]}}[Symbol.iterator](){return this}}var z=(t)=>t[t.length-1],G=(t,e,s)=>{let n=new Map;if(e===void 0)return n;let i=e.length+1,r=i+s,c=new Uint8Array(r*i).fill(s+1);for(let o=0;o<i;++o)c[o]=o;for(let o=1;o<r;++o)c[o*i]=o;return U(t,e,s,n,c,1,i,""),n},U=(t,e,s,n,i,r,c,o)=>{let u=r*c;t:for(let d of t.keys())if(d===""){let a=i[u-1];if(a<=s)n.set(o,[t.get(d),a])}else{let a=r;for(let h=0;h<d.length;++h,++a){let f=d[h],m=c*a,g=m-c,l=i[m],_=Math.max(0,a-s-1),F=Math.min(c-1,a+s);for(let p=_;p<F;++p){let k=f!==e[p],S=i[g+p]+ +k,y=i[g+p+1]+1,I=i[m+p]+1,j=i[m+p+1]=Math.min(S,y,I);if(j<l)l=j}if(l>s)continue t}U(t.get(d),e,s,n,i,a,c,o+d)}};class w{constructor(t=new Map,e=""){this._size=void 0,this._tree=t,this._prefix=e}atPrefix(t){if(!t.startsWith(this._prefix))throw Error("Mismatched prefix");let[e,s]=E(this._tree,t.slice(this._prefix.length));if(e===void 0){let[n,i]=R(s);for(let r of n.keys())if(r!==""&&r.startsWith(i)){let c=new Map;return c.set(r.slice(i.length),n.get(r)),new w(c,t)}}return new w(e,t)}clear(){this._size=void 0,this._tree.clear()}delete(t){return this._size=void 0,Z(this._tree,t)}entries(){return new L(this,"ENTRIES")}forEach(t){for(let[e,s]of this)t(e,s,this)}fuzzyGet(t,e){return G(this._tree,t,e)}get(t){let e=A(this._tree,t);return e!==void 0?e.get(""):void 0}has(t){let e=A(this._tree,t);return e!==void 0&&e.has("")}keys(){return new L(this,"KEYS")}set(t,e){if(typeof t!=="string")throw Error("key must be a string");return this._size=void 0,M(this._tree,t).set("",e),this}get size(){if(this._size)return this._size;this._size=0;let t=this.entries();while(!t.next().done)this._size+=1;return this._size}update(t,e){if(typeof t!=="string")throw Error("key must be a string");this._size=void 0;let s=M(this._tree,t);return s.set("",e(s.get(""))),this}fetch(t,e){if(typeof t!=="string")throw Error("key must be a string");this._size=void 0;let s=M(this._tree,t),n=s.get("");if(n===void 0)s.set("",n=e());return n}values(){return new L(this,"VALUES")}[Symbol.iterator](){return this.entries()}static from(t){let e=new w;for(let[s,n]of t)e.set(s,n);return e}static fromObject(t){return w.from(Object.entries(t))}}var E=(t,e,s=[])=>{if(e.length===0||t==null)return[t,s];for(let n of t.keys())if(n!==""&&e.startsWith(n))return s.push([t,n]),E(t.get(n),e.slice(n.length),s);return s.push([t,e]),E(void 0,"",s)},A=(t,e)=>{if(e.length===0||t==null)return t;for(let s of t.keys())if(s!==""&&e.startsWith(s))return A(t.get(s),e.slice(s.length))},M=(t,e)=>{let s=e.length;t:for(let n=0;t&&n<s;){for(let r of t.keys())if(r!==""&&e[n]===r[0]){let c=Math.min(s-n,r.length),o=1;while(o<c&&e[n+o]===r[o])++o;let u=t.get(r);if(o===r.length)t=u;else{let d=new Map;d.set(r.slice(o),u),t.set(e.slice(n,n+o),d),t.delete(r),t=d}n+=o;continue t}let i=new Map;return t.set(e.slice(n),i),i}return t},Z=(t,e)=>{let[s,n]=E(t,e);if(s===void 0)return;if(s.delete(""),s.size===0)Q(n);else if(s.size===1){let[i,r]=s.entries().next().value;B(n,i,r)}},Q=(t)=>{if(t.length===0)return;let[e,s]=R(t);if(e.delete(s),e.size===0)Q(t.slice(0,-1));else if(e.size===1){let[n,i]=e.entries().next().value;if(n!=="")B(t.slice(0,-1),n,i)}},B=(t,e,s)=>{if(t.length===0)return;let[n,i]=R(t);n.set(i+e,s),n.delete(i)},R=(t)=>t[t.length-1],N="or",K="and",H="and_not";class x{constructor(t){if((t===null||t===void 0?void 0:t.fields)==null)throw Error('MiniSearch: option "fields" must be provided');let e=t.autoVacuum==null||t.autoVacuum===!0?C:t.autoVacuum;this._options={...V,...t,autoVacuum:e,searchOptions:{...P,...t.searchOptions||{}},autoSuggestOptions:{...nt,...t.autoSuggestOptions||{}}},this._index=new w,this._documentCount=0,this._documentIds=new Map,this._idToShortId=new Map,this._fieldIds={},this._fieldLength=new Map,this._avgFieldLength=[],this._nextId=0,this._storedFields=new Map,this._dirtCount=0,this._currentVacuum=null,this._enqueuedVacuum=null,this._enqueuedVacuumConditions=D,this.addFields(this._options.fields)}add(t){let{extractField:e,stringifyField:s,tokenize:n,processTerm:i,fields:r,idField:c}=this._options,o=e(t,c);if(o==null)throw Error(`MiniSearch: document does not have ID field "${c}"`);if(this._idToShortId.has(o))throw Error(`MiniSearch: duplicate ID ${o}`);let u=this.addDocumentId(o);this.saveStoredFields(u,t);for(let d of r){let a=e(t,d);if(a==null)continue;let h=n(s(a,d),d),f=this._fieldIds[d],m=new Set(h).size;this.addFieldLength(u,f,this._documentCount-1,m);for(let g of h){let l=i(g,d);if(Array.isArray(l))for(let _ of l)this.addTerm(f,u,_);else if(l)this.addTerm(f,u,l)}}}addAll(t){for(let e of t)this.add(e)}addAllAsync(t,e={}){let{chunkSize:s=10}=e,n={chunk:[],promise:Promise.resolve()},{chunk:i,promise:r}=t.reduce(({chunk:c,promise:o},u,d)=>{if(c.push(u),(d+1)%s===0)return{chunk:[],promise:o.then(()=>new Promise((a)=>setTimeout(a,0))).then(()=>this.addAll(c))};else return{chunk:c,promise:o}},n);return r.then(()=>this.addAll(i))}remove(t){let{tokenize:e,processTerm:s,extractField:n,stringifyField:i,fields:r,idField:c}=this._options,o=n(t,c);if(o==null)throw Error(`MiniSearch: document does not have ID field "${c}"`);let u=this._idToShortId.get(o);if(u==null)throw Error(`MiniSearch: cannot remove document with ID ${o}: it is not in the index`);for(let d of r){let a=n(t,d);if(a==null)continue;let h=e(i(a,d),d),f=this._fieldIds[d],m=new Set(h).size;this.removeFieldLength(u,f,this._documentCount,m);for(let g of h){let l=s(g,d);if(Array.isArray(l))for(let _ of l)this.removeTerm(f,u,_);else if(l)this.removeTerm(f,u,l)}}this._storedFields.delete(u),this._documentIds.delete(u),this._idToShortId.delete(o),this._fieldLength.delete(u),this._documentCount-=1}removeAll(t){if(t)for(let e of t)this.remove(e);else if(arguments.length>0)throw Error("Expected documents to be present. Omit the argument to remove all documents.");else this._index=new w,this._documentCount=0,this._documentIds=new Map,this._idToShortId=new Map,this._fieldLength=new Map,this._avgFieldLength=[],this._storedFields=new Map,this._nextId=0}discard(t){let e=this._idToShortId.get(t);if(e==null)throw Error(`MiniSearch: cannot discard document with ID ${t}: it is not in the index`);this._idToShortId.delete(t),this._documentIds.delete(e),this._storedFields.delete(e),(this._fieldLength.get(e)||[]).forEach((s,n)=>{this.removeFieldLength(e,n,this._documentCount,s)}),this._fieldLength.delete(e),this._documentCount-=1,this._dirtCount+=1,this.maybeAutoVacuum()}maybeAutoVacuum(){if(this._options.autoVacuum===!1)return;let{minDirtFactor:t,minDirtCount:e,batchSize:s,batchWait:n}=this._options.autoVacuum;this.conditionalVacuum({batchSize:s,batchWait:n},{minDirtCount:e,minDirtFactor:t})}discardAll(t){let e=this._options.autoVacuum;try{this._options.autoVacuum=!1;for(let s of t)this.discard(s)}finally{this._options.autoVacuum=e}this.maybeAutoVacuum()}replace(t){let{idField:e,extractField:s}=this._options,n=s(t,e);this.discard(n),this.add(t)}vacuum(t={}){return this.conditionalVacuum(t)}conditionalVacuum(t,e){if(this._currentVacuum){if(this._enqueuedVacuumConditions=this._enqueuedVacuumConditions&&e,this._enqueuedVacuum!=null)return this._enqueuedVacuum;return this._enqueuedVacuum=this._currentVacuum.then(()=>{let s=this._enqueuedVacuumConditions;return this._enqueuedVacuumConditions=D,this.performVacuuming(t,s)}),this._enqueuedVacuum}if(this.vacuumConditionsMet(e)===!1)return Promise.resolve();return this._currentVacuum=this.performVacuuming(t),this._currentVacuum}async performVacuuming(t,e){let s=this._dirtCount;if(this.vacuumConditionsMet(e)){let n=t.batchSize||T.batchSize,i=t.batchWait||T.batchWait,r=1;for(let[c,o]of this._index){for(let[u,d]of o)for(let[a]of d){if(this._documentIds.has(a))continue;if(d.size<=1)o.delete(u);else d.delete(a)}if(this._index.get(c).size===0)this._index.delete(c);if(r%n===0)await new Promise((u)=>setTimeout(u,i));r+=1}this._dirtCount-=s}await null,this._currentVacuum=this._enqueuedVacuum,this._enqueuedVacuum=null}vacuumConditionsMet(t){if(t==null)return!0;let{minDirtCount:e,minDirtFactor:s}=t;return e=e||C.minDirtCount,s=s||C.minDirtFactor,this.dirtCount>=e&&this.dirtFactor>=s}get isVacuuming(){return this._currentVacuum!=null}get dirtCount(){return this._dirtCount}get dirtFactor(){return this._dirtCount/(1+this._documentCount+this._dirtCount)}has(t){return this._idToShortId.has(t)}getStoredFields(t){let e=this._idToShortId.get(t);if(e==null)return;return this._storedFields.get(e)}search(t,e={}){let{searchOptions:s}=this._options,n={...s,...e},i=this.executeQuery(t,e),r=[];for(let[c,{score:o,terms:u,match:d}]of i){let a=u.length||1,h={id:this._documentIds.get(c),score:o*a,terms:Object.keys(d),queryTerms:u,match:d};if(Object.assign(h,this._storedFields.get(c)),n.filter==null||n.filter(h))r.push(h)}if(t===x.wildcard&&n.boostDocument==null)return r;return r.sort(J),r}autoSuggest(t,e={}){e={...this._options.autoSuggestOptions,...e};let s=new Map;for(let{score:i,terms:r}of this.search(t,e)){let c=r.join(" "),o=s.get(c);if(o!=null)o.score+=i,o.count+=1;else s.set(c,{score:i,terms:r,count:1})}let n=[];for(let[i,{score:r,terms:c,count:o}]of s)n.push({suggestion:i,terms:c,score:r/o});return n.sort(J),n}get documentCount(){return this._documentCount}get termCount(){return this._index.size}static loadJSON(t,e){if(e==null)throw Error("MiniSearch: loadJSON should be given the same options used when serializing the index");return this.loadJS(JSON.parse(t),e)}static async loadJSONAsync(t,e){if(e==null)throw Error("MiniSearch: loadJSON should be given the same options used when serializing the index");return this.loadJSAsync(JSON.parse(t),e)}static getDefault(t){if(V.hasOwnProperty(t))return O(V,t);else throw Error(`MiniSearch: unknown option "${t}"`)}static loadJS(t,e){let{index:s,documentIds:n,fieldLength:i,storedFields:r,serializationVersion:c}=t,o=this.instantiateMiniSearch(t,e);o._documentIds=b(n),o._fieldLength=b(i),o._storedFields=b(r);for(let[u,d]of o._documentIds)o._idToShortId.set(d,u);for(let[u,d]of s){let a=new Map;for(let h of Object.keys(d)){let f=d[h];if(c===1)f=f.ds;a.set(parseInt(h,10),b(f))}o._index.set(u,a)}return o}static async loadJSAsync(t,e){let{index:s,documentIds:n,fieldLength:i,storedFields:r,serializationVersion:c}=t,o=this.instantiateMiniSearch(t,e);o._documentIds=await v(n),o._fieldLength=await v(i),o._storedFields=await v(r);for(let[d,a]of o._documentIds)o._idToShortId.set(a,d);let u=0;for(let[d,a]of s){let h=new Map;for(let f of Object.keys(a)){let m=a[f];if(c===1)m=m.ds;h.set(parseInt(f,10),await v(m))}if(++u%1000===0)await Y(0);o._index.set(d,h)}return o}static instantiateMiniSearch(t,e){let{documentCount:s,nextId:n,fieldIds:i,averageFieldLength:r,dirtCount:c,serializationVersion:o}=t;if(o!==1&&o!==2)throw Error("MiniSearch: cannot deserialize an index created with an incompatible version");let u=new x(e);return u._documentCount=s,u._nextId=n,u._idToShortId=new Map,u._fieldIds=i,u._avgFieldLength=r,u._dirtCount=c||0,u._index=new w,u}executeQuery(t,e={}){if(t===x.wildcard)return this.executeWildcardQuery(e);if(typeof t!=="string"){let h={...e,...t,queries:void 0},f=t.queries.map((m)=>this.executeQuery(m,h));return this.combineResults(f,h.combineWith)}let{tokenize:s,processTerm:n,searchOptions:i}=this._options,r={tokenize:s,processTerm:n,...i,...e},{tokenize:c,processTerm:o}=r,a=c(t).flatMap((h)=>o(h)).filter((h)=>!!h).map(st(r)).map((h)=>this.executeQuerySpec(h,r));return this.combineResults(a,r.combineWith)}executeQuerySpec(t,e){let s={...this._options.searchOptions,...e},n=(s.fields||this._options.fields).reduce((g,l)=>({...g,[l]:O(s.boost,l)||1}),{}),{boostDocument:i,weights:r,maxFuzzy:c,bm25:o}=s,{fuzzy:u,prefix:d}={...P.weights,...r},a=this._index.get(t.term),h=this.termResults(t.term,t.term,1,t.termBoost,a,n,i,o),f,m;if(t.prefix)f=this._index.atPrefix(t.term);if(t.fuzzy){let g=t.fuzzy===!0?0.2:t.fuzzy,l=g<1?Math.min(c,Math.round(t.term.length*g)):g;if(l)m=this._index.fuzzyGet(t.term,l)}if(f)for(let[g,l]of f){let _=g.length-t.term.length;if(!_)continue;m===null||m===void 0||m.delete(g);let F=d*g.length/(g.length+0.3*_);this.termResults(t.term,g,F,t.termBoost,l,n,i,o,h)}if(m)for(let g of m.keys()){let[l,_]=m.get(g);if(!_)continue;let F=u*g.length/(g.length+_);this.termResults(t.term,g,F,t.termBoost,l,n,i,o,h)}return h}executeWildcardQuery(t){let e=new Map,s={...this._options.searchOptions,...t};for(let[n,i]of this._documentIds){let r=s.boostDocument?s.boostDocument(i,"",this._storedFields.get(n)):1;e.set(n,{score:r,terms:[],match:{}})}return e}combineResults(t,e=N){if(t.length===0)return new Map;let s=e.toLowerCase(),n=X[s];if(!n)throw Error(`Invalid combination operator: ${e}`);return t.reduce(n)||new Map}toJSON(){let t=[];for(let[e,s]of this._index){let n={};for(let[i,r]of s)n[i]=Object.fromEntries(r);t.push([e,n])}return{documentCount:this._documentCount,nextId:this._nextId,documentIds:Object.fromEntries(this._documentIds),fieldIds:this._fieldIds,fieldLength:Object.fromEntries(this._fieldLength),averageFieldLength:this._avgFieldLength,storedFields:Object.fromEntries(this._storedFields),dirtCount:this._dirtCount,index:t,serializationVersion:2}}termResults(t,e,s,n,i,r,c,o,u=new Map){if(i==null)return u;for(let d of Object.keys(r)){let a=r[d],h=this._fieldIds[d],f=i.get(h);if(f==null)continue;let m=f.size,g=this._avgFieldLength[h];for(let l of f.keys()){if(!this._documentIds.has(l)){this.removeTerm(h,l,e),m-=1;continue}let _=c?c(this._documentIds.get(l),e,this._storedFields.get(l)):1;if(!_)continue;let F=f.get(l),p=this._fieldLength.get(l)[h],k=et(F,m,this._documentCount,p,g,o),S=s*n*a*_*k,y=u.get(l);if(y){y.score+=S,it(y.terms,t);let I=O(y.match,e);if(I)I.push(d);else y.match[e]=[d]}else u.set(l,{score:S,terms:[t],match:{[e]:[d]}})}}return u}addTerm(t,e,s){let n=this._index.fetch(s,q),i=n.get(t);if(i==null)i=new Map,i.set(e,1),n.set(t,i);else{let r=i.get(e);i.set(e,(r||0)+1)}}removeTerm(t,e,s){if(!this._index.has(s)){this.warnDocumentChanged(e,t,s);return}let n=this._index.fetch(s,q),i=n.get(t);if(i==null||i.get(e)==null)this.warnDocumentChanged(e,t,s);else if(i.get(e)<=1)if(i.size<=1)n.delete(t);else i.delete(e);else i.set(e,i.get(e)-1);if(this._index.get(s).size===0)this._index.delete(s)}warnDocumentChanged(t,e,s){for(let n of Object.keys(this._fieldIds))if(this._fieldIds[n]===e){this._options.logger("warn",`MiniSearch: document with ID ${this._documentIds.get(t)} has changed before removal: term "${s}" was not present in field "${n}". Removing a document after it has changed can corrupt the index!`,"version_conflict");return}}addDocumentId(t){let e=this._nextId;return this._idToShortId.set(t,e),this._documentIds.set(e,t),this._documentCount+=1,this._nextId+=1,e}addFields(t){for(let e=0;e<t.length;e++)this._fieldIds[t[e]]=e}addFieldLength(t,e,s,n){let i=this._fieldLength.get(t);if(i==null)this._fieldLength.set(t,i=[]);i[e]=n;let c=(this._avgFieldLength[e]||0)*s+n;this._avgFieldLength[e]=c/(s+1)}removeFieldLength(t,e,s,n){if(s===1){this._avgFieldLength[e]=0;return}let i=this._avgFieldLength[e]*s-n;this._avgFieldLength[e]=i/(s-1)}saveStoredFields(t,e){let{storeFields:s,extractField:n}=this._options;if(s==null||s.length===0)return;let i=this._storedFields.get(t);if(i==null)this._storedFields.set(t,i={});for(let r of s){let c=n(e,r);if(c!==void 0)i[r]=c}}}x.wildcard=Symbol("*");var O=(t,e)=>Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0,X={[N]:(t,e)=>{for(let s of e.keys()){let n=t.get(s);if(n==null)t.set(s,e.get(s));else{let{score:i,terms:r,match:c}=e.get(s);n.score=n.score+i,n.match=Object.assign(n.match,c),W(n.terms,r)}}return t},[K]:(t,e)=>{let s=new Map;for(let n of e.keys()){let i=t.get(n);if(i==null)continue;let{score:r,terms:c,match:o}=e.get(n);W(i.terms,c),s.set(n,{score:i.score+r,terms:i.terms,match:Object.assign(i.match,o)})}return s},[H]:(t,e)=>{for(let s of e.keys())t.delete(s);return t}},tt={k:1.2,b:0.7,d:0.5},et=(t,e,s,n,i,r)=>{let{k:c,b:o,d:u}=r;return Math.log(1+(s-e+0.5)/(e+0.5))*(u+t*(c+1)/(t+c*(1-o+o*n/i)))},st=(t)=>(e,s,n)=>{let i=typeof t.fuzzy==="function"?t.fuzzy(e,s,n):t.fuzzy||!1,r=typeof t.prefix==="function"?t.prefix(e,s,n):t.prefix===!0,c=typeof t.boostTerm==="function"?t.boostTerm(e,s,n):1;return{term:e,fuzzy:i,prefix:r,termBoost:c}},V={idField:"id",extractField:(t,e)=>t[e],stringifyField:(t,e)=>t.toString(),tokenize:(t)=>t.split(ot),processTerm:(t)=>t.toLowerCase(),fields:void 0,searchOptions:void 0,storeFields:[],logger:(t,e)=>{if(typeof(console===null||console===void 0?void 0:console[t])==="function")console[t](e)},autoVacuum:!0},P={combineWith:N,prefix:!1,fuzzy:!1,maxFuzzy:6,boost:{},weights:{fuzzy:0.45,prefix:0.375},bm25:tt},nt={combineWith:K,prefix:(t,e,s)=>e===s.length-1},T={batchSize:1000,batchWait:10},D={minDirtFactor:0.1,minDirtCount:20},C={...T,...D},it=(t,e)=>{if(!t.includes(e))t.push(e)},W=(t,e)=>{for(let s of e)if(!t.includes(s))t.push(s)},J=({score:t},{score:e})=>e-t,q=()=>new Map,b=(t)=>{let e=new Map;for(let s of Object.keys(t))e.set(parseInt(s,10),t[s]);return e},v=async(t)=>{let e=new Map,s=0;for(let n of Object.keys(t))if(e.set(parseInt(n,10),t[n]),++s%1000===0)await Y(0);return e},Y=(t)=>new Promise((e)=>setTimeout(e,t)),ot=/[\n\r\p{Z}\p{P}]+/u;var rt=new Set(("a an and are as at be but by can do does for from how i if in is it its me my of on or so that the their them then there these this to was what when where which who why will with you your au aux avec ce ces comment dans de des du elle en est et il je la le les leur ma mais me mes "+"mon ne nous on ou où par pas pour qu que quel quelle quels qui sa se ses son sont sur ta te tu "+"un une vos votre vous y").split(" ")),ct=0.05,ut=(t)=>t.normalize("NFD").replace(/\p{M}/gu,"").toLowerCase();function dt(t){return t.chunks.map((e)=>{let s=t.docs[e.doc];return{...e,url:s?.url??"",title:s?.title??""}})}function It(t){let e=dt(t),s=new x({fields:["title","heading","text"],processTerm:(n)=>{let i=ut(n);return i.length<2||rt.has(i)?null:i},searchOptions:{prefix:(n)=>n.length>3,fuzzy:(n)=>n.length>4?0.15:0,boost:{title:2,heading:1.5}}});return s.addAll(e.map((n,i)=>({id:i,title:n.title,heading:n.heading,text:n.text}))),{async search(n,{limit:i=6,budgetTokens:r=3000}={}){let c=[],o=0,u=s.search(n,{combineWith:"OR"}),d=(u[0]?.score??0)*ct;for(let a of u){if(a.score<d)break;let h=e[Number(a.id)];if(!h)continue;let f=Ye(h.text)+24;if(o+f>r)continue;if(o+=f,c.push(h),c.length>=i)break}return c}}}
2
2
  export{It};
@@ -0,0 +1,9 @@
1
+ import{xt,pt,St}from"./embed-q6y6vgv1.js";var E="script,style,noscript,template,svg,canvas,iframe,nav,header,footer,aside,form,button,dialog,[hidden],[aria-hidden='true'],[data-murmur-ignore],murmur-chat",O="main,article,[role='main'],body",y=/^(P|LI|DT|DD|PRE|BLOCKQUOTE|TABLE|TR|FIGCAPTION|DIV|SECTION|ARTICLE|UL|OL|DL|MAIN|H[1-6])$/;function g(i,{root:l=O,exclude:o=E}={}){let r=l.split(",").map((t)=>i.querySelector(t.trim())).find((t)=>!!t),p=r?.querySelector("h1")?.textContent?.replace(/\s+/g," ").trim()||i.querySelector("title")?.textContent?.trim()||"";if(!r)return{title:p,sections:[]};let u=[],e={heading:"",anchor:"",text:""},d=new Map,f=(t)=>{if(t.nodeType===3){e.text+=(t.textContent??"").replace(/\s+/g," ");return}if(t.nodeType!==1)return;let n=t;if(n.matches(o))return;let s=n.tagName.toUpperCase();if(/^H[1-3]$/.test(s)){u.push(e);let c=(n.textContent??"").replace(/\s+/g," ").trim(),m=n.id||n.closest("[id]")?.id||"";if(!m){let a=pt(c),x=d.get(a)??0;d.set(a,x+1),m=x?`${a}-${x}`:a}e={heading:c,anchor:m,text:""};return}if(s==="BR")e.text+=`
2
+ `;let h=y.test(s);if(h)e.text+=`
3
+
4
+ `;if(s==="LI")e.text+="- ";for(let c of Array.from(n.childNodes))f(c);if(h)e.text+=`
5
+
6
+ `};for(let t of Array.from(r.childNodes))f(t);return u.push(e),{title:p,sections:u.map((t)=>({...t,text:t.text.replace(/[ \t]+\n/g,`
7
+ `).replace(/\n{3,}/g,`
8
+
9
+ `).trim()})).filter((t)=>t.text)}}function T(i,l=i.location?.href??"",o={}){let r=g(i,o);return St([{url:l,title:r.title,sections:r.sections}],o.maxChunk??xt)}export{T as indexDocument};
@@ -1,4 +1,4 @@
1
- import{Ct}from"./embed-n7jskdxd.js";import{It}from"./embed-we24qtes.js";import{Ye,qt,Nt,Lt}from"./embed-2xm309sb.js";function M(e,n){let t=[...n].reverse().find((s)=>s.role==="user");return Ye(e)<12&&t?`${t.content} ${e}`:e}function w(e){let n=e.retriever??(e.index?It(e.index):null)??(()=>{throw Error("murmur: pass `index` or `retriever`.")})();return{retriever:n,async ask(t,{history:s=[],signal:u}={}){let i={};if(e.limit!==void 0)i.limit=e.limit;if(e.budgetTokens!==void 0)i.budgetTokens=e.budgetTokens;let o=await n.search(M(t,s),i),d=[e.instructions?.trim(),Nt(e.language),o.length?`Sources:
1
+ import{Ct}from"./embed-n7jskdxd.js";import{It}from"./embed-pnm9593k.js";import{Ye,qt,Nt,Lt}from"./embed-2xm309sb.js";function M(e,n){let t=[...n].reverse().find((s)=>s.role==="user");return Ye(e)<12&&t?`${t.content} ${e}`:e}function w(e){let n=e.retriever??(e.index?It(e.index):null)??(()=>{throw Error("murmur: pass `index` or `retriever`.")})();return{retriever:n,async ask(t,{history:s=[],signal:u}={}){let i={};if(e.limit!==void 0)i.limit=e.limit;if(e.budgetTokens!==void 0)i.budgetTokens=e.budgetTokens;let o=await n.search(M(t,s),i),d=[e.instructions?.trim(),Nt(e.language),o.length?`Sources:
2
2
 
3
3
  ${qt(o)}`:"Sources: none matched this question. Say you could not find it on this site."].filter(Boolean).join(`
4
4
 
@@ -1,8 +1,8 @@
1
- import{G,gn,kt}from"./embed-2xm309sb.js";gn(import.meta.url,["d1gkys45","11c9cspb","e0j28zmb","zrmby2xc","5vkc01ns","k9mmdcz5","e5entetm","2xm309sb","hn0r8fmg","q6y6vgv1","n7jskdxd","we24qtes","t87kf8t0","dhy4fp4c","w7nkjk5e","qha5xyx4","16bekg8b","za7hc1fv","kk9hgxdc","sgjh2kg2","59r4jck6"],[["./murmur.js",7],["./index-11c9cspb.js",8],["./chunk-e0j28zmb.js",9],["./index-zrmby2xc.js",9],["./murmur-5vkc01ns.js",10,11,7],["./retriever-k9mmdcz5.js",11],["./index-e5entetm.js",8],["./embed-2xm309sb.js"],["./embed-hn0r8fmg.js",7],["./embed-q6y6vgv1.js"],["./embed-n7jskdxd.js",7,19],["./embed-we24qtes.js",7],["./browser-t87kf8t0.js"],["./openai-dhy4fp4c.js",8,7,19],["./anthropic-w7nkjk5e.js",8,20,19],["./google-qha5xyx4.js",8,20,19],["./mistral-16bekg8b.js",8,19],["./openai-compatible-za7hc1fv.js",8,19],["./index-kk9hgxdc.js",10],["./embed-sgjh2kg2.js"],["./embed-59r4jck6.js",19]],0);
1
+ import{G,gn,kt}from"./embed-2xm309sb.js";gn(import.meta.url,["5fjz22kb","11c9cspb","e0j28zmb","hv290nbv","bnm335nb","m8peqj5t","e5entetm","2xm309sb","hn0r8fmg","q6y6vgv1","n7jskdxd","pnm9593k","t87kf8t0","dhy4fp4c","w7nkjk5e","qha5xyx4","16bekg8b","za7hc1fv","kk9hgxdc","sgjh2kg2","59r4jck6"],[["./murmur.js",7],["./index-11c9cspb.js",8],["./chunk-e0j28zmb.js",9],["./index-hv290nbv.js",9],["./murmur-bnm335nb.js",10,11,7],["./retriever-m8peqj5t.js",11],["./index-e5entetm.js",8],["./embed-2xm309sb.js"],["./embed-hn0r8fmg.js",7],["./embed-q6y6vgv1.js"],["./embed-n7jskdxd.js",7,19],["./embed-pnm9593k.js",7],["./browser-t87kf8t0.js"],["./openai-dhy4fp4c.js",8,7,19],["./anthropic-w7nkjk5e.js",8,20,19],["./google-qha5xyx4.js",8,20,19],["./mistral-16bekg8b.js",8,19],["./openai-compatible-za7hc1fv.js",8,19],["./index-kk9hgxdc.js",10],["./embed-sgjh2kg2.js"],["./embed-59r4jck6.js",19]],0);
2
2
  var F={open:"Ask a question",close:"Close",title:"Ask this site",greeting:"Hi! Ask me anything about this site. I answer from its pages and link to them.",placeholder:"Your question…",send:"Send",stop:"Stop",settings:"AI settings",back:"Back to chat",sources:"Sources",notFound:"Nothing on this site matched. Try other words?",thinking:"Looking through the site…",newChat:"New conversation",poweredBy:"Answers from this site's pages, by murmur",errorAuth:"The key was refused. Check it in the AI settings.",errorNetwork:"No answer from the AI provider: key refused or network down.",errorRate:"The AI provider is busy or rate-limited. Try again in a moment.",errorOther:"The answer failed:",retry:"Try again",setupTitle:"Connect an AI model",setupIntro:"This site lets you use your own AI key. It stays in your browser, encrypted, and is only sent to the provider you pick.",provider:"Provider",model:"Model",apiKey:"API key",apiKeyHint:"Sent only to the provider, never to this site.",remember:"Remember on this device",local:"Local server (Ollama, LM Studio)",localHint:"The server must allow this site's origin (CORS).",endpoint:"Server URL",test:"Test",testing:"Testing…",testOk:"Connected.",testFail:"Connection failed:",save:"Save and chat",forget:"Forget my key",loadingCatalog:"Loading models…",catalogError:"Could not load the model list.",searchModels:"Search models",recommended:"Recommended",otherProviders:"Other providers"},Z={open:"Poser une question",close:"Fermer",title:"Demandez au site",greeting:"Bonjour ! Posez-moi une question sur ce site. Je réponds à partir de ses pages, avec les liens.",placeholder:"Votre question…",send:"Envoyer",stop:"Arrêter",settings:"Réglages IA",back:"Retour au chat",sources:"Sources",notFound:"Rien sur ce site ne correspond. Essayez d'autres mots ?",thinking:"Je cherche dans le site…",newChat:"Nouvelle conversation",poweredBy:"Réponses tirées des pages de ce site, par murmur",errorAuth:"La clé a été refusée. Vérifiez-la dans les réglages IA.",errorNetwork:"Pas de réponse du fournisseur d'IA : clé refusée ou réseau coupé.",errorRate:"Le fournisseur d'IA est saturé ou limite les appels. Réessayez dans un instant.",errorOther:"La réponse a échoué :",retry:"Réessayer",setupTitle:"Connecter un modèle d'IA",setupIntro:"Ce site vous laisse utiliser votre propre clé d'IA. Elle reste dans votre navigateur, chiffrée, et n'est envoyée qu'au fournisseur choisi.",provider:"Fournisseur",model:"Modèle",apiKey:"Clé API",apiKeyHint:"Envoyée uniquement au fournisseur, jamais à ce site.",remember:"Mémoriser sur cet appareil",local:"Serveur local (Ollama, LM Studio)",localHint:"Le serveur doit autoriser l'origine de ce site (CORS).",endpoint:"URL du serveur",test:"Tester",testing:"Test…",testOk:"Connecté.",testFail:"Échec de la connexion :",save:"Enregistrer et discuter",forget:"Oublier ma clé",loadingCatalog:"Chargement des modèles…",catalogError:"Impossible de charger la liste des modèles.",searchModels:"Chercher un modèle",recommended:"Recommandés",otherProviders:"Autres fournisseurs"},V={en:F,fr:Z};function j(...e){for(let n of e){let i=n?.toLowerCase().split(/[-_]/)[0];if(i&&i in V)return i}return"en"}function P(e,n={}){return{...V[e]??F,...n}}var Q={chat:'<path d="M4 6.5A2.5 2.5 0 0 1 6.5 4h11A2.5 2.5 0 0 1 20 6.5v7a2.5 2.5 0 0 1-2.5 2.5H10l-4.2 3.4c-.5.4-1.3 0-1.3-.6V6.5Z"/><path d="M8.5 9h7M8.5 12h4.5"/>',close:'<path d="M6 6l12 12M18 6 6 18"/>',send:'<path d="M12 19V5M6 11l6-6 6 6"/>',stop:'<rect x="7" y="7" width="10" height="10" rx="1.5"/>',settings:'<path d="M4 7h9M17 7h3M4 17h3M11 17h9"/><circle cx="15" cy="7" r="2"/><circle cx="9" cy="17" r="2"/>',reset:'<path d="M5 12a7 7 0 1 0 2.1-5"/><path d="M5 4.5V8h3.5"/>',back:'<path d="M14.5 6 8.5 12l6 6"/>',check:'<path d="m5.5 12.5 4 4 9-9"/>',key:'<circle cx="8" cy="15" r="3.5"/><path d="m10.5 12.5 8-8M16 7l2 2M14 9l1.5 1.5"/>'};function R(e,n){let i=e.createElement("template");return i.innerHTML=`<svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">${Q[n]??""}</svg>`,i.content.firstElementChild}var X=/^(https?:\/\/|\/|#|\.\/|mailto:)/i;function k(e,n,i,t){let s=/(`[^`]+`)|(\*\*[^*]+\*\*)|(\*[^*\s][^*]*\*|_[^_\s][^_]*_)|(\[[^\]]+\]\([^)\s]+\))|(\[\d{1,2}\])/g,a=0;for(let c of n.matchAll(s)){let p=c.index??0;if(p>a)t.appendChild(e.createTextNode(n.slice(a,p)));a=p+c[0].length;let o=c[0];if(c[1]){let l=e.createElement("code");l.textContent=o.slice(1,-1),t.appendChild(l)}else if(c[2]){let l=e.createElement("strong");k(e,o.slice(2,-2),i,l),t.appendChild(l)}else if(c[3]){let l=e.createElement("em");k(e,o.slice(1,-1),i,l),t.appendChild(l)}else if(c[4]){let l=o.indexOf("]("),d=o.slice(1,l),u=o.slice(l+2,-1);if(X.test(u)){let h=e.createElement("a");if(h.href=u,h.textContent=d,/^https?:/i.test(u))h.target="_blank",h.rel="noopener noreferrer";t.appendChild(h)}else t.appendChild(e.createTextNode(d))}else{let l=i(Number(o.slice(1,-1)));t.appendChild(l??e.createTextNode(o))}}if(a<n.length)t.appendChild(e.createTextNode(n.slice(a)))}function U(e,n,i){let t=e.ownerDocument,s=t.createDocumentFragment(),a=n.replace(/\r\n?/g,`
3
3
  `).split(`
4
4
  `),c=[],p=null,o=()=>{if(!c.length)return;let d=t.createElement("p");k(t,c.join(" "),i,d),s.appendChild(d),c=[]},l=()=>{p=null};for(let d=0;d<a.length;d++){let u=a[d]??"";if(/^\s*```/.exec(u)){o(),l();let m=[];for(d++;d<a.length&&!/^\s*```/.test(a[d]??"");d++)m.push(a[d]??"");let x=t.createElement("pre");x.tabIndex=0;let M=t.createElement("code");M.textContent=m.join(`
5
- `),x.appendChild(M),s.appendChild(x);continue}let b=/^\s*(?:([-*+])|(\d+)[.)])\s+(.*)$/.exec(u);if(b){o();let m=b[1]?"ul":"ol";if(!p||p.tagName.toLowerCase()!==m)p=t.createElement(m),s.appendChild(p);let x=t.createElement("li");k(t,b[3]??"",i,x),p.appendChild(x);continue}let f=/^\s*#{1,6}\s+(.*)$/.exec(u);if(f){o(),l();let m=t.createElement("p"),x=t.createElement("strong");k(t,f[1]??"",i,x),m.appendChild(x),s.appendChild(m);continue}if(!u.trim()){o(),l();continue}if(p&&/^\s{2,}\S/.test(u)){let m=p.lastElementChild;if(m){m.appendChild(t.createTextNode(" ")),k(t,u.trim(),i,m);continue}}l(),c.push(u.trim())}o(),e.replaceChildren(s)}class O{options;turns=[];engine=null;storePromise=null;historyKey;constructor(e){this.options=e;this.historyKey=`${e.storageKey??"murmur"}-chat:${location.pathname.split("/")[1]??""}`;try{let n=sessionStorage.getItem(this.historyKey);if(n)this.turns=JSON.parse(n)}catch{this.turns=[]}}get mode(){if(this.options.model)return"custom";return this.options.llm?.endpoint?"proxy":"visitor"}persist(){try{sessionStorage.setItem(this.historyKey,JSON.stringify(this.turns.slice(-30)))}catch{}}clear(){this.turns=[],this.persist()}store(){return this.storePromise??=(G("11c9cspb"),import("./index-11c9cspb.js")).then((e)=>{let n={};if(this.options.catalogUrl)n.catalogUrl=this.options.catalogUrl;if(this.options.storageKey)n.storageKey=this.options.storageKey;return e.visitorStore(this.options.llm??{},n)}),this.storePromise}async settings(){if(this.mode==="custom")return null;let e=await (G("11c9cspb"),import("./index-11c9cspb.js"));return e.resolveSettings(this.options.llm??{},this.mode==="visitor"?await this.store():null)}async needsSetup(){return this.mode==="visitor"&&!await this.settings()}async loadIndex(){let{index:e}=this.options;if(e&&typeof e!=="string")return e;let{isMurmurIndex:n}=await (G("e0j28zmb"),import("./chunk-e0j28zmb.js"));if(e){let t=await fetch(new URL(e,location.href));if(!t.ok)throw Error(`murmur: index ${t.status}`);let s=await t.json();if(!n(s))throw Error("murmur: not a murmur index");return s}let{indexDocument:i}=await (G("zrmby2xc"),import("./index-zrmby2xc.js"));return i(document,location.pathname+location.search)}createEngine(){return(async()=>{let[{createMurmur:e},n]=await Promise.all([(G("5vkc01ns"),import("./murmur-5vkc01ns.js")),this.options.retriever??(G("k9mmdcz5"),import("./retriever-k9mmdcz5.js")).then(async(s)=>s.bm25Retriever(await this.loadIndex()))]),i=this.options.model??(async()=>{let s=await this.settings();if(!s)throw new L;let{loadModel:a}=await (G("11c9cspb"),import("./index-11c9cspb.js"));return a(s)}),t={retriever:n,model:i};if(this.options.instructions)t.instructions=this.options.instructions;if(this.options.lang)t.language=this.options.lang;return e(t)})()}async ask(e,n,i){let t=this.turns.filter((a)=>!a.error).map(({role:a,content:c})=>({role:a,content:c}));this.turns.push({role:"user",content:e});let s={role:"assistant",content:""};this.turns.push(s),this.persist();try{this.engine??=this.createEngine();let c=await(await this.engine.catch((p)=>{throw this.engine=null,p})).ask(e,{history:t,signal:i});s.passages=c.passages.map(({url:p,anchor:o,title:l,heading:d})=>({url:p,anchor:o,title:l,heading:d}));for await(let p of c.textStream)s.content+=p,n(s.content,s);s.cited=(await c.done).cited}catch(a){if(i.aborted)s.cited=[];else if(a instanceof L)throw this.turns.splice(-2,2),a;else s.error=await this.describe(a)}finally{this.persist()}return s}async describe(e){try{let{describeError:n}=await (G("11c9cspb"),import("./index-11c9cspb.js")),i=this.mode==="custom"?null:await this.settings(),t=n(e,i?.apiKey);return`${t.code}|${t.message}`}catch{return`unknown|${e instanceof Error?e.message:String(e)}`}}}class L extends Error{constructor(){super("murmur: no model set up")}}var W=`
5
+ `),x.appendChild(M),s.appendChild(x);continue}let b=/^\s*(?:([-*+])|(\d+)[.)])\s+(.*)$/.exec(u);if(b){o();let m=b[1]?"ul":"ol";if(!p||p.tagName.toLowerCase()!==m)p=t.createElement(m),s.appendChild(p);let x=t.createElement("li");k(t,b[3]??"",i,x),p.appendChild(x);continue}let f=/^\s*#{1,6}\s+(.*)$/.exec(u);if(f){o(),l();let m=t.createElement("p"),x=t.createElement("strong");k(t,f[1]??"",i,x),m.appendChild(x),s.appendChild(m);continue}if(!u.trim()){o(),l();continue}if(p&&/^\s{2,}\S/.test(u)){let m=p.lastElementChild;if(m){m.appendChild(t.createTextNode(" ")),k(t,u.trim(),i,m);continue}}l(),c.push(u.trim())}o(),e.replaceChildren(s)}class O{options;turns=[];engine=null;storePromise=null;historyKey;constructor(e){this.options=e;this.historyKey=`${e.storageKey??"murmur"}-chat:${location.pathname.split("/")[1]??""}`;try{let n=sessionStorage.getItem(this.historyKey);if(n)this.turns=JSON.parse(n)}catch{this.turns=[]}}get mode(){if(this.options.model)return"custom";return this.options.llm?.endpoint?"proxy":"visitor"}persist(){try{sessionStorage.setItem(this.historyKey,JSON.stringify(this.turns.slice(-30)))}catch{}}clear(){this.turns=[],this.persist()}store(){return this.storePromise??=(G("11c9cspb"),import("./index-11c9cspb.js")).then((e)=>{let n={};if(this.options.catalogUrl)n.catalogUrl=this.options.catalogUrl;if(this.options.storageKey)n.storageKey=this.options.storageKey;return e.visitorStore(this.options.llm??{},n)}),this.storePromise}async settings(){if(this.mode==="custom")return null;let e=await (G("11c9cspb"),import("./index-11c9cspb.js"));return e.resolveSettings(this.options.llm??{},this.mode==="visitor"?await this.store():null)}async needsSetup(){return this.mode==="visitor"&&!await this.settings()}async loadIndex(){let{index:e}=this.options;if(e&&typeof e!=="string")return e;let{isMurmurIndex:n}=await (G("e0j28zmb"),import("./chunk-e0j28zmb.js"));if(e){let t=await fetch(new URL(e,location.href));if(!t.ok)throw Error(`murmur: index ${t.status}`);let s=await t.json();if(!n(s))throw Error("murmur: not a murmur index");return s}let{indexDocument:i}=await (G("hv290nbv"),import("./index-hv290nbv.js"));return i(document,location.pathname+location.search)}createEngine(){return(async()=>{let[{createMurmur:e},n]=await Promise.all([(G("bnm335nb"),import("./murmur-bnm335nb.js")),this.options.retriever??(G("m8peqj5t"),import("./retriever-m8peqj5t.js")).then(async(s)=>s.bm25Retriever(await this.loadIndex()))]),i=this.options.model??(async()=>{let s=await this.settings();if(!s)throw new L;let{loadModel:a}=await (G("11c9cspb"),import("./index-11c9cspb.js"));return a(s)}),t={retriever:n,model:i};if(this.options.instructions)t.instructions=this.options.instructions;if(this.options.lang)t.language=this.options.lang;return e(t)})()}async ask(e,n,i){let t=this.turns.filter((a)=>!a.error).map(({role:a,content:c})=>({role:a,content:c}));this.turns.push({role:"user",content:e});let s={role:"assistant",content:""};this.turns.push(s),this.persist();try{this.engine??=this.createEngine();let c=await(await this.engine.catch((p)=>{throw this.engine=null,p})).ask(e,{history:t,signal:i});s.passages=c.passages.map(({url:p,anchor:o,title:l,heading:d})=>({url:p,anchor:o,title:l,heading:d}));for await(let p of c.textStream)s.content+=p,n(s.content,s);s.cited=(await c.done).cited}catch(a){if(i.aborted)s.cited=[];else if(a instanceof L)throw this.turns.splice(-2,2),a;else s.error=await this.describe(a)}finally{this.persist()}return s}async describe(e){try{let{describeError:n}=await (G("11c9cspb"),import("./index-11c9cspb.js")),i=this.mode==="custom"?null:await this.settings(),t=n(e,i?.apiKey);return`${t.code}|${t.message}`}catch{return`unknown|${e instanceof Error?e.message:String(e)}`}}}class L extends Error{constructor(){super("murmur: no model set up")}}var W=`
6
6
  :host {
7
7
  --accent: var(--murmur-accent, #211c17);
8
8
  --accent-ink: var(--murmur-accent-ink, #f6efe0);
@@ -0,0 +1 @@
1
+ import{It}from"./embed-pnm9593k.js";export{It as bm25Retriever};
package/dist/cli.js CHANGED
@@ -99,7 +99,7 @@ function extractSections(doc, { root = DEFAULT_ROOT, exclude = DEFAULT_EXCLUDE }
99
99
  return { title, sections: [] };
100
100
  const sections = [];
101
101
  let cur = { heading: "", anchor: "", text: "" };
102
- const used = new Set;
102
+ const slugs = new Map;
103
103
  const walk = (node) => {
104
104
  if (node.nodeType === 3) {
105
105
  cur.text += (node.textContent ?? "").replace(/\s+/g, " ");
@@ -114,10 +114,13 @@ function extractSections(doc, { root = DEFAULT_ROOT, exclude = DEFAULT_EXCLUDE }
114
114
  if (/^H[1-3]$/.test(tag)) {
115
115
  sections.push(cur);
116
116
  const heading = (el.textContent ?? "").replace(/\s+/g, " ").trim();
117
- let anchor = el.id || el.closest("[id]")?.id || slugify(heading);
118
- while (used.has(anchor))
119
- anchor += "-";
120
- used.add(anchor);
117
+ let anchor = el.id || el.closest("[id]")?.id || "";
118
+ if (!anchor) {
119
+ const base = slugify(heading);
120
+ const n = slugs.get(base) ?? 0;
121
+ slugs.set(base, n + 1);
122
+ anchor = n ? `${base}-${n}` : base;
123
+ }
121
124
  cur = { heading, anchor, text: "" };
122
125
  return;
123
126
  }
@@ -4,6 +4,8 @@ import {
4
4
 
5
5
  // src/rag/retriever.ts
6
6
  import MiniSearch from "minisearch";
7
+ var STOPWORDS = new Set(("a an and are as at be but by can do does for from how i if in is it its me my of on or so that the " + "their them then there these this to was what when where which who why will with you your " + "au aux avec ce ces comment dans de des du elle en est et il je la le les leur ma mais me mes " + "mon ne nous on ou où par pas pour qu que quel quelle quels qui sa se ses son sont sur ta te tu " + "un une vos votre vous y").split(" "));
8
+ var MIN_RELATIVE_SCORE = 0.05;
7
9
  var fold = (s) => s.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase();
8
10
  function passagesOf2(index) {
9
11
  return index.chunks.map((c) => {
@@ -15,15 +17,26 @@ function bm25Retriever2(index) {
15
17
  const passages = passagesOf2(index);
16
18
  const engine = new MiniSearch({
17
19
  fields: ["title", "heading", "text"],
18
- processTerm: (t) => fold(t),
19
- searchOptions: { prefix: true, fuzzy: 0.15, boost: { title: 2, heading: 1.5 } }
20
+ processTerm: (t) => {
21
+ const term = fold(t);
22
+ return term.length < 2 || STOPWORDS.has(term) ? null : term;
23
+ },
24
+ searchOptions: {
25
+ prefix: (term) => term.length > 3,
26
+ fuzzy: (term) => term.length > 4 ? 0.15 : 0,
27
+ boost: { title: 2, heading: 1.5 }
28
+ }
20
29
  });
21
30
  engine.addAll(passages.map((p, id) => ({ id, title: p.title, heading: p.heading, text: p.text })));
22
31
  return {
23
32
  async search(query, { limit = 6, budgetTokens = 3000 } = {}) {
24
33
  const out = [];
25
34
  let used = 0;
26
- for (const hit of engine.search(query, { combineWith: "OR" })) {
35
+ const hits = engine.search(query, { combineWith: "OR" });
36
+ const floor = (hits[0]?.score ?? 0) * MIN_RELATIVE_SCORE;
37
+ for (const hit of hits) {
38
+ if (hit.score < floor)
39
+ break;
27
40
  const p = passages[Number(hit.id)];
28
41
  if (!p)
29
42
  continue;
@@ -341,14 +341,14 @@ class ChatSession {
341
341
  throw new Error("murmur: not a murmur index");
342
342
  return data;
343
343
  }
344
- const { indexDocument } = await (__preload("hp2p9tp9"), import("../indexer/index.js"));
344
+ const { indexDocument } = await (__preload("gp7czjd1"), import("../indexer/index.js"));
345
345
  return indexDocument(document, location.pathname + location.search);
346
346
  }
347
347
  createEngine() {
348
348
  return (async () => {
349
349
  const [{ createMurmur }, retriever] = await Promise.all([
350
- (__preload("wq1d15n7"), import("./murmur-wq1d15n7.js")),
351
- this.options.retriever ?? (__preload("1rw4z2n6"), import("./retriever-1rw4z2n6.js")).then(async (r) => r.bm25Retriever(await this.loadIndex()))
350
+ (__preload("c1c79eh8"), import("./murmur-c1c79eh8.js")),
351
+ this.options.retriever ?? (__preload("h8nz6jsc"), import("./retriever-h8nz6jsc.js")).then(async (r) => r.bm25Retriever(await this.loadIndex()))
352
352
  ]);
353
353
  const model = this.options.model ?? (async () => {
354
354
  const settings = await this.settings();
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  bm25Retriever2
3
- } from "./index-z8pn9sdj.js";
3
+ } from "./index-10g918kt.js";
4
4
  import {
5
5
  estimateTokens2,
6
6
  formatSources2,
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  searchQuery2,
3
3
  createMurmur2
4
- } from "./index-fs6gmhz9.js";
5
- import"./index-z8pn9sdj.js";
4
+ } from "./index-ynjdey8j.js";
5
+ import"./index-10g918kt.js";
6
6
  export {
7
7
  createMurmur2 as createMurmur,
8
8
  searchQuery2 as searchQuery
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  passagesOf2,
3
3
  bm25Retriever2
4
- } from "./index-z8pn9sdj.js";
4
+ } from "./index-10g918kt.js";
5
5
  export {
6
6
  bm25Retriever2 as bm25Retriever,
7
7
  passagesOf2 as passagesOf
package/dist/lib/embed.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  __chunks,
3
3
  mountMurmur2
4
- } from "./chunks/index-0x7gav29.js";
5
- __chunks(import.meta.url,["9w5px1fq","0x7gav29","1rw4z2n6","hp2p9tp9","vb9smwta","kaeec41p","wq1d15n7","6re28wc1","z8pn9sdj","1zk822m5","fs6gmhz9"],[["./embed.js",1],["./chunks/index-0x7gav29.js",7],["./chunks/retriever-1rw4z2n6.js",8],["./indexer/index.js",9],["./llm/index.js"],["./chunks/chunk-kaeec41p.js",9],["./chunks/murmur-wq1d15n7.js",10,8],["./chunks/index-6re28wc1.js"],["./chunks/index-z8pn9sdj.js",7],["./chunks/index-1zk822m5.js"],["./chunks/index-fs6gmhz9.js",8,7]],0);
4
+ } from "./chunks/index-4at214g0.js";
5
+ __chunks(import.meta.url,["3qtg95t7","4at214g0","h8nz6jsc","gp7czjd1","vb9smwta","kaeec41p","c1c79eh8","6re28wc1","10g918kt","1zk822m5","ynjdey8j"],[["./embed.js",1],["./chunks/index-4at214g0.js",7],["./chunks/retriever-h8nz6jsc.js",8],["./indexer/index.js",9],["./llm/index.js"],["./chunks/chunk-kaeec41p.js",9],["./chunks/murmur-c1c79eh8.js",10,8],["./chunks/index-6re28wc1.js"],["./chunks/index-10g918kt.js",7],["./chunks/index-1zk822m5.js"],["./chunks/index-ynjdey8j.js",8,7]],0);
6
6
 
7
7
  // src/embed.ts
8
8
  function optionsFromDataset(data, base) {
package/dist/lib/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  passagesOf2,
3
3
  bm25Retriever2
4
- } from "./chunks/index-z8pn9sdj.js";
4
+ } from "./chunks/index-10g918kt.js";
5
5
  import {
6
6
  searchQuery2,
7
7
  createMurmur2
8
- } from "./chunks/index-fs6gmhz9.js";
8
+ } from "./chunks/index-ynjdey8j.js";
9
9
  import {
10
10
  MAX_CHUNK2,
11
11
  splitText2,
@@ -16,7 +16,7 @@ function extractSections(doc, { root = DEFAULT_ROOT, exclude = DEFAULT_EXCLUDE }
16
16
  return { title, sections: [] };
17
17
  const sections = [];
18
18
  let cur = { heading: "", anchor: "", text: "" };
19
- const used = new Set;
19
+ const slugs = new Map;
20
20
  const walk = (node) => {
21
21
  if (node.nodeType === 3) {
22
22
  cur.text += (node.textContent ?? "").replace(/\s+/g, " ");
@@ -31,10 +31,13 @@ function extractSections(doc, { root = DEFAULT_ROOT, exclude = DEFAULT_EXCLUDE }
31
31
  if (/^H[1-3]$/.test(tag)) {
32
32
  sections.push(cur);
33
33
  const heading = (el.textContent ?? "").replace(/\s+/g, " ").trim();
34
- let anchor = el.id || el.closest("[id]")?.id || slugify2(heading);
35
- while (used.has(anchor))
36
- anchor += "-";
37
- used.add(anchor);
34
+ let anchor = el.id || el.closest("[id]")?.id || "";
35
+ if (!anchor) {
36
+ const base = slugify2(heading);
37
+ const n = slugs.get(base) ?? 0;
38
+ slugs.set(base, n + 1);
39
+ anchor = n ? `${base}-${n}` : base;
40
+ }
38
41
  cur = { heading, anchor, text: "" };
39
42
  return;
40
43
  }
@@ -11,7 +11,7 @@ import {
11
11
  import {
12
12
  passagesOf2,
13
13
  bm25Retriever2
14
- } from "../chunks/index-z8pn9sdj.js";
14
+ } from "../chunks/index-10g918kt.js";
15
15
  import {
16
16
  estimateTokens2,
17
17
  formatSources2,
@@ -8,8 +8,8 @@ import {
8
8
  MurmurChat2,
9
9
  defineMurmurChat2,
10
10
  mountMurmur2
11
- } from "../chunks/index-0x7gav29.js";
12
- __chunks(import.meta.url,["988ctnns","0x7gav29","1rw4z2n6","hp2p9tp9","vb9smwta","kaeec41p","wq1d15n7","6re28wc1","z8pn9sdj","1zk822m5","fs6gmhz9"],[["./index.js",1],["../chunks/index-0x7gav29.js",7],["../chunks/retriever-1rw4z2n6.js",8],["../indexer/index.js",9],["../llm/index.js"],["../chunks/chunk-kaeec41p.js",9],["../chunks/murmur-wq1d15n7.js",10,8],["../chunks/index-6re28wc1.js"],["../chunks/index-z8pn9sdj.js",7],["../chunks/index-1zk822m5.js"],["../chunks/index-fs6gmhz9.js",8,7]],0);
11
+ } from "../chunks/index-4at214g0.js";
12
+ __chunks(import.meta.url,["1ykj7t4p","4at214g0","h8nz6jsc","gp7czjd1","vb9smwta","kaeec41p","c1c79eh8","6re28wc1","10g918kt","1zk822m5","ynjdey8j"],[["./index.js",1],["../chunks/index-4at214g0.js",7],["../chunks/retriever-h8nz6jsc.js",8],["../indexer/index.js",9],["../llm/index.js"],["../chunks/chunk-kaeec41p.js",9],["../chunks/murmur-c1c79eh8.js",10,8],["../chunks/index-6re28wc1.js"],["../chunks/index-10g918kt.js",7],["../chunks/index-1zk822m5.js"],["../chunks/index-ynjdey8j.js",8,7]],0);
13
13
  export {
14
14
  MESSAGES2 as MESSAGES,
15
15
  MurmurChat2 as MurmurChat,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "murmur-rag",
3
- "version": "0.1.2",
3
+ "version": "1.0.0",
4
4
  "description": "Embeddable AI chat for static sites: one script tag, a mini RAG over your own pages, any LLM through llm-connect (your proxy or the visitor's own key). No backend.",
5
5
  "author": "maxgfr",
6
6
  "license": "MIT",
@@ -111,6 +111,7 @@
111
111
  "@playwright/test": "^1.64.1",
112
112
  "@semantic-release/exec": "^7.1.0",
113
113
  "@types/bun": "^1.4.4",
114
+ "conventional-changelog-conventionalcommits": "^9",
114
115
  "semantic-release": "^25.0.9",
115
116
  "typescript": "^7.0.2"
116
117
  }
@@ -1,9 +0,0 @@
1
- import{xt,pt,St}from"./embed-q6y6vgv1.js";var h="script,style,noscript,template,svg,canvas,iframe,nav,header,footer,aside,form,button,dialog,[hidden],[aria-hidden='true'],[data-murmur-ignore],murmur-chat",E="main,article,[role='main'],body",O=/^(P|LI|DT|DD|PRE|BLOCKQUOTE|TABLE|TR|FIGCAPTION|DIV|SECTION|ARTICLE|UL|OL|DL|MAIN|H[1-6])$/;function f(i,{root:l=E,exclude:o=h}={}){let r=l.split(",").map((t)=>i.querySelector(t.trim())).find((t)=>!!t),m=r?.querySelector("h1")?.textContent?.replace(/\s+/g," ").trim()||i.querySelector("title")?.textContent?.trim()||"";if(!r)return{title:m,sections:[]};let u=[],e={heading:"",anchor:"",text:""},x=new Set,d=(t)=>{if(t.nodeType===3){e.text+=(t.textContent??"").replace(/\s+/g," ");return}if(t.nodeType!==1)return;let n=t;if(n.matches(o))return;let s=n.tagName.toUpperCase();if(/^H[1-3]$/.test(s)){u.push(e);let c=(n.textContent??"").replace(/\s+/g," ").trim(),a=n.id||n.closest("[id]")?.id||pt(c);while(x.has(a))a+="-";x.add(a),e={heading:c,anchor:a,text:""};return}if(s==="BR")e.text+=`
2
- `;let p=O.test(s);if(p)e.text+=`
3
-
4
- `;if(s==="LI")e.text+="- ";for(let c of Array.from(n.childNodes))d(c);if(p)e.text+=`
5
-
6
- `};for(let t of Array.from(r.childNodes))d(t);return u.push(e),{title:m,sections:u.map((t)=>({...t,text:t.text.replace(/[ \t]+\n/g,`
7
- `).replace(/\n{3,}/g,`
8
-
9
- `).trim()})).filter((t)=>t.text)}}function S(i,l=i.location?.href??"",o={}){let r=f(i,o);return St([{url:l,title:r.title,sections:r.sections}],o.maxChunk??xt)}export{S as indexDocument};
@@ -1 +0,0 @@
1
- import{It}from"./embed-we24qtes.js";export{It as bm25Retriever};