Skip to content

Commit bae450a

Browse files
committed
rebuild the index when the embedding model changed
1 parent b446155 commit bae450a

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

cli.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ protected function showinfo()
139139
];
140140
$stats = array_merge(
141141
$stats,
142-
array_map('dformat', $this->helper->getRunData()),
142+
$this->helper->getRunData(),
143143
$this->helper->getStorage()->statistics()
144144
);
145145
$this->printTable($stats);
@@ -341,7 +341,7 @@ protected function runMaintenance()
341341
$this->notice('Spent time: {time}min', ['time' => round((time() - $start) / 60, 2)]);
342342

343343
$data = $this->helper->getRunData();
344-
$data['maintenance ran at'] = time();
344+
$data['maintenance ran at'] = dformat();
345345
$this->helper->setRunData($data);
346346
}
347347

@@ -354,13 +354,25 @@ protected function createEmbeddings($clear)
354354
{
355355
[$skipRE, $matchRE] = $this->getRegexps();
356356

357+
$data = $this->helper->getRunData();
358+
$lastEmbedModel = $data['embed used'] ?? '';
359+
360+
if(
361+
!$clear && $lastEmbedModel &&
362+
$lastEmbedModel != (string) $this->helper->getEmbeddingModel()
363+
){
364+
$this->warning('Embedding model has changed since last run. Forcing an index rebuild');
365+
$clear = true;
366+
}
367+
357368
$start = time();
358369
$this->helper->getEmbeddings()->createNewIndex($skipRE, $matchRE, $clear);
359370
$this->notice('Peak memory used: {memory}', ['memory' => filesize_h(memory_get_peak_usage(true))]);
360371
$this->notice('Spent time: {time}min', ['time' => round((time() - $start) / 60, 2)]);
361372

362-
$data = $this->helper->getRunData();
363-
$data['embed ran at'] = time();
373+
374+
$data['embed ran at'] = dformat();
375+
$data['embed used'] = (string) $this->helper->getEmbeddingModel();
364376
$this->helper->setRunData($data);
365377
}
366378

0 commit comments

Comments
 (0)