diff --git a/core/rag-processor.js b/core/rag-processor.js index 5d0ce09..9bcf81d 100644 --- a/core/rag-processor.js +++ b/core/rag-processor.js @@ -1 +1 @@ -'use strict';const _0x3f5590=_0x555a;(function(_0x4c94f3,_0x492e3c){const _0xcffccf=_0x555a,_0x3ff047=_0x4c94f3();while(!![]){try{const _0x4203ef=-parseInt(_0xcffccf(0x1a9))/0x1+parseInt(_0xcffccf(0x15b))/0x2+parseInt(_0xcffccf(0x1ae))/0x3+parseInt(_0xcffccf(0x158))/0x4+parseInt(_0xcffccf(0x1e1))/0x5+-parseInt(_0xcffccf(0x197))/0x6*(-parseInt(_0xcffccf(0x1a8))/0x7)+-parseInt(_0xcffccf(0x1b8))/0x8*(parseInt(_0xcffccf(0x1a1))/0x9);if(_0x4203ef===_0x492e3c)break;else _0x3ff047['push'](_0x3ff047['shift']());}catch(_0x177488){_0x3ff047['push'](_0x3ff047['shift']());}}}(_0x39cc,0x1f6b5));import{extension_prompt_roles,setExtensionPrompt}from'/script.js';function _0x555a(_0x32e683,_0x365ee1){const _0x39cc57=_0x39cc();return _0x555a=function(_0x555abe,_0x2df5a6){_0x555abe=_0x555abe-0x152;let _0x48ced7=_0x39cc57[_0x555abe];return _0x48ced7;},_0x555a(_0x32e683,_0x365ee1);}import*as _0x518e01 from'./utils/context-utils.js';import{defaultSettings as _0x338568}from'./rag-settings.js';const MODULE_NAME='hanlinyuan-rag-core',OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME=_0x3f5590(0x1af);let context=null,settings=null;export{initialize,getSettings,saveSettings,resetSettings,testApiConnection,fetchEmbeddingModels,fetchRerankModels,getVectorCount,purgeStorage,getMessagesForCondensation,processCondensation,ingestTextToHanlinyuan,getCollectionId};function _0x39cc(){const _0x89c7d7=['join','queryMessageCount','[翰林院-日志]\x20没有需要插入的文本块,操作完成。','获取模型列表失败\x20(','replace','[翰林院-日志]\x20清空宝库API错误:','[翰林院]\x20处理外部文书时发生错误:','azure','[翰林院-日志]\x20正在为\x20','150szBETd','min','embedding','\x20条结果。','mes','top_n','rerank','凝识之权未开启','url','floor','354852TRFErV','\x20个文本块获取向量...','saveSettingsDebounced','retrieval','/api/vector/purge','GET','enabled','68054pwCbWt','206795yODbKk','[翰林院-日志]\x20开始向量查询\x20(采用最终API交互模式)...','/v1/embeddings','reduce','object','377328hqlfDl','vectors_rearrangeChat','[翰林院-Rerank]\x20外部Rerank失败,将仅使用内部加权。','getContext','API\x20URL\x20或\x20Key\x20未提供。','外部Rerank完成','charCodeAt','position','忆识存入API错误\x20','maxResults','96hCjLql','application/json','api-key','notify','log','Rerank模型API的响应格式无效:\x20未找到\x20\x27data\x27\x20数组。','HANLINYUAN_RAG','Bearer\x20','now','/v1','rerank_score','[翰林院-日志]\x20开始向量插入...','lorebook','[翰林院-日志]\x20/api/vector/purge\x20响应状态:\x20','original_index','quiet','length','[翰林院-日志]\x20/api/vector/list\x20响应状态:\x20','isArray','depth_role','[翰林院-日志]\x20清空宝库API调用成功。','/embeddings','final_score','condensation','[翰林院]\x20未能获取SillyTavern上下文,初始化失败。','endsWith','extensionSettings','embeddings','warning','webllm','POST','stringify','hashes','[翰林院-日志]\x20开始获取向量总数...','status','forEach','[翰林院-日志]\x20获取向量列表API错误:','embeddingModel','info','/v1/rerank','json','319565EYlgby','toString','[翰林院-日志]\x20/api/vector/list\x20响应内容:','map','[翰林院-日志]\x20发送到\x20/api/vector/list\x20的请求体:','/api/vector/insert','message','is_user','data','push','翰林院忆识核心已启动\x20(V5.1-借壳上市版),已注册全局函数:\x20','[翰林院-Rerank]\x20元数据加权排序完成。','856728awqjqz','source','神力获取失败\x20','323406TavmOi','metadata','unknown','filter','manual','matchThreshold','trim','[翰林院-日志]\x20宝库查询API错误:','relevance_score','[翰林院-日志]\x20/api/vector/insert\x20响应状态:\x20','error','findIndex','[翰林院-日志]\x20发送到\x20/api/vector/query\x20的请求体:','Rerank失败:\x20','/rerank','substring','):\x20','getRequestHeaders','batchSize','\x20获取模型列表...','/v1/models','depth','[翰林院-日志]\x20清空目标集合ID:\x20','advanced','openai','model','function','[翰林院-日志]\x20查询目标集合ID:\x20','slice','text','injection','[翰林院-Rerank]\x20开始外部API重排序...','max','No\x20messages\x20to\x20process.','send_date','宝库查询API错误\x20','{{text}}','/api/vector/query','Rerank\x20API\x20请求失败\x20(','chat','\x20个向量。','测试连接','/api/vector/list','items','Authorization','sort','[翰林院-Rerank]\x20正在从\x20','count','核心未初始化','https://api.openai.com','toISOString'];_0x39cc=function(){return _0x89c7d7;};return _0x39cc();}function initialize(){const _0x5a5be9=_0x3f5590;context=SillyTavern[_0x5a5be9(0x1b1)]();if(!context){console[_0x5a5be9(0x165)](_0x5a5be9(0x1d0));return;}settings=getSettings();const _0x487807=window[OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME];typeof _0x487807===_0x5a5be9(0x175)?(window[OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME]=async function(..._0x201182){await rearrangeChat(..._0x201182),await _0x487807(..._0x201182);},console['log']('翰林院忆识核心已启动\x20(V5.1-和平共存版),已代理\x20'+OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME)):(window[OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME]=rearrangeChat,console[_0x5a5be9(0x1bc)](_0x5a5be9(0x156)+OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME));}async function ingestTextToHanlinyuan(_0xd659db,_0x1401ca=_0x3f5590(0x15f),_0x58dd10=null){const _0x5cbede=_0x3f5590;if(!settings)return{'success':![],'error':_0x5cbede(0x18b)};try{const _0x258faa=splitIntoChunks(_0xd659db)[_0x5cbede(0x1e4)](_0x39ba94=>{const _0x2b1564=_0x5cbede,_0x1693a8={'source':_0x1401ca,'timestamp':new Date()['toISOString']()};return _0x1401ca===_0x2b1564(0x1c4)&&_0x58dd10&&(_0x1693a8['entry']=_0x58dd10),{'text':_0x39ba94,'metadata':_0x1693a8};});if(_0x258faa[_0x5cbede(0x1c8)]===0x0)return{'success':!![]};const _0xefe218=await insertVectors(_0x258faa);return{'success':!![],'count':_0xefe218[_0x5cbede(0x18a)]};}catch(_0x2da01f){return console[_0x5cbede(0x165)](_0x5cbede(0x194),_0x2da01f),{'success':![],'error':_0x2da01f[_0x5cbede(0x152)]};}}function getSettings(){const _0x69186a=_0x3f5590;if(!context||!context[_0x69186a(0x1d2)])return structuredClone(_0x338568);let _0x2d28b4=context[_0x69186a(0x1d2)][MODULE_NAME];!_0x2d28b4&&(_0x2d28b4={},context['extensionSettings'][MODULE_NAME]=_0x2d28b4);for(const _0x28fdfb in _0x338568){if(_0x2d28b4[_0x28fdfb]===undefined)_0x2d28b4[_0x28fdfb]=structuredClone(_0x338568[_0x28fdfb]);else{if(typeof _0x338568[_0x28fdfb]===_0x69186a(0x1ad)&&!Array[_0x69186a(0x1ca)](_0x338568[_0x28fdfb])&&_0x338568[_0x28fdfb]!==null)for(const _0x2a4615 in _0x338568[_0x28fdfb]){_0x2d28b4[_0x28fdfb][_0x2a4615]===undefined&&(_0x2d28b4[_0x28fdfb][_0x2a4615]=_0x338568[_0x28fdfb][_0x2a4615]);}}}return _0x2d28b4;}function saveSettings(){const _0x526e55=_0x3f5590;if(context)context[_0x526e55(0x1a3)]();}function resetSettings(){context&&(context['extensionSettings'][MODULE_NAME]=structuredClone(_0x338568),saveSettings());}function showNotification(_0x19244a,_0x23a9f4=_0x3f5590(0x1de)){toastr[_0x23a9f4](_0x19244a);}function splitIntoChunks(_0x2a7a38){const _0x180699=_0x3f5590,{chunkSize:_0x32b849,overlap:_0xe6f3c7}=settings[_0x180699(0x172)],_0x4cbe8c=[];if(!_0x2a7a38||_0x32b849<=0x0)return _0x4cbe8c;let _0x2da619=0x0;while(_0x2da619<_0x2a7a38['length']){const _0x5c17b8=Math[_0x180699(0x198)](_0x2da619+_0x32b849,_0x2a7a38[_0x180699(0x1c8)]);_0x4cbe8c['push'](_0x2a7a38[_0x180699(0x16a)](_0x2da619,_0x5c17b8)),_0x2da619+=_0x32b849-_0xe6f3c7;}return _0x4cbe8c;}import{getCollectionId}from'./utils/context-utils.js';function generateHash(_0x32d809){const _0x2e212c=_0x3f5590;let _0x2fbe5e=0x0;for(let _0x540460=0x0;_0x540460<_0x32d809[_0x2e212c(0x1c8)];_0x540460++){const _0x2b272b=_0x32d809[_0x2e212c(0x1b4)](_0x540460);_0x2fbe5e=(_0x2fbe5e<<0x5)-_0x2fbe5e+_0x2b272b,_0x2fbe5e=_0x2fbe5e&_0x2fbe5e;}return Math['abs'](_0x2fbe5e)[_0x2e212c(0x1e2)](0x24);}function getSanitizedBaseUrl(_0x4c41d0){const _0x482359=_0x3f5590;let _0x568e98=_0x4c41d0[_0x482359(0x161)]();return _0x568e98[_0x482359(0x1d1)]('/')&&(_0x568e98=_0x568e98[_0x482359(0x177)](0x0,-0x1)),_0x568e98['endsWith'](_0x482359(0x1c1))&&(_0x568e98=_0x568e98[_0x482359(0x177)](0x0,-0x3)),_0x568e98[_0x482359(0x1d1)](_0x482359(0x1cd))&&(_0x568e98=_0x568e98[_0x482359(0x177)](0x0,-0xb)),_0x568e98;}async function fetchEmbeddingModels(){const _0x2ec184=_0x3f5590,{apiKey:_0x39b323}=settings['retrieval'],_0x5a695d=getApiEndpointUrl(!![]);if(!_0x5a695d||!_0x39b323)throw new Error(_0x2ec184(0x1b2));const _0x432f3d=getSanitizedBaseUrl(_0x5a695d),_0x22e5ea=_0x432f3d+_0x2ec184(0x16f);console['log']('[翰林院]\x20正在从\x20'+_0x22e5ea+_0x2ec184(0x16e));const _0xc47b98=await fetch(_0x22e5ea,{'method':_0x2ec184(0x1a6),'headers':getApiHeaders()});if(!_0xc47b98['ok']){const _0x2aa617=await _0xc47b98[_0x2ec184(0x178)]();throw new Error(_0x2ec184(0x191)+_0xc47b98[_0x2ec184(0x1da)]+_0x2ec184(0x16b)+_0x2aa617);}const _0x24e182=await _0xc47b98[_0x2ec184(0x1e0)]();if(!_0x24e182[_0x2ec184(0x154)]||!Array[_0x2ec184(0x1ca)](_0x24e182['data']))throw new Error('模型API的响应格式无效:\x20未找到\x20\x27data\x27\x20数组。');return _0x24e182[_0x2ec184(0x154)][_0x2ec184(0x1e4)](_0x5a1bd3=>_0x5a1bd3['id'])['sort']();}function getRerankBaseUrl(_0x3207ea){const _0x520c5a=_0x3f5590;let _0x3cfa26=_0x3207ea['trim']();return _0x3cfa26['endsWith']('/')&&(_0x3cfa26=_0x3cfa26[_0x520c5a(0x177)](0x0,-0x1)),_0x3cfa26['endsWith'](_0x520c5a(0x1c1))&&(_0x3cfa26=_0x3cfa26[_0x520c5a(0x177)](0x0,-0x3)),_0x3cfa26[_0x520c5a(0x1d1)](_0x520c5a(0x169))&&(_0x3cfa26=_0x3cfa26['slice'](0x0,-0x7)),_0x3cfa26;}async function fetchRerankModels(){const _0x52979f=_0x3f5590,{url:_0x14d217,apiKey:_0x109aa0}=settings[_0x52979f(0x19d)];if(!_0x14d217||!_0x109aa0)throw new Error('Rerank\x20API\x20URL\x20或\x20Key\x20未提供。');const _0x18b5c6=getRerankBaseUrl(_0x14d217),_0x478121=_0x18b5c6+_0x52979f(0x16f);console[_0x52979f(0x1bc)](_0x52979f(0x189)+_0x478121+_0x52979f(0x16e));const _0x29358a=await fetch(_0x478121,{'method':'GET','headers':{'Authorization':_0x52979f(0x1bf)+_0x109aa0}});if(!_0x29358a['ok']){const _0x3b29e9=await _0x29358a[_0x52979f(0x178)]();throw new Error('获取Rerank模型列表失败\x20('+_0x29358a[_0x52979f(0x1da)]+_0x52979f(0x16b)+_0x3b29e9);}const _0x2811a0=await _0x29358a['json']();if(!_0x2811a0['data']||!Array['isArray'](_0x2811a0['data']))throw new Error(_0x52979f(0x1bd));return _0x2811a0[_0x52979f(0x154)]['map'](_0x348bb7=>_0x348bb7['id'])[_0x52979f(0x188)]();}function getApiEndpointUrl(_0x258970=![]){const _0x7f093a=_0x3f5590,{apiEndpoint:_0x51366f,customApiUrl:_0x2a8a0e}=settings[_0x7f093a(0x1a4)];let _0x35da17;switch(_0x51366f){case _0x7f093a(0x173):_0x35da17=_0x7f093a(0x18c);break;case'azure':case'custom':_0x35da17=_0x2a8a0e;break;default:_0x35da17=_0x7f093a(0x18c);break;}if(_0x258970)return _0x35da17;return getSanitizedBaseUrl(_0x35da17)+_0x7f093a(0x1ab);}function getApiHeaders(){const _0x3352aa=_0x3f5590,_0x324e88={'Content-Type':_0x3352aa(0x1b9)},{apiKey:_0x2d73f3,apiEndpoint:_0x4b03d7}=settings['retrieval'];switch(_0x4b03d7){case'openai':case'custom':_0x324e88[_0x3352aa(0x187)]=_0x3352aa(0x1bf)+_0x2d73f3;break;case _0x3352aa(0x195):_0x324e88[_0x3352aa(0x1ba)]=_0x2d73f3;break;}return _0x324e88;}async function getEmbeddings(_0x21dde){const _0x285755=_0x3f5590;if(!settings[_0x285755(0x1a4)]['apiKey'])throw new Error('请先配置API\x20Key');const _0x3d1a07=getApiEndpointUrl(),_0x496a89=getApiHeaders(),_0x3ce888=settings['retrieval'][_0x285755(0x1dd)],_0x56dd75=settings[_0x285755(0x1a4)][_0x285755(0x16d)]||0x5,_0xb384b5=[];for(let _0x5f4c29=0x0;_0x5f4c29<_0x21dde[_0x285755(0x1c8)];_0x5f4c29+=_0x56dd75){const _0x4998e3=_0x21dde['slice'](_0x5f4c29,_0x5f4c29+_0x56dd75),_0x5674d1=await fetch(_0x3d1a07,{'method':_0x285755(0x1d6),'headers':_0x496a89,'body':JSON[_0x285755(0x1d7)]({'input':_0x4998e3,'model':_0x3ce888})});if(!_0x5674d1['ok']){const _0x298606=await _0x5674d1['text']();throw new Error(_0x285755(0x15a)+_0x5674d1[_0x285755(0x1da)]+':\x20'+_0x298606);}const _0x269d90=await _0x5674d1[_0x285755(0x1e0)]();_0xb384b5[_0x285755(0x155)](..._0x269d90['data'][_0x285755(0x1e4)](_0x9cdabb=>_0x9cdabb[_0x285755(0x199)])),_0x5f4c29+_0x56dd75<_0x21dde[_0x285755(0x1c8)]&&await new Promise(_0x4ba547=>setTimeout(_0x4ba547,0xc8));}return _0xb384b5;}async function queryVectors(_0x276186){const _0x20c2af=_0x3f5590;console[_0x20c2af(0x1bc)](_0x20c2af(0x1aa));const _0xa4e144=getCollectionId();console[_0x20c2af(0x1bc)](_0x20c2af(0x176)+_0xa4e144);const _0x36e4ba=(await getEmbeddings([_0x276186]))[0x0],_0x4430aa={'collectionId':_0xa4e144,'searchText':_0x276186,'topK':settings['advanced'][_0x20c2af(0x1b7)],'threshold':settings[_0x20c2af(0x172)][_0x20c2af(0x160)],'source':_0x20c2af(0x1d5),'embeddings':{[_0x276186]:_0x36e4ba}};console[_0x20c2af(0x1bc)](_0x20c2af(0x167),JSON['stringify'](_0x4430aa,null,0x2));const _0x9cf018=await fetch(_0x20c2af(0x180),{'method':'POST','headers':context[_0x20c2af(0x16c)](),'body':JSON[_0x20c2af(0x1d7)](_0x4430aa)});console['log']('[翰林院-日志]\x20/api/vector/query\x20响应状态:\x20'+_0x9cf018[_0x20c2af(0x1da)]);if(!_0x9cf018['ok']){const _0x44264f=await _0x9cf018[_0x20c2af(0x178)]();console[_0x20c2af(0x165)](_0x20c2af(0x162),_0x44264f);throw new Error(_0x20c2af(0x17e)+_0x9cf018['status']+':\x20'+_0x44264f);}const _0x418a47=await _0x9cf018[_0x20c2af(0x1e0)]();console['log']('[翰林院-日志]\x20/api/vector/query\x20响应内容:',_0x418a47);const _0x2a369e=_0x418a47[_0x20c2af(0x15c)]||_0x418a47['results']||_0x418a47[_0x20c2af(0x154)]||[];return console[_0x20c2af(0x1bc)]('[翰林院-日志]\x20查询成功,返回\x20'+_0x2a369e[_0x20c2af(0x1c8)]+_0x20c2af(0x19a)),_0x2a369e;}async function insertVectors(_0x35684c){const _0x126ad3=_0x3f5590;console['log'](_0x126ad3(0x1c3));const _0x3fb5ff=getCollectionId();console[_0x126ad3(0x1bc)]('[翰林院-日志]\x20插入目标集合ID:\x20'+_0x3fb5ff);const _0x42f7b0=_0x35684c[_0x126ad3(0x1e4)](_0x24224d=>_0x24224d[_0x126ad3(0x178)]);if(_0x42f7b0[_0x126ad3(0x1c8)]===0x0)return console[_0x126ad3(0x1bc)](_0x126ad3(0x190)),{'success':!![],'count':0x0};console[_0x126ad3(0x1bc)](_0x126ad3(0x196)+_0x42f7b0[_0x126ad3(0x1c8)]+_0x126ad3(0x1a2));const _0x37723e=await getEmbeddings(_0x42f7b0);console[_0x126ad3(0x1bc)]('[翰林院-日志]\x20成功获取\x20'+_0x37723e[_0x126ad3(0x1c8)]+_0x126ad3(0x183));const _0xeb2818=_0x35684c[_0x126ad3(0x1e4)]((_0x2c94a2,_0x215c7f)=>({'hash':generateHash(_0x2c94a2[_0x126ad3(0x178)]+Date[_0x126ad3(0x1c0)]()+_0x215c7f),'text':_0x2c94a2[_0x126ad3(0x178)],'metadata':_0x2c94a2[_0x126ad3(0x15c)]||{'source':_0x126ad3(0x15d),'timestamp':new Date()[_0x126ad3(0x18d)]()}})),_0x45ebfe=_0xeb2818[_0x126ad3(0x1ac)]((_0x1502d6,_0x9f803c,_0x137d35)=>{const _0x41e0cc=_0x126ad3;return _0x1502d6[_0x9f803c[_0x41e0cc(0x178)]]=_0x37723e[_0x137d35],_0x1502d6;},{}),_0x8afd32={'collectionId':_0x3fb5ff,'items':_0xeb2818,'source':_0x126ad3(0x1d5),'embeddings':_0x45ebfe};console[_0x126ad3(0x1bc)]('[翰林院-日志]\x20发送到\x20/api/vector/insert\x20的请求体\x20(仅显示条目数):',{'collectionId':_0x8afd32['collectionId'],'source':_0x8afd32[_0x126ad3(0x159)],'itemCount':_0x8afd32[_0x126ad3(0x186)][_0x126ad3(0x1c8)],'embeddingCount':Object['keys'](_0x8afd32[_0x126ad3(0x1d3)])[_0x126ad3(0x1c8)]});const _0x563079=await fetch(_0x126ad3(0x1e6),{'method':_0x126ad3(0x1d6),'headers':context[_0x126ad3(0x16c)](),'body':JSON[_0x126ad3(0x1d7)](_0x8afd32)});console[_0x126ad3(0x1bc)](_0x126ad3(0x164)+_0x563079[_0x126ad3(0x1da)]);if(!_0x563079['ok']){const _0x44d351=await _0x563079['text']();console[_0x126ad3(0x165)]('[翰林院-日志]\x20忆识存入API错误:',_0x44d351);throw new Error(_0x126ad3(0x1b6)+_0x563079[_0x126ad3(0x1da)]+':\x20'+_0x44d351);}return console['log']('[翰林院-日志]\x20忆识存入API调用成功。'),{'success':!![],'count':_0xeb2818[_0x126ad3(0x1c8)]};}async function testApiConnection(){const _0x45d578=_0x3f5590;await getEmbeddings([_0x45d578(0x184)]);}async function getVectorCount(){const _0x4c9083=_0x3f5590;console[_0x4c9083(0x1bc)](_0x4c9083(0x1d9));const _0x41acec=getCollectionId();console[_0x4c9083(0x1bc)]('[翰林院-日志]\x20统计目标集合ID:\x20'+_0x41acec);const _0x328ab8={'collectionId':_0x41acec,'source':_0x4c9083(0x1d5),'embeddings':{}};console[_0x4c9083(0x1bc)](_0x4c9083(0x1e5),JSON[_0x4c9083(0x1d7)](_0x328ab8,null,0x2));const _0x5c2440=await fetch(_0x4c9083(0x185),{'method':_0x4c9083(0x1d6),'headers':context[_0x4c9083(0x16c)](),'body':JSON['stringify'](_0x328ab8)});console['log'](_0x4c9083(0x1c9)+_0x5c2440[_0x4c9083(0x1da)]);if(!_0x5c2440['ok']){const _0xd413ac=await _0x5c2440[_0x4c9083(0x178)]();return console[_0x4c9083(0x165)](_0x4c9083(0x1dc),_0xd413ac),0x0;}const _0x4edd6a=await _0x5c2440[_0x4c9083(0x1e0)]();console['log'](_0x4c9083(0x1e3),_0x4edd6a);let _0x5c68f8=0x0;if(Array['isArray'](_0x4edd6a))_0x5c68f8=_0x4edd6a[_0x4c9083(0x1c8)];else _0x4edd6a&&_0x4edd6a['hashes']&&(_0x5c68f8=_0x4edd6a[_0x4c9083(0x1d8)][_0x4c9083(0x1c8)]);return console['log']('[翰林院-日志]\x20统计成功,向量总数:\x20'+_0x5c68f8),_0x5c68f8;}async function purgeStorage(){const _0x624315=_0x3f5590;console[_0x624315(0x1bc)]('[翰林院-日志]\x20开始清空宝库...');const _0x50fedd=getCollectionId();console[_0x624315(0x1bc)](_0x624315(0x171)+_0x50fedd);const _0x54fdd0={'collectionId':_0x50fedd};console[_0x624315(0x1bc)]('[翰林院-日志]\x20发送到\x20/api/vector/purge\x20的请求体:',JSON[_0x624315(0x1d7)](_0x54fdd0,null,0x2));const _0x161a3e=await fetch(_0x624315(0x1a5),{'method':_0x624315(0x1d6),'headers':context[_0x624315(0x16c)](),'body':JSON[_0x624315(0x1d7)](_0x54fdd0)});console[_0x624315(0x1bc)](_0x624315(0x1c5)+_0x161a3e['status']);if(!_0x161a3e['ok']){const _0x4daeab=await _0x161a3e[_0x624315(0x178)]();console['error'](_0x624315(0x193),_0x4daeab);}else console['log'](_0x624315(0x1cc));return _0x161a3e['ok'];}function getMessagesForCondensation(_0x2e502b=null){const _0x23982e=_0x3f5590;if(!settings[_0x23982e(0x1cf)][_0x23982e(0x1a7)])return showNotification(_0x23982e(0x19e),_0x23982e(0x1d4)),[];const {layerStart:_0x5b52c3,layerEnd:_0x1d5aa7}=settings[_0x23982e(0x1cf)],_0x20fe45=_0x2e502b||settings[_0x23982e(0x1cf)]['messageTypes'],_0x4fd38e=context['chat'][_0x23982e(0x1c8)],_0xc8e44e=Math[_0x23982e(0x17b)](0x0,_0x5b52c3-0x1),_0x2b4dfe=Math[_0x23982e(0x198)](_0x4fd38e,_0x1d5aa7),_0xa5cee2=context[_0x23982e(0x182)]['slice'](_0xc8e44e,_0x2b4dfe);return _0xa5cee2[_0x23982e(0x15e)](_0x43d4ff=>{const _0x5f128b=_0x23982e,_0x123637=_0x43d4ff['is_user']===!![],_0x52462e=_0x43d4ff[_0x5f128b(0x153)]===![];if(!_0x43d4ff[_0x5f128b(0x19b)]||!_0x43d4ff[_0x5f128b(0x19b)][_0x5f128b(0x161)]())return![];return _0x20fe45['user']&&_0x123637||_0x20fe45['ai']&&_0x52462e;});}async function processCondensation(_0x25d339){const _0x403996=_0x3f5590;if(!_0x25d339||_0x25d339[_0x403996(0x1c8)]===0x0)return{'success':![],'error':_0x403996(0x17c)};const _0x29b39e=[],_0x4bf73c=context[_0x403996(0x182)];for(const _0x321354 of _0x25d339){const _0x4dd2da=(_0x321354[_0x403996(0x19b)]||'')['replace'](/<[^>]*>/g,'')[_0x403996(0x161)]();if(_0x4dd2da[_0x403996(0x1c8)]===0x0)continue;const _0x522b39=_0x4bf73c[_0x403996(0x166)](_0x1155e4=>_0x1155e4===_0x321354),_0x15552d=_0x522b39!==-0x1?_0x522b39+0x1:-0x1,_0x8c5aed={'source':'chat_history','floor':_0x15552d,'is_user':_0x321354[_0x403996(0x153)],'timestamp':new Date(_0x321354[_0x403996(0x17d)])['toISOString']()},_0x2fee10=splitIntoChunks(_0x4dd2da)['map'](_0x3f577a=>({'text':_0x3f577a,'metadata':_0x8c5aed}));_0x29b39e[_0x403996(0x155)](..._0x2fee10);}if(_0x29b39e[_0x403996(0x1c8)]===0x0)return{'success':![],'error':'No\x20valid\x20chunks\x20generated.'};return await insertVectors(_0x29b39e);}async function rerankResults(_0x25aefd,_0x48d172,_0x293be1){const _0xe95076=_0x3f5590;let _0x75c5ce=_0x25aefd;if(_0x293be1[_0xe95076(0x19d)][_0xe95076(0x1a7)]&&_0x25aefd['length']>0x0){console[_0xe95076(0x1bc)](_0xe95076(0x17a));try{const _0x3cb587=_0x25aefd[_0xe95076(0x1e4)]((_0x4161a6,_0x1268df)=>({'text':_0x4161a6[_0xe95076(0x178)],'original_index':_0x1268df})),_0x49e0c8=getRerankBaseUrl(_0x293be1[_0xe95076(0x19d)][_0xe95076(0x19f)]),_0x494ba9=_0x49e0c8+_0xe95076(0x1df),_0x1c4e93=await fetch(_0x494ba9,{'method':'POST','headers':{'Content-Type':'application/json','Authorization':'Bearer\x20'+_0x293be1[_0xe95076(0x19d)]['apiKey']},'body':JSON['stringify']({'query':_0x48d172,'documents':_0x3cb587[_0xe95076(0x1e4)](_0x394183=>_0x394183[_0xe95076(0x178)]),'model':_0x293be1[_0xe95076(0x19d)][_0xe95076(0x174)],'top_n':_0x293be1[_0xe95076(0x19d)][_0xe95076(0x19c)]})});if(!_0x1c4e93['ok'])throw new Error(_0xe95076(0x181)+_0x1c4e93[_0xe95076(0x1da)]+_0xe95076(0x16b)+await _0x1c4e93[_0xe95076(0x178)]());const _0x1b955e=await _0x1c4e93[_0xe95076(0x1e0)](),_0x39f6f5=_0x25aefd[_0xe95076(0x1e4)]((_0x1f7fdc,_0xa2e38a)=>({..._0x1f7fdc,'original_index':_0xa2e38a}));_0x75c5ce=_0x39f6f5[_0xe95076(0x1e4)](_0x1d2e2e=>{const _0x6b2ae4=_0xe95076,_0x364e5e=_0x1b955e['results']['find'](_0x4651d7=>_0x4651d7['index']===_0x1d2e2e[_0x6b2ae4(0x1c6)]),_0x1223a0=_0x364e5e?_0x364e5e[_0x6b2ae4(0x163)]:0x0;return{..._0x1d2e2e,'rerank_score':_0x1223a0};});if(_0x293be1['rerank'][_0xe95076(0x1bb)])showNotification(_0xe95076(0x1b3),'success');}catch(_0x369ec5){console[_0xe95076(0x165)](_0xe95076(0x1b0),_0x369ec5);if(_0x293be1[_0xe95076(0x19d)][_0xe95076(0x1bb)])showNotification(_0xe95076(0x168)+_0x369ec5['message'],_0xe95076(0x165));_0x75c5ce['forEach'](_0x16557b=>_0x16557b[_0xe95076(0x1c2)]=0x0);}}else _0x75c5ce[_0xe95076(0x1db)](_0x2cce3b=>_0x2cce3b[_0xe95076(0x1c2)]=0x0);console[_0xe95076(0x1bc)]('[翰林院-Rerank]\x20开始元数据加权最终排序...');const _0x277dd1=context[_0xe95076(0x182)][_0xe95076(0x1c8)],_0xc03fbc=_0x293be1[_0xe95076(0x19d)]['hybrid_alpha'],_0x529cf1=_0x75c5ce['map'](_0x3deb96=>{const _0x4b8ad1=_0xe95076;let _0x1e7b7c=0x1;const _0x114bbe=_0x3deb96[_0x4b8ad1(0x15c)]||{};switch(_0x114bbe['source']){case'lorebook':_0x1e7b7c*=1.2;break;case _0x4b8ad1(0x15f):_0x1e7b7c*=1.1;break;case'chat_history':if(_0x114bbe[_0x4b8ad1(0x1a0)]&&_0x277dd1>0x0){const _0xe7c62c=_0x114bbe['floor']/_0x277dd1;_0x1e7b7c*=0x1+_0xe7c62c;}break;}const _0x408af4=_0x3deb96['rerank_score']*_0xc03fbc+(_0x3deb96['score']||0x0)*(0x1-_0xc03fbc),_0x3cd452=_0x408af4*_0x1e7b7c;return{..._0x3deb96,'final_score':_0x3cd452};});return _0x529cf1[_0xe95076(0x188)]((_0x1e2281,_0x3b41e5)=>(_0x3b41e5[_0xe95076(0x1ce)]||0x0)-(_0x1e2281[_0xe95076(0x1ce)]||0x0)),console[_0xe95076(0x1bc)](_0xe95076(0x157)),_0x529cf1[_0xe95076(0x177)](0x0,_0x293be1['rerank'][_0xe95076(0x19c)]);}async function rearrangeChat(_0x39eaaa,_0x185227,_0x444b53,_0x540d1e){const _0x166523=_0x3f5590;setExtensionPrompt(_0x166523(0x1be),'',settings[_0x166523(0x179)][_0x166523(0x1b5)],settings[_0x166523(0x179)][_0x166523(0x170)],![],settings[_0x166523(0x179)][_0x166523(0x1cb)]);if(_0x540d1e===_0x166523(0x1c7)||!settings[_0x166523(0x1a4)][_0x166523(0x1a7)])return;const _0x5bdc9c=_0x39eaaa['slice'](-settings[_0x166523(0x172)][_0x166523(0x18f)]);if(_0x5bdc9c['length']===0x0)return;const _0x23efaa=_0x5bdc9c[_0x166523(0x1e4)](_0x3859cd=>_0x3859cd['mes'])[_0x166523(0x18e)]('\x20')[_0x166523(0x192)](/<[^>]*>/g,'')['trim']();if(!_0x23efaa)return;try{const _0x4a3efa=await queryVectors(_0x23efaa);if(_0x4a3efa['length']===0x0)return;const _0x40fc46=await rerankResults(_0x4a3efa,_0x23efaa,settings);if(_0x40fc46['length']===0x0)return;const _0x3a228e=_0x40fc46['map'](_0x8c82b4=>_0x8c82b4[_0x166523(0x178)])[_0x166523(0x18e)]('\x0a\x0a'),_0x5ae818=settings[_0x166523(0x179)]['template']['replace'](_0x166523(0x17f),_0x3a228e);setExtensionPrompt('HANLINYUAN_RAG',_0x5ae818,settings['injection'][_0x166523(0x1b5)],settings[_0x166523(0x179)][_0x166523(0x170)],![],settings[_0x166523(0x179)][_0x166523(0x1cb)]);}catch(_0x201b03){console[_0x166523(0x165)]('[翰林院]\x20检索或注入时发生错误:',_0x201b03);if(settings[_0x166523(0x1a4)][_0x166523(0x1bb)])showNotification('忆识检索失败:\x20'+_0x201b03[_0x166523(0x152)],'error');}} +'use strict';const _0x3a0919=_0x580c;(function(_0x377b04,_0x5166f7){const _0x278bb0=_0x580c,_0x52d199=_0x377b04();while(!![]){try{const _0x25b928=parseInt(_0x278bb0(0x24d))/0x1*(parseInt(_0x278bb0(0x27d))/0x2)+-parseInt(_0x278bb0(0x261))/0x3*(-parseInt(_0x278bb0(0x1dd))/0x4)+parseInt(_0x278bb0(0x239))/0x5+-parseInt(_0x278bb0(0x251))/0x6+parseInt(_0x278bb0(0x1db))/0x7*(parseInt(_0x278bb0(0x23d))/0x8)+-parseInt(_0x278bb0(0x234))/0x9+-parseInt(_0x278bb0(0x224))/0xa*(parseInt(_0x278bb0(0x26c))/0xb);if(_0x25b928===_0x5166f7)break;else _0x52d199['push'](_0x52d199['shift']());}catch(_0x28c241){_0x52d199['push'](_0x52d199['shift']());}}}(_0x5667,0x6010b));function _0x580c(_0x393099,_0xb617c7){const _0x5667ce=_0x5667();return _0x580c=function(_0x580c74,_0x3c277c){_0x580c74=_0x580c74-0x1da;let _0x22e775=_0x5667ce[_0x580c74];return _0x22e775;},_0x580c(_0x393099,_0xb617c7);}import{extension_prompt_roles,setExtensionPrompt}from'/script.js';import*as _0x270d56 from'./utils/context-utils.js';import{defaultSettings as _0x7e7f53}from'./rag-settings.js';import*as _0x572a3f from'./ingestion-manager.js';const MODULE_NAME=_0x3a0919(0x229),OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME=_0x3a0919(0x246);let context=null,settings=null,lockedCollectionId=null;export{initialize,getSettings,saveSettings,resetSettings,testApiConnection,fetchEmbeddingModels,fetchRerankModels,getVectorCount,purgeStorage,getMessagesForCondensation,processCondensation,ingestTextToHanlinyuan,getCollectionId,toggleSessionLock,isSessionLocked,getLockedSessionInfo};function initialize(){const _0x49b24a=_0x3a0919;context=SillyTavern[_0x49b24a(0x241)]();if(!context){console[_0x49b24a(0x23b)](_0x49b24a(0x280));return;}settings=getSettings();const _0x17ed4d=window[OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME];typeof _0x17ed4d==='function'?(window[OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME]=async function(..._0x15dd66){await rearrangeChat(..._0x15dd66),await _0x17ed4d(..._0x15dd66);},console['log'](_0x49b24a(0x20d)+OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME)):(window[OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME]=rearrangeChat,console['log'](_0x49b24a(0x250)+OFFICIAL_REARRANGE_CHAT_FUNCTION_NAME));}async function ingestTextToHanlinyuan(_0x22635b,_0xad6df7=_0x3a0919(0x279),_0x42d65f='',_0x49145c=()=>{},_0x21c919=null,_0x8574d3=()=>{},_0x10e4be=()=>{},_0x398c50=null,_0x3ab6dc=0x0){const _0x2d2346=_0x3a0919;if(!_0x22635b||!_0x22635b[_0x2d2346(0x1f4)]())return{'success':![],'error':_0x2d2346(0x210)};if(!settings)return{'success':![],'error':_0x2d2346(0x272)};try{const _0x5ab184=getCollectionId();if(!_0x5ab184)throw new Error(_0x2d2346(0x20c));_0x8574d3(_0x2d2346(0x232)+_0x5ab184,'info'),_0x49145c({'message':_0x2d2346(0x276),'processed':0x0,'total':0x1});const _0x2b44ad=splitIntoChunks(_0x22635b,_0xad6df7,_0x42d65f),_0x46e5c1=_0x2b44ad[_0x2d2346(0x254)];if(_0x21c919?.[_0x2d2346(0x242)])throw new Error(_0x2d2346(0x265));_0x8574d3(_0x2d2346(0x1f0)+(_0x42d65f||_0xad6df7)+'\x27的文本分割成\x20'+_0x46e5c1+_0x2d2346(0x235),'info');if(_0x46e5c1===0x0)return{'success':!![],'count':0x0};const _0x295751=settings[_0x2d2346(0x23f)][_0x2d2346(0x204)]||0x5;let _0x4e529a=_0x3ab6dc;for(let _0x1d2c1a=_0x3ab6dc;_0x1d2c1a<_0x46e5c1;_0x1d2c1a+=_0x295751){if(_0x21c919?.[_0x2d2346(0x242)])throw new Error('AbortError');const _0x49637e=_0x2b44ad[_0x2d2346(0x22a)](_0x1d2c1a,_0x1d2c1a+_0x295751);_0x49145c({'message':_0x2d2346(0x286)+(_0x1d2c1a+0x1)+'-'+(_0x1d2c1a+_0x49637e[_0x2d2346(0x254)])+'\x20块','processed':_0x1d2c1a,'total':_0x46e5c1});const _0x56fddf=_0x49637e[_0x2d2346(0x288)](_0x428235=>_0x428235[_0x2d2346(0x207)]),_0x440db2=await getEmbeddings(_0x56fddf,_0x21c919);if(_0x21c919?.[_0x2d2346(0x242)])throw new Error(_0x2d2346(0x265));if(_0x49637e[_0x2d2346(0x254)]!==_0x440db2['length'])throw new Error(_0x2d2346(0x202));const _0x2c844d=_0x49637e[_0x2d2346(0x288)]((_0x22ef01,_0x348c87)=>({..._0x22ef01,'vector':_0x440db2[_0x348c87]}));await insertVectors(_0x2c844d,_0x21c919,_0x5ab184),_0x4e529a+=_0x49637e['length'],_0x398c50&&_0x572a3f['saveProgress'](_0x398c50,_0x4e529a,_0x46e5c1),_0x10e4be();}return _0x398c50&&_0x572a3f[_0x2d2346(0x22b)](_0x398c50),_0x8574d3('[翰林院-核心]\x20成功插入\x20'+_0x4e529a+_0x2d2346(0x236),_0x2d2346(0x27e)),{'success':!![],'count':_0x4e529a};}catch(_0x3a6576){if(_0x3a6576[_0x2d2346(0x1f2)]===_0x2d2346(0x265)){_0x8574d3(_0x2d2346(0x270),'warn');throw _0x3a6576;}return console['error']('[翰林院-核心]\x20ingestTextToHanlinyuan\x20失败:',_0x3a6576),_0x8574d3(_0x2d2346(0x271)+_0x3a6576[_0x2d2346(0x262)],_0x2d2346(0x23b)),{'success':![],'error':_0x3a6576[_0x2d2346(0x262)]};}}function getSettings(){const _0x2d167f=_0x3a0919;if(!context||!context['extensionSettings'])return structuredClone(_0x7e7f53);let _0x460e9c=context[_0x2d167f(0x1ed)][MODULE_NAME];!_0x460e9c&&(_0x460e9c={},context[_0x2d167f(0x1ed)][MODULE_NAME]=_0x460e9c);for(const _0x151d9c in _0x7e7f53){if(_0x460e9c[_0x151d9c]===undefined)_0x460e9c[_0x151d9c]=structuredClone(_0x7e7f53[_0x151d9c]);else{if(typeof _0x7e7f53[_0x151d9c]==='object'&&!Array['isArray'](_0x7e7f53[_0x151d9c])&&_0x7e7f53[_0x151d9c]!==null)for(const _0x2d8dda in _0x7e7f53[_0x151d9c]){_0x460e9c[_0x151d9c][_0x2d8dda]===undefined&&(_0x460e9c[_0x151d9c][_0x2d8dda]=_0x7e7f53[_0x151d9c][_0x2d8dda]);}}}return _0x460e9c;}function saveSettings(){if(context)context['saveSettingsDebounced']();}function resetSettings(){context&&(context['extensionSettings'][MODULE_NAME]=structuredClone(_0x7e7f53),saveSettings());}function showNotification(_0x272a13,_0x1c31a0='info'){toastr[_0x1c31a0](_0x272a13);}function splitIntoChunks(_0x3c1d84,_0x1ec053,_0x430203){const _0x10eaaa=_0x3a0919,{chunkSize:_0x345ca4,overlap:_0x4e3142}=settings['advanced'],_0x35b19c=[];if(!_0x3c1d84||_0x345ca4<=0x0)return _0x35b19c;const _0xd841eb=/(第\s*[一二三四五六七八九十百千万零\d]+\s*卷)/gim,_0x4a36dc=/(第\s*[一二三四五六七八九十百千万零\d]+\s*[章回节部])|^(Chapter\s+\d+)/gim;let _0x1c27a3=0x0,_0x4f3592=0x1,_0x5579ae=0x1,_0x1a9cda=![];const _0x525130=_0x3c1d84[_0x10eaaa(0x289)]('\x0a');let _0x44e6f6=_0x10eaaa(0x285),_0x20883a=_0x10eaaa(0x231),_0x4dc3e0=[];function _0x149ac0(){const _0x51fbfe=_0x10eaaa;if(_0x4dc3e0[_0x51fbfe(0x254)]===0x0)return;const _0x1aedd7=_0x4dc3e0[_0x51fbfe(0x228)]('\x0a');let _0xec7a53=0x0,_0x5014ae=0x1;while(_0xec7a53<_0x1aedd7['length']){const _0x1febbf=Math['min'](_0xec7a53+_0x345ca4,_0x1aedd7[_0x51fbfe(0x254)]),_0x441b75=_0x1aedd7[_0x51fbfe(0x27a)](_0xec7a53,_0x1febbf);if(_0x441b75[_0x51fbfe(0x1f4)]()[_0x51fbfe(0x254)]>0x0){const _0x205b37={'source':_0x1ec053,'sourceName':_0x430203,'timestamp':new Date()[_0x51fbfe(0x23a)](),'globalIndex':_0x1c27a3++,'volume':_0x44e6f6,'chapter':_0x20883a,'section':_0x5014ae},_0x1b2214=_0x51fbfe(0x25d)+_0x430203+',\x20'+_0x44e6f6+',\x20'+_0x20883a+_0x51fbfe(0x23e)+_0x5014ae+_0x51fbfe(0x27f);_0x35b19c[_0x51fbfe(0x253)]({'text':_0x1b2214+_0x441b75,'metadata':_0x205b37}),_0x5014ae++;}_0xec7a53+=_0x345ca4-_0x4e3142;if(_0xec7a53>=_0x1aedd7['length'])break;}_0x4dc3e0=[];}for(const _0x54a966 of _0x525130){const _0x3b4b49=_0x54a966[_0x10eaaa(0x1f4)]();if(_0xd841eb[_0x10eaaa(0x1ee)](_0x3b4b49))_0x149ac0(),_0x44e6f6=_0x3b4b49,_0x20883a=_0x10eaaa(0x231),_0x4f3592++,_0x5579ae=0x1,_0x1a9cda=!![];else _0x4a36dc[_0x10eaaa(0x1ee)](_0x3b4b49)?(_0x149ac0(),_0x20883a=_0x3b4b49,_0x5579ae++):_0x4dc3e0[_0x10eaaa(0x253)](_0x54a966);}_0x149ac0();if(_0x35b19c[_0x10eaaa(0x254)]===0x0&&_0x3c1d84[_0x10eaaa(0x254)]>0x0){let _0x12a6c5=0x0,_0x567fb0=0x1;while(_0x12a6c5<_0x3c1d84['length']){const _0xdd5a52=Math[_0x10eaaa(0x1f7)](_0x12a6c5+_0x345ca4,_0x3c1d84[_0x10eaaa(0x254)]),_0x4dd088=_0x3c1d84[_0x10eaaa(0x27a)](_0x12a6c5,_0xdd5a52),_0x145a15={'source':_0x1ec053,'sourceName':_0x430203,'timestamp':new Date()[_0x10eaaa(0x23a)](),'globalIndex':_0x35b19c[_0x10eaaa(0x254)],'volume':_0x10eaaa(0x285),'chapter':_0x10eaaa(0x231),'section':_0x567fb0},_0x514c12=_0x10eaaa(0x25d)+_0x430203+_0x10eaaa(0x249)+_0x567fb0+'节]\x0a';_0x35b19c[_0x10eaaa(0x253)]({'text':_0x514c12+_0x4dd088,'metadata':_0x145a15}),_0x567fb0++,_0x12a6c5+=_0x345ca4-_0x4e3142;}}return _0x35b19c;}import{getCollectionId as _0x370f52,getCharacterName}from'./utils/context-utils.js';function getCollectionId(){return lockedCollectionId||_0x370f52();}function toggleSessionLock(){return lockedCollectionId?(lockedCollectionId=null,![]):(lockedCollectionId=_0x370f52(),!![]);}function isSessionLocked(){return lockedCollectionId!==null;}function getLockedSessionInfo(){const _0x5977ee=_0x3a0919;if(!lockedCollectionId)return null;return{'id':lockedCollectionId,'name':_0x5977ee(0x264)+lockedCollectionId[_0x5977ee(0x27a)](0x0,0x8)+_0x5977ee(0x257)};}function generateHash(_0x28a652){const _0x17f00a=_0x3a0919;let _0x128b7a=0x0;for(let _0x54a4db=0x0;_0x54a4db<_0x28a652[_0x17f00a(0x254)];_0x54a4db++){const _0x21e103=_0x28a652['charCodeAt'](_0x54a4db);_0x128b7a=(_0x128b7a<<0x5)-_0x128b7a+_0x21e103,_0x128b7a=_0x128b7a&_0x128b7a;}return Math[_0x17f00a(0x268)](_0x128b7a)[_0x17f00a(0x1e7)](0x24);}function getSanitizedBaseUrl(_0x49229f){const _0x5ece11=_0x3a0919;let _0x920ce8=_0x49229f[_0x5ece11(0x1f4)]();return _0x920ce8[_0x5ece11(0x255)]('/')&&(_0x920ce8=_0x920ce8[_0x5ece11(0x22a)](0x0,-0x1)),_0x920ce8[_0x5ece11(0x255)](_0x5ece11(0x227))&&(_0x920ce8=_0x920ce8['slice'](0x0,-0x3)),_0x920ce8[_0x5ece11(0x255)]('/embeddings')&&(_0x920ce8=_0x920ce8['slice'](0x0,-0xb)),_0x920ce8;}function _0x5667(){const _0x545038=['[翰林院-日志]\x20查询成功,返回\x20','[翰林院-日志]\x20清空宝库API错误:','测试连接','Authorization','第1章','[翰林院-核心]\x20已锁定忆识宝库ID:\x20','/v1/models','2232873mYTtZQ','\x20个块。','\x20个向量条目。','[翰林院-日志]\x20获取向量列表API错误:','[翰林院-日志]\x20/api/vector/list\x20响应状态:\x20','846630hTXnGP','toISOString','error','Rerank\x20API\x20请求失败\x20(','8RdKLFC',',\x20第','retrieval','advanced','getContext','aborted','rerank_score','score','maxResults','vectors_rearrangeChat','/api/vector/insert','Rerank模型API的响应格式无效:\x20未找到\x20\x27data\x27\x20数组。',',\x20第1卷,\x20第1章,\x20第','depth','messageTypes','[翰林院-日志]\x20/api/vector/query\x20响应内容:','149449cEtkdi','chat','[翰林院-Rerank]\x20开始外部API重排序...','翰林院忆识核心已启动\x20(V5.1-借壳上市版),已注册全局函数:\x20','2734398LxqFwQ','is_user','push','length','endsWith','info','...)','No\x20messages\x20to\x20process.','now','index','replace','Bearer\x20','[来源:\x20','[翰林院-日志]\x20/api/vector/purge\x20响应状态:\x20','POST','openai','3OPtovy','message','isArray','(已锁定:\x20','AbortError','chat_history','\x20条消息分解为\x20','abs','json','[翰林院-Rerank]\x20元数据加权排序完成。','模型API的响应格式无效:\x20未找到\x20\x27data\x27\x20数组。','11noOKBV','hashes','condensation','[翰林院-Rerank]\x20开始元数据加权最终排序...','[翰林院-核心]\x20文本录入任务被用户中止。','[翰林院-核心]\x20文本录入失败:\x20','核心未初始化','application/json','webllm','HANLINYUAN_RAG','正在智能分块...','url','GET','manual','substring','max','filter','4tcIPBn','success','节]\x0a','[翰林院]\x20未能获取SillyTavern上下文,初始化失败。','[翰林院-核心]\x20已将\x20','notify','data','https://api.openai.com','第1卷','正在处理\x20','外部Rerank完成','map','split','depth_role','[翰林院-日志]\x20统计成功,向量总数:\x20','3654217xmHzgm','/api/vector/purge','2655628JYXgFu','hybrid_alpha','matchThreshold','top_n','Rerank失败:\x20','getRequestHeaders','[翰林院-核心]\x20聊天记录凝识失败:\x20','user','status','API\x20URL\x20或\x20Key\x20未提供。','toString','/v1/rerank','enabled','[翰林院-Rerank]\x20正在从\x20','position','findIndex','extensionSettings','test','quiet','[翰林院-核心]\x20将来源\x27','[翰林院-日志]\x20开始清空宝库...','name','[翰林院-核心]\x20聊天记录凝识完成,成功插入\x20','trim','[翰林院-日志]\x20宝库查询API错误:','宝库查询API错误\x20','min','queryMessageCount','forEach','log','):\x20','final_score','stringify','/v1/embeddings','find','results','\x20获取模型列表...','文本块和向量数量不匹配','floor','batchSize','忆识存入API错误\x20','[翰林院-日志]\x20开始获取向量总数...','text','custom','injection','在insertVectors内部也无法获取collectionId','[翰林院-日志]\x20开始向量查询\x20(采用最终API交互模式)...','无法确定当前忆识宝库的ID,请确认角色已正确加载。','翰林院忆识核心已启动\x20(V5.1-和平共存版),已代理\x20','source','获取模型列表失败\x20(','输入文本为空','send_date','Rerank\x20API\x20URL\x20或\x20Key\x20未提供。','rerank','warning','lorebook','/api/vector/list','vector','mes','/rerank','\x20条结果。','[翰林院-Rerank]\x20外部Rerank失败,将仅使用内部加权。','[翰林院-日志]\x20查询目标集合ID:\x20','请先配置API\x20Key','sort','\x20个知识块,准备入库。','{{text}}','apiKey','[翰林院-日志]\x20发送到\x20/api/vector/query\x20的请求体:','metadata','5568490FBJNpE','original_index','model','/v1','join','hanlinyuan-rag-core','slice','clearJob','[翰林院-核心]\x20insertVectors被调用时未提供collectionId!'];_0x5667=function(){return _0x545038;};return _0x5667();}async function fetchEmbeddingModels(){const _0x1f7722=_0x3a0919,{apiKey:_0x5c9125}=settings['retrieval'],_0x5359b4=getApiEndpointUrl(!![]);if(!_0x5359b4||!_0x5c9125)throw new Error(_0x1f7722(0x1e6));const _0xbbd8b2=getSanitizedBaseUrl(_0x5359b4),_0x4e82cf=_0xbbd8b2+_0x1f7722(0x233);console['log']('[翰林院]\x20正在从\x20'+_0x4e82cf+_0x1f7722(0x201));const _0x5b644c=await fetch(_0x4e82cf,{'method':_0x1f7722(0x278),'headers':getApiHeaders()});if(!_0x5b644c['ok']){const _0x1e2069=await _0x5b644c['text']();throw new Error(_0x1f7722(0x20f)+_0x5b644c[_0x1f7722(0x1e5)]+_0x1f7722(0x1fb)+_0x1e2069);}const _0x3c062f=await _0x5b644c[_0x1f7722(0x269)]();if(!_0x3c062f[_0x1f7722(0x283)]||!Array[_0x1f7722(0x263)](_0x3c062f[_0x1f7722(0x283)]))throw new Error(_0x1f7722(0x26b));return _0x3c062f['data'][_0x1f7722(0x288)](_0x243720=>_0x243720['id'])[_0x1f7722(0x21e)]();}function getRerankBaseUrl(_0x37207c){const _0x91497f=_0x3a0919;let _0x292c65=_0x37207c[_0x91497f(0x1f4)]();return _0x292c65['endsWith']('/')&&(_0x292c65=_0x292c65[_0x91497f(0x22a)](0x0,-0x1)),_0x292c65[_0x91497f(0x255)](_0x91497f(0x227))&&(_0x292c65=_0x292c65[_0x91497f(0x22a)](0x0,-0x3)),_0x292c65[_0x91497f(0x255)](_0x91497f(0x219))&&(_0x292c65=_0x292c65[_0x91497f(0x22a)](0x0,-0x7)),_0x292c65;}async function fetchRerankModels(){const _0x1036a8=_0x3a0919,{url:_0x5e34fd,apiKey:_0x368885}=settings[_0x1036a8(0x213)];if(!_0x5e34fd||!_0x368885)throw new Error(_0x1036a8(0x212));const _0x1858de=getRerankBaseUrl(_0x5e34fd),_0x5e2d4b=_0x1858de+'/v1/models';console[_0x1036a8(0x1fa)](_0x1036a8(0x1ea)+_0x5e2d4b+_0x1036a8(0x201));const _0xeda729=await fetch(_0x5e2d4b,{'method':'GET','headers':{'Authorization':_0x1036a8(0x25c)+_0x368885}});if(!_0xeda729['ok']){const _0x281bd6=await _0xeda729[_0x1036a8(0x207)]();throw new Error('获取Rerank模型列表失败\x20('+_0xeda729['status']+_0x1036a8(0x1fb)+_0x281bd6);}const _0x2c7d4a=await _0xeda729[_0x1036a8(0x269)]();if(!_0x2c7d4a[_0x1036a8(0x283)]||!Array[_0x1036a8(0x263)](_0x2c7d4a[_0x1036a8(0x283)]))throw new Error(_0x1036a8(0x248));return _0x2c7d4a[_0x1036a8(0x283)]['map'](_0x443e9b=>_0x443e9b['id'])[_0x1036a8(0x21e)]();}function getApiEndpointUrl(_0x276fcc=![]){const _0x11e5c7=_0x3a0919,{apiEndpoint:_0x569119,customApiUrl:_0x20a7f8}=settings[_0x11e5c7(0x23f)];let _0xbca49a;switch(_0x569119){case _0x11e5c7(0x260):_0xbca49a=_0x11e5c7(0x284);break;case'azure':case'custom':_0xbca49a=_0x20a7f8;break;default:_0xbca49a=_0x11e5c7(0x284);break;}if(_0x276fcc)return _0xbca49a;return getSanitizedBaseUrl(_0xbca49a)+_0x11e5c7(0x1fe);}function getApiHeaders(){const _0xf45fd8=_0x3a0919,_0x412b61={'Content-Type':_0xf45fd8(0x273)},{apiKey:_0x47c4d9,apiEndpoint:_0x51e7d1}=settings[_0xf45fd8(0x23f)];switch(_0x51e7d1){case _0xf45fd8(0x260):case _0xf45fd8(0x208):_0x412b61[_0xf45fd8(0x230)]=_0xf45fd8(0x25c)+_0x47c4d9;break;case'azure':_0x412b61['api-key']=_0x47c4d9;break;}return _0x412b61;}async function getEmbeddings(_0x364cd0,_0x3e6090=null){const _0x234dfa=_0x3a0919;if(!settings[_0x234dfa(0x23f)]['apiKey'])throw new Error(_0x234dfa(0x21d));const _0x1ba5c7=getApiEndpointUrl(),_0xe9bdfa=getApiHeaders(),_0xa1bb07=settings['retrieval']['embeddingModel'],_0x591079=settings[_0x234dfa(0x23f)][_0x234dfa(0x204)]||0x5,_0x283103=[];for(let _0x68541b=0x0;_0x68541b<_0x364cd0[_0x234dfa(0x254)];_0x68541b+=_0x591079){if(_0x3e6090?.[_0x234dfa(0x242)])throw new Error('AbortError');const _0x1ce6f5=_0x364cd0[_0x234dfa(0x22a)](_0x68541b,_0x68541b+_0x591079),_0x38bda0=await fetch(_0x1ba5c7,{'method':_0x234dfa(0x25f),'headers':_0xe9bdfa,'body':JSON[_0x234dfa(0x1fd)]({'input':_0x1ce6f5,'model':_0xa1bb07}),'signal':_0x3e6090});if(!_0x38bda0['ok']){const _0x16fca1=await _0x38bda0[_0x234dfa(0x207)]();throw new Error('神力获取失败\x20'+_0x38bda0[_0x234dfa(0x1e5)]+':\x20'+_0x16fca1);}const _0x439741=await _0x38bda0['json']();_0x283103['push'](..._0x439741['data']['map'](_0x474abc=>_0x474abc['embedding'])),_0x68541b+_0x591079<_0x364cd0[_0x234dfa(0x254)]&&await new Promise(_0x32c85c=>setTimeout(_0x32c85c,0xc8));}return _0x283103;}async function queryVectors(_0x42d52d){const _0x144a22=_0x3a0919;console[_0x144a22(0x1fa)](_0x144a22(0x20b));const _0x103d74=getCollectionId();console[_0x144a22(0x1fa)](_0x144a22(0x21c)+_0x103d74);const _0x5eb0e0=(await getEmbeddings([_0x42d52d]))[0x0],_0x462fa7={'collectionId':_0x103d74,'searchText':_0x42d52d,'topK':settings['advanced'][_0x144a22(0x245)],'threshold':settings[_0x144a22(0x240)][_0x144a22(0x1df)],'source':_0x144a22(0x274),'embeddings':{[_0x42d52d]:_0x5eb0e0}};console[_0x144a22(0x1fa)](_0x144a22(0x222),JSON[_0x144a22(0x1fd)](_0x462fa7,null,0x2));const _0x144870=await fetch('/api/vector/query',{'method':_0x144a22(0x25f),'headers':context['getRequestHeaders'](),'body':JSON[_0x144a22(0x1fd)](_0x462fa7)});console[_0x144a22(0x1fa)]('[翰林院-日志]\x20/api/vector/query\x20响应状态:\x20'+_0x144870[_0x144a22(0x1e5)]);if(!_0x144870['ok']){const _0x31469c=await _0x144870['text']();console[_0x144a22(0x23b)](_0x144a22(0x1f5),_0x31469c);throw new Error(_0x144a22(0x1f6)+_0x144870[_0x144a22(0x1e5)]+':\x20'+_0x31469c);}const _0x2639b0=await _0x144870['json']();console[_0x144a22(0x1fa)](_0x144a22(0x24c),_0x2639b0);const _0x10f74d=_0x2639b0[_0x144a22(0x223)]||_0x2639b0['results']||_0x2639b0[_0x144a22(0x283)]||[];return console[_0x144a22(0x1fa)](_0x144a22(0x22d)+_0x10f74d[_0x144a22(0x254)]+_0x144a22(0x21a)),_0x10f74d;}async function insertVectors(_0x45d2af,_0x31b207=null,_0x50abb7){const _0xd12960=_0x3a0919;if(!_0x50abb7){console[_0xd12960(0x23b)](_0xd12960(0x22c)),_0x50abb7=getCollectionId();if(!_0x50abb7)throw new Error(_0xd12960(0x20a));}if(_0x45d2af[_0xd12960(0x254)]===0x0)return{'success':!![],'count':0x0};const _0x24b215=_0x45d2af[_0xd12960(0x288)]((_0x416019,_0x4e5590)=>({'hash':generateHash(_0x416019[_0xd12960(0x207)]+Date[_0xd12960(0x259)]()+_0x4e5590),'text':_0x416019[_0xd12960(0x207)],'metadata':_0x416019[_0xd12960(0x223)]||{'source':'unknown','timestamp':new Date()[_0xd12960(0x23a)]()}})),_0x2180a5=_0x24b215['reduce']((_0x5eda18,_0x2dbfd0,_0x38a9ab)=>{const _0x4bf6a2=_0xd12960;return _0x5eda18[_0x2dbfd0[_0x4bf6a2(0x207)]]=_0x45d2af[_0x38a9ab][_0x4bf6a2(0x217)],_0x5eda18;},{}),_0x2996a7={'collectionId':_0x50abb7,'items':_0x24b215,'source':_0xd12960(0x274),'embeddings':_0x2180a5},_0x5ef4a6=await fetch(_0xd12960(0x247),{'method':_0xd12960(0x25f),'headers':context['getRequestHeaders'](),'body':JSON[_0xd12960(0x1fd)](_0x2996a7),'signal':_0x31b207});if(!_0x5ef4a6['ok']){const _0x5c5534=await _0x5ef4a6['text']();console['error']('[翰林院-日志]\x20忆识存入API错误:',_0x5c5534);throw new Error(_0xd12960(0x205)+_0x5ef4a6[_0xd12960(0x1e5)]+':\x20'+_0x5c5534);}return{'success':!![],'count':_0x24b215[_0xd12960(0x254)]};}async function testApiConnection(){const _0x4f8d35=_0x3a0919;await getEmbeddings([_0x4f8d35(0x22f)]);}async function getVectorCount(){const _0x2e0a28=_0x3a0919;console[_0x2e0a28(0x1fa)](_0x2e0a28(0x206));const _0xa6c6b6=getCollectionId();console['log']('[翰林院-日志]\x20统计目标集合ID:\x20'+_0xa6c6b6);const _0x311d1f={'collectionId':_0xa6c6b6,'source':'webllm','embeddings':{}};console['log']('[翰林院-日志]\x20发送到\x20/api/vector/list\x20的请求体:',JSON[_0x2e0a28(0x1fd)](_0x311d1f,null,0x2));const _0xf86fb4=await fetch(_0x2e0a28(0x216),{'method':'POST','headers':context['getRequestHeaders'](),'body':JSON[_0x2e0a28(0x1fd)](_0x311d1f)});console['log'](_0x2e0a28(0x238)+_0xf86fb4[_0x2e0a28(0x1e5)]);if(!_0xf86fb4['ok']){const _0x16a3f9=await _0xf86fb4[_0x2e0a28(0x207)]();return console[_0x2e0a28(0x23b)](_0x2e0a28(0x237),_0x16a3f9),0x0;}const _0x34eae5=await _0xf86fb4[_0x2e0a28(0x269)]();let _0xa9439a=0x0;if(Array['isArray'](_0x34eae5))_0xa9439a=_0x34eae5[_0x2e0a28(0x254)];else _0x34eae5&&_0x34eae5['hashes']&&(_0xa9439a=_0x34eae5[_0x2e0a28(0x26d)][_0x2e0a28(0x254)]);return console[_0x2e0a28(0x1fa)](_0x2e0a28(0x1da)+_0xa9439a),_0xa9439a;}async function purgeStorage(){const _0x24b3ca=_0x3a0919;console[_0x24b3ca(0x1fa)](_0x24b3ca(0x1f1));const _0xdff36d=getCollectionId();console[_0x24b3ca(0x1fa)]('[翰林院-日志]\x20清空目标集合ID:\x20'+_0xdff36d);const _0x19f22e={'collectionId':_0xdff36d};console[_0x24b3ca(0x1fa)]('[翰林院-日志]\x20发送到\x20/api/vector/purge\x20的请求体:',JSON[_0x24b3ca(0x1fd)](_0x19f22e,null,0x2));const _0x3d47f6=await fetch(_0x24b3ca(0x1dc),{'method':_0x24b3ca(0x25f),'headers':context[_0x24b3ca(0x1e2)](),'body':JSON[_0x24b3ca(0x1fd)](_0x19f22e)});console[_0x24b3ca(0x1fa)](_0x24b3ca(0x25e)+_0x3d47f6[_0x24b3ca(0x1e5)]);if(!_0x3d47f6['ok']){const _0x20982a=await _0x3d47f6[_0x24b3ca(0x207)]();console['error'](_0x24b3ca(0x22e),_0x20982a);}else console['log']('[翰林院-日志]\x20清空宝库API调用成功。');return _0x3d47f6['ok'];}function getMessagesForCondensation(_0x45cb03=null){const _0x264537=_0x3a0919;if(!settings[_0x264537(0x26e)][_0x264537(0x1e9)])return showNotification('凝识之权未开启',_0x264537(0x214)),[];const {layerStart:_0x59f972,layerEnd:_0x153ca2}=settings['condensation'],_0x5457eb=_0x45cb03||settings['condensation'][_0x264537(0x24b)],_0x156b72=context[_0x264537(0x24e)][_0x264537(0x254)],_0x374913=Math[_0x264537(0x27b)](0x0,_0x59f972-0x1),_0x9fc1=Math[_0x264537(0x1f7)](_0x156b72,_0x153ca2),_0x23105b=context['chat'][_0x264537(0x22a)](_0x374913,_0x9fc1);return _0x23105b[_0x264537(0x27c)](_0x1bc1b4=>{const _0x3c6880=_0x264537,_0x35359=_0x1bc1b4[_0x3c6880(0x252)]===!![],_0x3616f1=_0x1bc1b4[_0x3c6880(0x252)]===![];if(!_0x1bc1b4[_0x3c6880(0x218)]||!_0x1bc1b4[_0x3c6880(0x218)]['trim']())return![];return _0x5457eb[_0x3c6880(0x1e4)]&&_0x35359||_0x5457eb['ai']&&_0x3616f1;});}async function processCondensation(_0x2e2388,_0xde3e98=()=>{}){const _0x5c976e=_0x3a0919;if(!_0x2e2388||_0x2e2388[_0x5c976e(0x254)]===0x0)return{'success':![],'error':_0x5c976e(0x258)};try{const _0x4110c3=getCollectionId();if(!_0x4110c3)throw new Error('无法确定当前忆识宝库的ID,请确认角色已正确加载。');_0xde3e98('[翰林院-核心]\x20凝识任务已锁定忆识宝库ID:\x20'+_0x4110c3,_0x5c976e(0x256));const _0x3390ad=[],_0x4de3d6=context['chat'],{chunkSize:_0x20672b,overlap:_0x28bc64}=settings[_0x5c976e(0x240)];for(const _0x1950b9 of _0x2e2388){const _0x521641=(_0x1950b9[_0x5c976e(0x218)]||'')['replace'](/<[^>]*>/g,'')[_0x5c976e(0x1f4)]();if(_0x521641[_0x5c976e(0x254)]===0x0)continue;const _0xaffb11=_0x4de3d6[_0x5c976e(0x1ec)](_0x55a79e=>_0x55a79e===_0x1950b9),_0x36a667=_0xaffb11!==-0x1?_0xaffb11+0x1:-0x1,_0x75a173={'source':'chat_history','sourceName':'聊天记录\x20#'+_0x36a667,'floor':_0x36a667,'is_user':_0x1950b9[_0x5c976e(0x252)],'timestamp':new Date(_0x1950b9[_0x5c976e(0x211)])['toISOString']()};let _0x13d1d1=0x0;while(_0x13d1d1<_0x521641[_0x5c976e(0x254)]){const _0x3b03b3=Math[_0x5c976e(0x1f7)](_0x13d1d1+_0x20672b,_0x521641[_0x5c976e(0x254)]),_0x266e21=_0x521641[_0x5c976e(0x27a)](_0x13d1d1,_0x3b03b3);_0x3390ad[_0x5c976e(0x253)]({'text':_0x266e21,'metadata':_0x75a173}),_0x13d1d1+=_0x20672b-_0x28bc64;if(_0x13d1d1>=_0x521641[_0x5c976e(0x254)])break;}}if(_0x3390ad[_0x5c976e(0x254)]===0x0)return{'success':!![],'count':0x0};_0xde3e98(_0x5c976e(0x281)+_0x2e2388['length']+_0x5c976e(0x267)+_0x3390ad[_0x5c976e(0x254)]+_0x5c976e(0x21f),'info');const _0xc2105b=settings['retrieval']['batchSize']||0x5;let _0x3cea1e=0x0;for(let _0x137c28=0x0;_0x137c28<_0x3390ad[_0x5c976e(0x254)];_0x137c28+=_0xc2105b){const _0x5bc305=_0x3390ad[_0x5c976e(0x22a)](_0x137c28,_0x137c28+_0xc2105b),_0xc114d7=_0x5bc305[_0x5c976e(0x288)](_0x4a8576=>_0x4a8576[_0x5c976e(0x207)]),_0x11fae3=await getEmbeddings(_0xc114d7);if(_0x5bc305[_0x5c976e(0x254)]!==_0x11fae3[_0x5c976e(0x254)])throw new Error('文本块和向量数量不匹配');const _0x25c257=_0x5bc305['map']((_0x7c8a7b,_0x8a814f)=>({..._0x7c8a7b,'vector':_0x11fae3[_0x8a814f]}));await insertVectors(_0x25c257,null,_0x4110c3),_0x3cea1e+=_0x5bc305[_0x5c976e(0x254)];}return _0xde3e98(_0x5c976e(0x1f3)+_0x3cea1e+'\x20个条目。',_0x5c976e(0x27e)),{'success':!![],'count':_0x3cea1e};}catch(_0x5048e2){return console[_0x5c976e(0x23b)]('[翰林院-核心]\x20processCondensation\x20失败:',_0x5048e2),_0xde3e98(_0x5c976e(0x1e3)+_0x5048e2[_0x5c976e(0x262)],_0x5c976e(0x23b)),{'success':![],'error':_0x5048e2[_0x5c976e(0x262)]};}}async function rerankResults(_0x39f99c,_0x4b8390,_0xcefcb9){const _0x4cae16=_0x3a0919;let _0x31edb5=_0x39f99c;if(_0xcefcb9[_0x4cae16(0x213)]['enabled']&&_0x39f99c[_0x4cae16(0x254)]>0x0){console['log'](_0x4cae16(0x24f));try{const _0x5e694b=_0x39f99c[_0x4cae16(0x288)]((_0x33f562,_0x342403)=>({'text':_0x33f562[_0x4cae16(0x207)],'original_index':_0x342403})),_0x5c96e1=getRerankBaseUrl(_0xcefcb9[_0x4cae16(0x213)][_0x4cae16(0x277)]),_0x4fdd63=_0x5c96e1+_0x4cae16(0x1e8),_0x59c0bf=await fetch(_0x4fdd63,{'method':_0x4cae16(0x25f),'headers':{'Content-Type':'application/json','Authorization':_0x4cae16(0x25c)+_0xcefcb9[_0x4cae16(0x213)][_0x4cae16(0x221)]},'body':JSON[_0x4cae16(0x1fd)]({'query':_0x4b8390,'documents':_0x5e694b[_0x4cae16(0x288)](_0x4f3f3d=>_0x4f3f3d[_0x4cae16(0x207)]),'model':_0xcefcb9[_0x4cae16(0x213)][_0x4cae16(0x226)],'top_n':_0xcefcb9[_0x4cae16(0x213)][_0x4cae16(0x1e0)]})});if(!_0x59c0bf['ok'])throw new Error(_0x4cae16(0x23c)+_0x59c0bf[_0x4cae16(0x1e5)]+_0x4cae16(0x1fb)+await _0x59c0bf[_0x4cae16(0x207)]());const _0x43e901=await _0x59c0bf['json'](),_0x1c042c=_0x39f99c[_0x4cae16(0x288)]((_0x42b645,_0xc02253)=>({..._0x42b645,'original_index':_0xc02253}));_0x31edb5=_0x1c042c[_0x4cae16(0x288)](_0x20cddd=>{const _0x27a10f=_0x4cae16,_0x14639b=_0x43e901[_0x27a10f(0x200)][_0x27a10f(0x1ff)](_0x5b503d=>_0x5b503d[_0x27a10f(0x25a)]===_0x20cddd[_0x27a10f(0x225)]),_0x237f44=_0x14639b?_0x14639b['relevance_score']:0x0;return{..._0x20cddd,'rerank_score':_0x237f44};});if(_0xcefcb9[_0x4cae16(0x213)][_0x4cae16(0x282)])showNotification(_0x4cae16(0x287),_0x4cae16(0x27e));}catch(_0x542364){console[_0x4cae16(0x23b)](_0x4cae16(0x21b),_0x542364);if(_0xcefcb9[_0x4cae16(0x213)]['notify'])showNotification(_0x4cae16(0x1e1)+_0x542364[_0x4cae16(0x262)],_0x4cae16(0x23b));_0x31edb5[_0x4cae16(0x1f9)](_0x2d4fc5=>_0x2d4fc5[_0x4cae16(0x243)]=0x0);}}else _0x31edb5['forEach'](_0x2a2760=>_0x2a2760[_0x4cae16(0x243)]=0x0);console['log'](_0x4cae16(0x26f));const _0x3fe3fa=context[_0x4cae16(0x24e)][_0x4cae16(0x254)],_0x18f8aa=_0xcefcb9['rerank'][_0x4cae16(0x1de)],_0x222d47=_0x31edb5[_0x4cae16(0x288)](_0x533ffe=>{const _0x2af2c3=_0x4cae16;let _0x11e37d=0x1;const _0x422c0d=_0x533ffe['metadata']||{};switch(_0x422c0d[_0x2af2c3(0x20e)]){case _0x2af2c3(0x215):_0x11e37d*=1.2;break;case _0x2af2c3(0x279):_0x11e37d*=1.1;break;case _0x2af2c3(0x266):if(_0x422c0d[_0x2af2c3(0x203)]&&_0x3fe3fa>0x0){const _0x421bcf=_0x422c0d[_0x2af2c3(0x203)]/_0x3fe3fa;_0x11e37d*=0x1+_0x421bcf;}break;}const _0x545e88=_0x533ffe[_0x2af2c3(0x243)]*_0x18f8aa+(_0x533ffe[_0x2af2c3(0x244)]||0x0)*(0x1-_0x18f8aa),_0x107ac0=_0x545e88*_0x11e37d;return{..._0x533ffe,'final_score':_0x107ac0};});return _0x222d47[_0x4cae16(0x21e)]((_0xd8b6de,_0x1afd2f)=>(_0x1afd2f[_0x4cae16(0x1fc)]||0x0)-(_0xd8b6de[_0x4cae16(0x1fc)]||0x0)),console[_0x4cae16(0x1fa)](_0x4cae16(0x26a)),_0x222d47[_0x4cae16(0x22a)](0x0,_0xcefcb9[_0x4cae16(0x213)][_0x4cae16(0x1e0)]);}async function rearrangeChat(_0x42af50,_0x55fb5c,_0x43611a,_0x165c1b){const _0xc56163=_0x3a0919;setExtensionPrompt(_0xc56163(0x275),'',settings[_0xc56163(0x209)]['position'],settings[_0xc56163(0x209)][_0xc56163(0x24a)],![],settings[_0xc56163(0x209)][_0xc56163(0x28a)]);if(_0x165c1b===_0xc56163(0x1ef)||!settings['retrieval']['enabled'])return;const _0x111e99=_0x42af50['slice'](-settings[_0xc56163(0x240)][_0xc56163(0x1f8)]);if(_0x111e99[_0xc56163(0x254)]===0x0)return;const _0x3226f2=_0x111e99['map'](_0x430280=>_0x430280[_0xc56163(0x218)])[_0xc56163(0x228)]('\x20')['replace'](/<[^>]*>/g,'')[_0xc56163(0x1f4)]();if(!_0x3226f2)return;try{const _0x5c1490=await queryVectors(_0x3226f2);if(_0x5c1490[_0xc56163(0x254)]===0x0)return;const _0x53e2d9=await rerankResults(_0x5c1490,_0x3226f2,settings);if(_0x53e2d9[_0xc56163(0x254)]===0x0)return;const _0xac4b0e=_0x53e2d9[_0xc56163(0x288)](_0x5965e0=>_0x5965e0['text'])[_0xc56163(0x228)]('\x0a\x0a'),_0x1c0414=settings[_0xc56163(0x209)]['template'][_0xc56163(0x25b)](_0xc56163(0x220),_0xac4b0e);setExtensionPrompt(_0xc56163(0x275),_0x1c0414,settings[_0xc56163(0x209)][_0xc56163(0x1eb)],settings[_0xc56163(0x209)][_0xc56163(0x24a)],![],settings[_0xc56163(0x209)]['depth_role']);}catch(_0x367ecc){console['error']('[翰林院]\x20检索或注入时发生错误:',_0x367ecc);if(settings[_0xc56163(0x23f)]['notify'])showNotification('忆识检索失败:\x20'+_0x367ecc['message'],_0xc56163(0x23b));}}