From 1978c36294a5b465e514f86c10f81663d8e0a601 Mon Sep 17 00:00:00 2001 From: Michael Hughes Date: Mon, 18 Mar 2024 23:45:54 +0000 Subject: [PATCH] first RAG based response --- mod/xaichat/view.php | 19 +++++++-- search/engine/solr/classes/engine.php | 3 +- search/engine/solrrag/classes/ai/aiclient.php | 2 +- search/engine/solrrag/classes/engine.php | 39 ++++++++++++------- search/engine/solrrag/classes/schema.php | 1 + 5 files changed, 44 insertions(+), 20 deletions(-) diff --git a/mod/xaichat/view.php b/mod/xaichat/view.php index cf44d40d0a9c..b519113eb513 100644 --- a/mod/xaichat/view.php +++ b/mod/xaichat/view.php @@ -92,9 +92,7 @@ $progress->update(1, $totalsteps,'Processing System Prompts'); } $progress->update(1, $totalsteps,'Looking for relevant context'); -// $vector = $aiclient->embed_query($data->userprompt); - $vector = [-0.027786661000000001,0.0090511510000000003,-0.044274903999999997,-0.014116816000000001,-0.027637671999999999,-0.026917553,-0.020126086000000001,0.072856180000000006,-0.018462362,-0.028258463000000001,-0.0012904718999999999,0.022807906999999999,0.0097464390000000008,-0.0071825663999999997,-0.013272539,-0.043306466000000002,-6.3679705e-5,0.00088850889999999997,-0.046609079999999997,0.053785439999999997,-0.0091194380000000005,-0.0021650129999999999,-0.013061468999999999,-0.041270266999999999,0.010646587000000001,0.042685675999999999,-0.013620182,0.016376499999999999,0.039755534000000002,0.041295100000000001,0.0019896391000000001,-0.063320810000000005,0.0015030932999999999,-0.061185284999999999,0.013483607999999999,-0.041568250000000001,0.0011445857000000001,-0.061880574000000001,0.012353766,0.022311273999999999,-0.023714265000000002,-0.0024816170000000002,0.047105714999999999,0.023143134999999999,-0.016500656999999998,-0.027513513,-0.0022922754,-0.012788320000000001,-0.0023962580000000001,-0.0092001410000000002,-0.017034540000000001,0.020970362999999999,0.0086290120000000001,0.018400282,-0.0040817090000000002,0.01021824,0.0033367584000000001,0.009131854,-0.0040910210000000002,0.0036564662999999998,0.001761498,0.0088152500000000002,-0.027215533,-0.089940383999999998,-0.038762268000000002,0.022820323999999999,-0.084676064999999995,0.0099450920000000009,-0.029947017999999999,0.027836324999999999,0.017940896000000001,0.0044790159999999997,0.016339251999999999,0.032008050000000003,0.023230046000000001,-0.0093987949999999997,0.016997293,-0.017940896000000001,0.014514123,0.039234072000000002,-0.010187201,-0.0056398977000000003,-0.0148990145,-0.046435259999999999,-0.0056709372000000001,0.0055716102999999999,0.013669845999999999,-0.028183969,-0.037446189999999997,-0.026768561,0.026867888999999999,-0.040425990000000002,-0.023602521000000001,0.024359887,0.016897965000000001,-0.054629717000000001,0.0031970800000000001,0.021255927000000001,0.048322469999999999,0.013433944,-0.0063879521999999998,-0.058155819999999997,-0.023453531999999999,0.019778442,0.012540002999999999,0.041841400000000001,0.031536248000000003,0.028010146999999999,-0.054331740000000003,0.035558979999999997,-0.048272807000000001,-0.0078468140000000006,-0.0033957337,-0.010255488,-0.022869987000000001,0.045963459999999998,0.0138933305,-0.0084303590000000001,0.02984769,0.017369768000000001,0.039383059999999998,-0.005764056,0.016438580000000001,-0.046956724999999998,0.033075809999999997,0.0016652752,0.028928919000000001,0.0010925943,-0.026048442000000002,-0.031039612000000001,0.0114287855,0.013483607999999999,-0.025216580999999998,0.021889135000000001,-0.037595179999999999,-0.019654283000000002,-0.014501707000000001,-0.013421529,-0.032504680000000001,0.017071787000000001,-0.064810709999999994,0.0017537382,-0.058304809999999999,-0.0014231662000000001,-0.027910819999999999,0.0062265460000000003,-0.00046249022000000001,0.016724143,-0.018251291999999999,-0.0136946775,-0.025551809000000002,-0.035608639999999997,-0.048819102000000003,0.021802223999999999,-0.078021170000000001,0.0022814115999999999,0.023950164999999999,-0.021255927000000001,-0.013942994,0.06351946,-0.048918429999999999,0.010801786000000001,-0.024993095999999999,0.0083248239999999998,0.0013168555,0.012502756,0.031958385999999998,0.0066921404000000002,-0.027861156000000002,-0.036055613,0.004379689,0.010776954,-0.023950164999999999,-0.022447848999999999,-0.048843934999999998,0.031412086999999998,-0.019592202999999999,0.0013766068999999999,0.035211336000000003,0.011006647,0.012285478000000001,0.0045938626999999996,0.027414186,-0.038091812000000003,0.051053955999999998,-0.010702458,0.013011806000000001,-0.067095230000000006,-0.041692406000000001,-0.035236169999999997,0.014787272000000001,0.035112009999999999,-0.013645014,-0.024732362000000001,-0.028680601999999999,0.025775295,-0.00060760044,0.019294222999999999,0.030319492999999999,0.0049942737000000003,-0.0044107290000000004,0.017096618000000001,-0.00083962149999999998,0.018598936,-0.031511415000000001,-0.02674373,-0.025067592,0.012155111999999999,-0.0054443479999999999,-0.028481949999999999,0.057659183000000003,0.0069280415999999996,0.011012855,-0.025166918,-0.011484656500000001,0.022062957000000001,-0.033795930000000002,0.068982440000000006,-0.016364085,0.048595619999999999,-0.028233632000000002,0.081398280000000003,0.012751073,-0.040972290000000001,-0.0039575505000000004,0.02291965,0.0042306990000000001,-0.041220605,-0.027439017,0.01542048,0.0006921834,0.016910382000000002,-0.024732362000000001,-0.033100642,-0.016463410000000001,-0.0070149525999999999,-0.040525316999999998,-0.017071787000000001,0.018139550000000001,-0.017742243000000001,-0.022770660000000002,-0.038191139999999998,-0.013868498999999999,0.012825568000000001,0.0084427740000000001,-0.010497596999999999,0.0013890227,-0.0070646160000000001,0.031362425999999999,-0.031337592999999997,0.035236169999999997,-0.0023947059999999999,0.021106936,0.019915016000000001,0.022969313000000002,0.025874620000000001,0.026917553,-0.040699140000000002,0.040972290000000001,-0.019964678,-0.032703336,-0.033795930000000002,0.017692579,-0.054331740000000003,-0.040574983000000002,-0.0091132299999999999,-0.016860718,-0.011503279999999999,-0.012428260999999999,0.064314074999999998,-0.032703336,0.021442164,-0.0040475655999999997,0.035658307,-0.057559859999999997,0.074594400000000005,-0.016041270999999999,0.022112619999999999,-0.012726240999999999,-0.04248702,-0.0079647650000000004,0.023403868000000001,-0.017332520000000001,-0.012527587999999999,-0.015308736999999999,0.011497073,0.070770316,0.0032995108000000001,0.0061892989999999997,-0.00035889552000000001,0.028630938000000002,-0.048943263000000001,0.023465946000000001,0.030220167999999999,-0.034367059999999998,-0.026247097,0.0021060377000000001,0.017034540000000001,-0.022447848999999999,-0.030145670999999999,0.055126349999999998,0.036105279999999997,0.010752121999999999,0.030319492999999999,-0.0055405706999999997,0.0056647295,-0.032281197999999997,0.0025530079999999998,0.021578738,-0.02124351,-0.054530393000000003,0.038265634,-0.035012685000000002,0.0023605625999999998,0.086811589999999994,-0.0062731057,-0.0061365315000000004,-0.0084179430000000006,0.019877767000000001,-0.035856961999999999,0.016513073999999999,-0.041915894000000002,-0.010007171,0.044771537,-0.024210898000000002,-0.045243338000000001,0.021678065999999999,-0.011801260500000001,-0.069379739999999995,-0.010789369,0.024111569999999999,-0.06287384,-0.0070832394999999996,0.046162113999999997,0.0070335763000000003,-0.033572446999999998,-0.0025499042,-0.051202945,-0.00016218198,-0.0058602790000000004,-0.012887647,0.006400368,0.019964678,-0.001118202,-0.061483264000000003,0.027612839,0.059546391999999997,-0.039556883000000001,-0.044101080000000001,0.048620447999999997,0.019095569999999999,0.009318092,0.014303054000000001,-0.021988460000000001,0.0292269,-0.028953751999999999,0.027339690999999999,0.049315735999999999,-0.026942383,0.027662503000000001,-0.071167624999999998,0.031387255000000003,-0.038091812000000003,0.031461753000000002,-0.025253828999999998,-0.018412698000000002,-0.0069466652000000004,-0.0095167450000000001,0.0036005949999999998,-0.012260647,0.023453531999999999,0.057410865999999998,-0.013794004,0.055374670000000001,0.01556947,-0.00093739629999999995,-0.0081261700000000003,-0.023192799,-0.03866294,0.027588008000000001,-0.023639767999999999,-0.029475215999999999,0.0095415770000000007,-0.041468921999999998,-0.030046346000000002,-0.0028649562000000002,-0.032330860000000003,-0.0049601300000000001,-0.052593517999999999,-0.023379036999999998,-0.00059091660000000002,-0.034093909999999998,0.014315469000000001,-0.0088649130000000003,0.0031815602,-0.029003412999999999,-0.082093570000000005,0.055672649999999997,-0.0099575080000000003,0.019455627999999999,0.044721875000000001,0.0017521861,-0.022720996,0.033199970000000002,-0.05408342,0.010013378999999999,-0.055076689999999998,0.04966338,-0.0080206359999999994,0.028134304999999998,0.0063103530000000003,-0.012242022999999999,0.026545078,0.003845808,0.0039823823999999997,-0.0095229530000000007,-0.0056430018000000002,-0.015855035,-0.0057609519999999997,0.043231970000000002,0.025725630999999999,-0.041742069999999999,0.024210898000000002,0.04055015,-0.0022286442000000002,0.0026942384,0.045739975000000002,0.036328763,0.030096008,0.033994585000000001,0.015110083999999999,-0.025949117000000001,-0.029475215999999999,0.030716800999999998,-0.011751598,-0.029798029,-0.010243072000000001,-0.0026880304999999998,-0.031983215000000002,0.021442164,-0.017866401000000001,0.053835105000000001,0.020858620000000001,-0.04966338,-0.088102840000000002,0.026470581,0.033448286000000001,0.010491389,0.040128009999999999,-0.020933113999999999,-0.024471631000000001,-0.022820323999999999,-0.0037092335999999999,-0.012130281,0.053040490000000003,0.0094050030000000003,0.030989948999999999,0.053338469999999999,-0.0049849619999999999,-0.042313200000000002,-0.056864570000000003,-0.0141044,-0.011155636999999999,-0.015743291,0.020746877,-0.034689869999999998,0.018474778000000001,0.024782025999999999,-0.070968970000000006,-0.039979022000000003,-0.0028261568000000001,0.00065571179999999996,-0.0036626741999999999,0.025502145,-0.029673868999999999,0.060887302999999997,-0.0094360420000000004,-0.020088836999999998,0.036403257000000001,-0.0090201115000000005,-0.017655331999999999,0.025266245,0.015693627000000002,-0.015345984,-0.019952264000000001,-0.029971850000000001,0.0090821909999999999,-0.016438580000000001,-0.015668795999999999,-0.00081866980000000001,0.016537904999999999,0.0099326759999999997,0.01601644,-0.012688993500000001,-0.012912478999999999,-0.0056833530000000004,0.029450384999999999,-0.061234946999999998,0.011906795,-0.010317567,0.016773807000000002,0.015544638,-0.012862815499999999,0.037768999999999997,-0.047503023999999998,0.0041065407000000003,-0.011074934,0.0097836859999999998,-0.0054195164999999998,0.06595297,0.00099481960000000007,0.042611179999999999,-0.045293002999999998,-0.00044774642000000001,0.0090635669999999998,-0.037520683999999999,0.0063444966999999996,-0.018785172999999999,-0.00020447344,-0.035782464,0.021044858,0.0014805895,0.032728170000000001,0.016848301999999999,-0.010447933,0.020846203000000001,0.026843058,0.014588617999999999,-0.011211508,-0.0072073980000000003,0.045566152999999998,0.044746703999999998,0.0075798732999999997,-0.02011367,-0.029723532,0.017556004,0.0050253132000000001,0.065754320000000005,0.00530467,-0.019815689000000001,-0.03203288,-0.0012268406999999999,-0.022323688000000001,-0.0048608035000000001,-0.032827492999999999,0.040103180000000002,-0.027165870000000002,-0.0057392245999999996,0.057013559999999998,0.0094546660000000005,0.020895866999999999,0.011739181,0.043927260000000003,-0.024335057,-0.024868937000000001,-0.053338469999999999,-0.034044247,-0.0079771800000000004,-0.00023337909,0.0064810709999999997,0.0060868681999999997,0.0056740413,-0.032827492999999999,0.0043610656000000001,-0.011137012999999999,0.040773634000000003,0.028829591000000002,-0.0048359715999999999,-0.0034888523999999999,-0.024993095999999999,0.015631549000000002,0.031312760000000002,0.013272539,-0.062824174999999996,0.046956724999999998,0.0018794485000000001,0.025253828999999998,-0.0089890714999999993,-0.023043807999999999,0.065903305999999995,0.011981291,0.016972460000000002,-0.027364521999999999,-0.032504680000000001,-0.0097153989999999996,0.0049352985999999996,-0.019244560000000001,-0.0045907585999999997,-0.040922627000000003,0.041915894000000002,-0.024744779000000001,0.033522780000000002,-0.0058602790000000004,-0.0064189920000000001,-0.034242901999999999,0.016239925999999998,0.024881354000000001,0.025502145,0.0094360420000000004,-0.022584422,0.03143692,0.0081075469999999997,-0.0030775775999999999,-0.00019118461999999999,-0.01903349,-0.042611179999999999,0.0077102400000000001,-0.069330080000000002,0.035683140000000002,-0.026718898000000001,0.0069839129999999996,-0.0022022604999999999,-0.034143575000000002,0.0041034365999999996,-0.02542765,0.0042648427000000003,-0.028556444,0.0013494472,-0.024918599999999999,-0.0038240803000000002,-0.0059565017000000001,-0.015743291,-0.049290907000000002,0.021988460000000001,-0.013632597999999999,0.033994585000000001,-0.035434822999999997,0.059149085999999997,-0.0028416766000000002,0.018946579000000002,-0.011776429,-0.0068535465,-0.036552247000000003,-0.010267904,0.018176798000000001,-0.022671332999999998,-0.0051215360000000003,0.018462362,-0.011484656500000001,-0.0084055269999999994,0.0044666002999999999,0.057311542,-0.011174261,0.0035757634000000002,0.021752560000000001,-0.020523392000000001,0.015494974,0.0041375802999999997,0.009299468,0.0055964420000000001,-0.028159136000000001,-0.011621230999999999,0.0020749980000000002,-0.041617910000000001,6.7996150000000001e-5,0.025291075999999999,-0.020262658999999999,0.015271489500000001,0.0075612496999999997,0.02982286,-0.0021588050000000002,0.037992484999999999,0.023341787999999999,0.01873551,0.008945616,0.041841400000000001,0.027712166,0.0093677550000000002,-0.0031365528999999998,-0.035037513999999999,0.012924895,0.030393988,0.0041406843999999996,-0.031958385999999998,-0.00031932,-0.0055126350000000001,-0.0024241938000000001,-0.016662065,0.0067418039999999997,0.034044247,-0.0124034295,-0.039879695,-0.0053605409999999999,-0.021255927000000001,0.014663113,-0.018139550000000001,0.005847863,-0.044672209999999997,0.0041096450000000003,0.0013277193999999999,-0.034218070000000003,0.035782464,0.033771097999999999,0.033175137,-0.010826617,0.0020346467,0.015445311999999999,-0.0035354117999999999,-0.011074934,-0.036279100000000002,0.015134915000000001,-0.021926383000000001,0.023130719000000001,-0.010336191,0.033175137,-0.032057714000000001,0.019517709000000001,-0.0085669330000000005,0.020200579999999999,-0.0010111154000000001,0.010193408500000001,-0.011447409,0.0048235557,-0.023316956999999999,0.0010491389999999999,0.033969751999999999,0.017742243000000001,0.015681212999999999,0.022336104999999998,0.012316518,-0.0022814115999999999,0.012167528,-0.032877160000000002,0.0075364179999999996,0.010174785,-0.0044479766000000004,-0.0292269,-0.024049493000000002,-0.016587568,-0.0073253483999999999,0.040748804999999999,-0.00400411,0.0037309613999999998,0.013818835999999999,0.014886597999999999,0.0060868681999999997,-0.022820323999999999,0.017046954,-0.012496548,-0.0065493584000000001,-0.010547261,0.015544638,-0.0030418820000000001,-0.0011647615,0.013545687000000001,0.02540282,0.023403868000000001,0.0014107504,-0.0014565337999999999,-0.028084641,-0.036204603000000002,0.0086165960000000007,0.0036130110000000002,-0.0051743034,-0.021094522000000001,-0.010516220999999999,-0.015395648,-0.054778710000000001,-0.013433944,0.011975082999999999,-0.0083062009999999992,0.0028168450000000001,-0.021144183,-0.0035012683000000002,0.029351057,0.0060527246,-0.00080470194000000004,-0.011832301,-0.013371865,-0.015879865999999999,0.034069080000000002,-0.018487192999999999,0.017704995000000001,0.03116377,0.027439017,0.036229434999999997,0.027935651999999998,0.019182479999999998,0.0022705477000000002,0.024161234,0.020697213999999999,-0.025005512000000001,0.012502756,-0.027215533,-0.018648600000000001,0.049812370000000002,-0.0078716454999999998,-0.023863254,-0.034789197000000001,0.02704171,-0.0069466652000000004,-0.022646501999999999,0.0011391537,-0.059298075999999998,0.024347473000000001,0.039234072000000002,-0.014700361,-0.042909160000000002,-0.0035074762999999999,0.0075302099999999999,-0.0067542195000000003,0.0087097159999999993,0.031660404000000003,0.040997119999999998,0.046559419999999997,0.0082565369999999996,0.025191749999999999,-0.061830907999999997,0.010143746,-0.024335057,-0.036105279999999997,0.030691968,0.030120839999999999,-0.03143692,-0.014315469000000001,0.011776429,0.0022208841999999999,-0.0045473029999999999,0.019666698,-0.017233193000000001,-0.01072729,0.0078964770000000007,0.035757635000000003,-0.039258899999999999,0.044920526000000002,0.052295540000000001,-0.018437530000000001,0.031511415000000001,0.048918429999999999,-0.011192884,0.0092932599999999994,-0.026768561,-0.0061210114999999997,-0.0030279143000000001,0.0025607680000000002,-0.0055747143999999998,0.01822646,0.016984875999999999,-0.043430626,0.03866294,-0.0077412794000000004,0.022907235000000001,-0.018164381,-0.023602521000000001,0.0094546660000000005,-0.0041034365999999996,0.033572446999999998,0.020734460999999999,-0.028283294,0.0014542057999999999,0.013185628,0.018276122999999998,0.00029254835999999998,0.024794442999999999,0.0078840620000000007,0.0099140530000000008,-0.016239925999999998,-0.029897355,0.004181036,0.004742853,0.0072322297000000004,0.0090014880000000002,0.0022301962999999999,-0.029947017999999999,0.032604010000000003,0.027736996999999999,-0.00025219685999999997,-0.023503195000000001,-0.037048879999999999,-0.046733240000000002,0.023999829,-0.0027407978,-0.038836761999999997,-0.0076481607,-0.017481509999999999,0.0051029124000000004,-0.026818225000000001,-0.021094522000000001,0.014278222,0.012682785,-0.019654283000000002,-0.039457555999999998,-0.0060278926999999998,0.015755707000000001,-0.011379122,-0.0027609735000000001,0.0029503150999999998,-0.00075891849999999998,-0.027339690999999999,0.044796370000000002,-0.038687773000000002,-0.029996682,0.019753608999999998,-0.041518588000000002,-0.026594739999999999,0.0014673977000000001,0.0040630850000000001,0.042909160000000002,0.014116816000000001,-0.024335057,-0.036676407000000001,-0.04303332,-0.023279709999999999,0.020225410999999999,-0.017270440000000001,0.0029518672,-0.00062079227000000001,0.0030930974000000001,0.0095353690000000001,0.016984875999999999,-0.0038178724000000001,0.013421529,-0.0020765502,-0.022596838000000001,0.0026771666000000001,-0.0011507936,0.019381134000000001,0.00080082199999999997,0.028606106999999999,-0.022236780000000001,-0.015035588000000001,-0.014464459000000001,-0.022211946999999999,-0.016997293,0.0095353690000000001,0.034888524999999997,-0.010832825000000001,0.016302003999999998,-0.010180992999999999,0.0025607680000000002,0.036800563000000001,0.016935213000000001,-0.025924283999999999,0.0087904184999999992,0.021206263,0.030890622999999999,-0.020635133999999999,-0.044796370000000002,0.019145234000000001,0.034516048000000001,0.00067317159999999996,-0.022795490000000002,0.033895257999999998,0.035385158,-0.025055175999999998,-0.015470143,-0.0094608739999999993,-0.032157036999999999,-0.012713825,-0.0013432392,0.017680162999999999,0.010640379,0.036552247000000003,-0.024769612,0.017655331999999999,0.014563786,-0.0080765079999999996,0.00035617955,0.011434994,-0.010776954,-0.027339690999999999,0.0063134569999999997,0.023205215000000001,0.025998779,-0.020461312999999998,-0.043207143000000003,0.0037713130000000001,0.0099078445000000005,-0.02181464,0.0059937489999999996,-0.034590546,0.0054971150000000003,-0.009131854,-0.017357351,0.0088835370000000004,0.010615546999999999,0.017258024,0.040574983000000002,0.0040289415,-0.026445750000000001,0.033249630000000002,0.011453616999999999,-0.0092063490000000008,-0.019617036000000001,-0.026470581,0.014389964999999999,0.051004290000000001,-0.0090759824999999995,-0.0091442699999999995,0.040351495000000001,0.043604450000000003,-0.015333569,-0.014166478999999999,-0.0078033586,-0.0041344759999999998,-0.0018002974999999999,-0.049787539999999998,0.017034540000000001,0.036030779999999998,0.025452481999999998,0.0065555659999999997,0.032082542999999998,0.032877160000000002,0.018164381,-0.021578738,-0.013396697000000001,-0.024570957000000001,-0.002633711,-0.045640646999999999,0.0066114375000000001,0.025725630999999999,0.02512967,0.022373351999999999,-0.0075860815000000003,0.014601034000000001,-0.017183529999999999,0.035484485000000003,0.034118740000000002,-0.052841840000000001,-0.012136488000000001,0.034863690000000003,0.0075426260000000002,0.035310662999999999,-0.023292126,0.025824957999999999,-0.001839097,-0.0016311316000000001,-0.002408674,-0.0099885470000000004,0.053139816999999999,0.01476244,0.0076854080000000003,-0.014253389999999999,0.0046745655000000001,0.032157036999999999,0.039830033000000001,-0.001766154,-0.0096471109999999999,-0.0051339519999999998,0.011838507999999999,0.038315295999999999,0.026818225000000001,-0.013806419,0.044945359999999997,-0.00072787893999999998,-0.013545687000000001,-0.04998619,0.044995019999999997,0.0072322297000000004,-0.020275075,0.013570518,-0.029475215999999999,-0.042064882999999997,-0.002006711,-0.013843668,0.013297369999999999,-0.014414796000000001,0.0038116643999999999,-0.012297895,0.020473728,-0.016488243,0.009665735,-0.0072632692999999998,0.014340301,0.022236780000000001,-0.015730876000000001,-0.019915016000000001,-0.015010756,-0.0048328675,0.035136840000000003,0.0051991353000000002,-0.015842617999999999,-0.00064484790000000002,0.029698702,-0.017978142999999999,-0.0021029337999999998,0.029152404999999999,-0.00044076249999999999,0.019778442,-0.036055613,-0.0016776911000000001,0.014774855,-0.017816736999999999,0.0078778540000000001,-0.031635574999999999,0.018363034,-0.015805370999999999,0.021007609999999999,-0.042735339999999997,-0.0079399329999999997,0.010125122,0.016537904999999999,0.010298943,-0.014191311,-0.030145670999999999,-0.0027345898999999998,-8.9287390000000001e-5,0.016860718,-0.031635574999999999,-0.020275075,-0.030567810000000001,0.0095912399999999991,-0.0048328675,-0.0094546660000000005,0.024558541999999999,-0.0058230315,-0.072309880000000007,-0.010261696000000001,0.070422670000000007,-0.0094050030000000003,0.0068907940000000004,0.0073253483999999999,0.010832825000000001,0.0036099068999999998,0.011037686,-0.0107397055,-0.0041965559999999997,-0.022410599999999999,-0.0051215360000000003,0.00020932338999999999,-0.0036005949999999998,-0.0088524980000000003,0.019617036000000001,0.0030791296000000001,0.018810006000000001,-0.018363034,0.0076109130000000004,-0.069230749999999994,-0.031238265000000001,0.00063864,-0.00027858053,-0.016798638000000001,-0.009131854,0.0053419173000000004,0.047329202000000001,0.014961093999999999,0.0059751253999999997,0.014799687000000001,-0.015470143,0.019542540000000001,0.022596838000000001,-0.0091380620000000006,-0.0073998435000000003,0.0077723189999999998,0.014228558000000001,-0.014067152499999999,-0.013322202,0.07732588,-0.016264757000000001,-0.0079585565,-0.00093506834999999996,-0.015259073999999999,-0.0026942384,0.0095788239999999997,-0.0090076949999999996,-0.0022177803,-0.021727730000000001,-0.015507391000000001,-0.069777049999999993,0.020461312999999998,0.040053516999999997,0.010932150999999999,-0.014563786,0.0033833177000000001,0.012030954,-0.013297369999999999,-0.013446359999999999,0.0039575505000000004,0.0053295013,0.0087035075000000007,-0.0063258730000000001,-0.012304102000000001,-0.021827055000000001,-0.0041841400000000003,-0.0083744869999999999,0.024359887,0.0030496417999999999,0.024595789999999999,-0.0055933379999999998,-0.016066104000000001,0.027488680000000001,0.0092746359999999993,0.021851888,-0.04934057,-0.01682347,0.0048483876000000002,0.0049290903999999998,0.01075833,-0.016922796,-0.021640818999999999,-0.0036130110000000002,-0.012105449000000001,0.022435432000000002,-0.0030030825,-0.044721875000000001,-0.0083124080000000003,-0.010398271000000001,0.0071949824000000001,0.010174785,0.021963630000000001,0.032157036999999999,-0.0024288497000000001,0.0068038832000000002,0.010677626000000001,-0.031337592999999997,0.065505999999999995,-0.0039730705000000002,0.021678065999999999,-0.0045690310000000003,-0.0011026822000000001,0.0068349229999999997,-0.014961093999999999,0.0099637149999999997,0.016364085,-6.7511159999999996e-5,0.0021945005,0.010236864,-0.0102244485,-0.015159746999999999,0.011795053,-0.014402379999999999,0.016190263,-0.018896916999999999,-0.0025157606999999999,-0.021876718999999999,-0.013011806000000001,0.0019104880999999999,-0.022261610000000001,0.034814030000000003,0.057162549999999999,-0.019554955999999998,-0.014961093999999999,0.034342225999999997,-0.018884499999999999,0.0074991705000000001,0.01822646,0.051451261999999998,0.028034977999999999,-0.0048080359999999999,0.012273063000000001,0.00272683,-0.0092870520000000005,-0.005379165,0.015581885,-0.0060372044999999997,-0.0060930760000000002,-0.015917113,-0.0030279143000000001,-0.00052612139999999997,-0.01933147,-0.044001753999999997,0.0084862300000000009,-0.024037076000000001,-0.015470143,-0.01189438,0.043256804000000003,0.033249630000000002,0.018300956,-0.023416283999999999,-0.0083558629999999998,0.023167968000000001,-0.0064376154999999996,-0.010801786000000001,0.013905747,0.024012245000000002,-0.033249630000000002,-0.034367059999999998,0.022075371999999999,0.027836324999999999,0.00032630393999999999,-0.017419430999999999,0.00094050022999999999,0.017704995000000001,0.021082105,0.013781588000000001,0.012751073,0.0046838773,0.046609079999999997,0.014923845,0.012837984,-0.023230046000000001,0.02925173,0.0094670819999999999,0.012446885,0.023267293000000001,-0.026420920000000001,0.028407452999999999,0.020548224,-0.0088214580000000008,0.014154063999999999,-0.056715580000000002,0.031461753000000002,-0.037669674,0.022100205000000001,0.045590980000000003,-0.013880915000000001,0.019194896999999999,-0.045491660000000003,0.0051401596999999999,-0.020622720000000001,0.023652184999999999,-0.0029425554,-0.00054164125999999998,-0.018934164,-0.0076543684000000001,-0.0060372044999999997,-0.019170064000000001,-0.014365133,-0.018437530000000001,0.00094282825000000002,-0.035981119999999998,0.0148990145,0.0067418039999999997,0.024868937000000001,0.0067976750000000004,-0.027513513,0.0031520726999999999,0.018425113999999999,-0.0084179430000000006,-0.055076689999999998,0.0037092335999999999,-0.0029518672,-0.0102244485,-0.024198482,0.028730266000000001,-0.015408063,0.037247534999999998,9.1178860000000006e-5,-0.013545687000000001,-0.026967215999999999,0.010149953,0.02121868,-0.016612400999999999,-0.0014456699,0.0034205653000000001,0.0046528378000000002,-0.0098830129999999995,0.023366620000000001,-0.0074184669999999998,0.0091628934999999998,0.030170504000000001,0.00042912264999999999,0.025949117000000001,-0.021119352000000001,-0.039904527000000002,0.0085048539999999992,-0.039681040000000001,0.017407015000000001,0.0012423604,0.031859060000000002,0.016165430000000001,-0.017704995000000001,0.022149868,-0.017990559999999999,0.012813152,-0.014427212,0.0025048967999999998,0.0016311316000000001,-0.011875755999999999,0.020386817000000002,0.019828104999999999,-0.033721436,-0.013098716999999999,0.0054971150000000003,0.0067914673000000004,-0.0031365528999999998,0.023391452,-0.033175137,-0.029996682,0.030393988,-0.0050842889999999996,0.005286046,-0.027885988,-0.034590546,0.0061458433000000003,-3.8526704999999997e-6,-0.017034540000000001,0.039705873000000003,0.029996682,0.012018538,-0.0081882499999999993,-0.030642306000000001,0.00064019200000000004,0.0036968180000000002,-0.0063755362999999999,-0.011348083,0.022733413000000001,-0.014427212,0.017779489999999998,-0.010994230000000001,-0.0082813690000000002,0.0074681310000000002,0.015656380000000001,0.038712605999999997,-0.028804759999999999,0.026147770000000001,-0.0040289415,0.0018437530000000001,-0.025874620000000001,-0.013682260999999999,-0.0046745655000000001,0.040152844,0.017071787000000001,0.0044852240000000003,0.0011779532999999999,-0.0037961446000000002,0.0028059809999999999,-0.00084738140000000005,-0.020858620000000001,0.011844716,0.022472679999999998,-0.0052208630000000001,-0.0095850320000000003,-0.0063041453000000003,-0.012086825000000001,0.024099154000000001,0.019977095,-0.0052084469999999997,0.024918599999999999,0.025626303999999999,-0.00034027173999999998,-0.025328323,0.011962667,0.010994230000000001,-0.017258024,0.015308736999999999,-0.037421357000000002,0.0037216494999999998,-0.014377548,-0.013520855,0.022720996,-0.018797589999999999,0.0083869029999999994,-0.032231532,0.0050656646000000003,-0.021082105,0.016450995999999999,0.00023202109999999999,-0.0082006660000000006,-0.020064005999999999,-0.020212995000000001,0.0058602790000000004,-0.017431846000000001,-0.0059844369999999996,-0.020647550000000001,-0.030716800999999998,0.016066104000000001,-0.015768124000000001,0.052593517999999999,0.0048576994000000002,-0.0070646160000000001,-0.010752121999999999,0.022460263000000001,-0.025179334000000001,0.051401599999999999,-0.02432264,-0.0041375802999999997,0.017680162999999999,-0.0025731840000000001,-0.036403257000000001,0.00044541843999999997,-0.0022255399999999998,0.00075659057000000002,0.041170944000000001,-0.019157647999999999,-0.00062932812999999998,0.024111569999999999,0.019095569999999999,-0.016115766,0.0096719430000000006,0.017407015000000001,-0.018474778000000001,0.00049663379999999996,-0.021615986,-0.0077164475999999997,-0.0051215360000000003,-0.023130719000000001,0.0086290120000000001,-0.0028990997999999999,0.015507391000000001,-0.011782637,0.0044821202999999997,0.026247097,-0.017469093000000002,0.028779929999999999,0.032554346999999997,0.013918162,-0.018611351000000002,-0.010013378999999999,0.0016063,0.04303332,-0.036800563000000001,0.0086352200000000007,-0.0033181347000000002,-0.012962141999999999,-0.0087966260000000001,0.00067161960000000002,-0.011490864999999999,-0.023006559999999999,0.0034143572999999999,-0.024782025999999999,0.025315909000000001,-0.0031241369999999999,-0.023304539999999999,0.0038923675,0.022845154999999999,0.030220167999999999,0.019617036000000001,-0.036825396000000003,-0.0062420660000000001,-0.0088835370000000004,-0.0070459920000000001,0.018971412,0.0065245264999999998,-0.00065105589999999997,0.017320103999999999,0.0023559065999999998,-0.031089275999999999,0.010901111999999999,-0.025216580999999998,0.021082105,-0.030195335,-0.026445750000000001,-0.0082565369999999996,-0.05025934,0.01933147,-0.015619133,0.0064127840000000004,-0.0092622199999999998,-0.014948677,-0.028829591000000002,0.0039482387000000004,-0.024409551000000002,-0.012695201999999999,0.038240799999999998,0.0064251999999999998]; - + $vector = $aiclient->embed_query($data->userprompt); $search = \core_search\manager::instance(true, true); $settings = [ 'similarity' => true, @@ -102,10 +100,21 @@ ]; $limit = 0; $docs = $search->search((object)$settings); - exit(); + var_dump($docs); + // Perform "R" from RAG, finding documents from within the context that are similar to the user's prompt. // Add the retrieved documents to the context for this chat by generating some system messages with the content // returned + if (!empty($docs)) { + $context = []; + foreach ($docs as $doc) { + $context[] = $doc->content; + } + $_SESSION[$aicontextkey]['messages'][] = (object)[ + "role" => "system", + "content" => "Use the following context to answer questions:" . implode("\n",$context) + ]; + } // Add the user's new prompt to the messages. $progress->update(2, $totalsteps,'Attaching user prompt'); @@ -114,7 +123,9 @@ "content" => $data->userprompt ]; // Pass the whole context over the AI to summarise. + var_dump($_SESSION[$aicontextkey]['messages']); $progress->update(3, $totalsteps, 'Waiting for response'); + $airesults = $aiclient->chat($_SESSION[$aicontextkey]['messages']); $_SESSION[$aicontextkey]['messages'] = array_merge($_SESSION[$aicontextkey]['messages'],$airesults); $progress->update(4, $totalsteps, 'Got Response'); diff --git a/search/engine/solr/classes/engine.php b/search/engine/solr/classes/engine.php index 8da39b32021e..48080323cf96 100644 --- a/search/engine/solr/classes/engine.php +++ b/search/engine/solr/classes/engine.php @@ -837,7 +837,8 @@ protected function add_solr_document($doc) { debugging('Solr client error adding document with id ' . $doc['id'] . ': ' . $e->getMessage(), DEBUG_DEVELOPER); } catch (\SolrServerException $e) { // We only use the first line of the message, as it's a fully java stacktrace behind it. - $msg = strtok($e->getMessage(), "\n"); + // $msg = strtok($e->getMessage(), "\n"); + $msg = $e->getMessage(); debugging('Solr server error adding document with id ' . $doc['id'] . ': ' . $msg, DEBUG_DEVELOPER); } diff --git a/search/engine/solrrag/classes/ai/aiclient.php b/search/engine/solrrag/classes/ai/aiclient.php index 4b9c9b8bad8e..a9445e3614a5 100644 --- a/search/engine/solrrag/classes/ai/aiclient.php +++ b/search/engine/solrrag/classes/ai/aiclient.php @@ -84,7 +84,7 @@ public function embed_query($content): array { $rawresult = $this->post($this->get_embeddings_url(), $params); // var_dump($rawresult); $result = json_decode($rawresult, true); - var_dump($result); + // var_dump($result); $usage = $result['usage']; $this->provider->increment_prompt_usage($usage['prompt_tokens']); $this->provider->increment_total_tokens($usage['total_tokens']); diff --git a/search/engine/solrrag/classes/engine.php b/search/engine/solrrag/classes/engine.php index 57794cbdf381..e7ece7e996c4 100644 --- a/search/engine/solrrag/classes/engine.php +++ b/search/engine/solrrag/classes/engine.php @@ -339,7 +339,7 @@ public function execute_query($filters, $accessinfo, $limit = 0) { ) { // Do a vector similarity search. debugging("Running similarity search", DEBUG_DEVELOPER); - $this->execute_solr_knn_query($filters, $accessinfo, $limit); + return $this->execute_solr_knn_query($filters, $accessinfo, $limit); } else { debugging("Running regular search", DEBUG_DEVELOPER); print_r($filters); @@ -353,6 +353,7 @@ public function execute_solr_knn_query($filters, $accessinfo, $limit) { $topK = 3; // Nearest neighbours to retrieve. $field = "solr_vector_" . count($vector); $requestbody = "{!knn f={$field} topK={$topK}}[" . implode(",", $vector) . "]"; + $filters->mainquery = $requestbody; if (empty($limit)) { $limit = \core_search\manager::MAX_RESULTS; @@ -360,20 +361,18 @@ public function execute_solr_knn_query($filters, $accessinfo, $limit) { $curl = $this->get_curl_object(); $requesturl = $this->get_connection_url('/select'); - $requesturl->param('fl', 'id,areaid,score'); + $requesturl->param('fl', 'id,areaid,score,content'); $requesturl->param('wt', 'xml'); - - $body = [ - 'query' => $requestbody + // $requesturl->param('query', $requestbody) + $params = [ + "query" => $requestbody, ]; - echo $requesturl->out(false); - $result = $curl->post($requesturl->out(false), - json_encode($body) - ); + $curl->setHeader('Content-type: application/json'); + $result = $curl->post($requesturl->out(false), json_encode($params)); + // Probably have to duplicate error handling code from the add_stored_file() function. $code = $curl->get_errno(); $info = $curl->get_info(); - // Now error handling. It is just informational, since we aren't tracking per file/doc results. if ($code != 0) { // This means an internal cURL error occurred error is in result. @@ -410,10 +409,22 @@ public function execute_solr_knn_query($filters, $accessinfo, $limit) { // echo htmlentities($result); // debugging("Got SOLR update/extract response"); $xml = simplexml_load_string($result); - print_r($xml->result); - print_r($xml->result['numFound']); - print_r($xml->result['maxScore']); - + // echo "
";
+                    // var_dump($xml->result);
+                    // echo "
"; + $results = $xml->result->doc; + $docs = []; + foreach($results as $doc) { + $docs[] = (object)[ + 'id' => (string)$doc->str[0], + 'areaid' => (string)$doc->str[1], + 'content' => (string)$doc->str[2], + 'score' => (string)$doc->float, + ]; + } + return $docs; + // [0][1][2] as defined in the fl attribute above + } } else { // We received an unprocessable response. diff --git a/search/engine/solrrag/classes/schema.php b/search/engine/solrrag/classes/schema.php index 54f00cb74fa8..6892d49dd29f 100644 --- a/search/engine/solrrag/classes/schema.php +++ b/search/engine/solrrag/classes/schema.php @@ -128,6 +128,7 @@ protected function validate_add_field_result($result) { // It comes as error when fetching fields data. if (!empty($results->error)) { + var_dump($results); throw new \moodle_exception('errorcreatingschema', 'search_solrrag', '', $results->error); }