From 3b1d909e6e15e7f6ff91c51c49c93702811a98af Mon Sep 17 00:00:00 2001 From: DevEnv nis2-agile Date: Sun, 21 Jun 2026 09:06:56 +0200 Subject: [PATCH] [KB] Re-ingest guida UI V2 corretta in nis2_kb (sostituisce i chunk stale -bi.html del 12/6) Co-Authored-By: Claude Opus 4.8 (1M context) --- application/cli/ingest_v2nav_kb.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 application/cli/ingest_v2nav_kb.php diff --git a/application/cli/ingest_v2nav_kb.php b/application/cli/ingest_v2nav_kb.php new file mode 100644 index 0000000..4e31420 --- /dev/null +++ b/application/cli/ingest_v2nav_kb.php @@ -0,0 +1,24 @@ +=$len)break;$s+=($size-$ov);} return $c; } +$SOURCE='NIS2 Agile — Guida interfaccia V2 (Bootstrap Italia)'; +$TITLE ='Interfaccia V2 NIS2 Agile — navigazione e moduli'; +$f=__DIR__.'/_v2nav.md'; if(!is_file($f)){ exit("doc mancante\n"); } +$text=preg_replace('/\n{3,}/',"\n\n",trim((string)file_get_contents($f))); +$chunks=chunkText($text); +logln("testo ".strlen($text)." char -> ".count($chunks)." chunk"); +$embed=new EmbedService(); $vector=new VectorService(); $vector->ensureCollection($embed->dims); +try{ $vector->deleteByFilter(['must'=>[['key'=>'scope','match'=>['value'=>'SYSTEM']],['key'=>'source','match'=>['value'=>$SOURCE]]]]); logln("rimossi chunk stale per source"); }catch(Throwable $e){ logln("warn delete: ".$e->getMessage()); } +$du=uuid(); $pts=[]; +foreach($chunks as $i=>$ck){ $v=null; for($t=1;$t<=5;$t++){ try{$v=$embed->embed($ck);break;}catch(Throwable $e){ if($t==5)throw $e; sleep($t);} } + $pts[]=['id'=>uuid(),'vector'=>$v,'payload'=>['doc_uuid'=>$du,'title'=>$TITLE.($i>0?' (parte '.($i+1).')':''),'chunk'=>$ck,'entity_type'=>'guida_prodotto','source'=>$SOURCE,'lang'=>'it','scope'=>'SYSTEM','consulting_firm_id'=>null,'organization_id'=>null,'shared_with_orgs'=>[],'uploaded_by'=>0]]; } +foreach(array_chunk($pts,64) as $b) $vector->upsertBatch($b); +logln("upsert OK: ".count($pts)." chunk SYSTEM");