Skip to content

Commit

Permalink
Skip existing embeddings
Browse files Browse the repository at this point in the history
  • Loading branch information
Casmo committed Dec 1, 2023
1 parent b000d54 commit 0a97603
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Engines/OpenAiEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ private function saveObjects($objects)
{
foreach ($objects as $object) {

$exists = DB::connection(config('embed.database.connection'))
->table(config('embed.database.table'))
->where('foreign_id', $object['objectID'])
->where('content', $object['content'])
->exists();

if ($exists) {
continue;
}

$embed = $this->embed($object['content']);

DB::connection(config('embed.database.connection'))
Expand All @@ -68,7 +78,7 @@ private function saveObjects($objects)
'foreign_id' => $object['objectID'],
], [
'content' => $object['content'],
'embedding' => '['.implode(',', $embed).']',
'embedding' => '['.implode(',', $embed).']'
]);
}
}
Expand Down

0 comments on commit 0a97603

Please sign in to comment.