diff --git a/src/Engines/OpenAiEngine.php b/src/Engines/OpenAiEngine.php index 4bf57e7..fb2728a 100644 --- a/src/Engines/OpenAiEngine.php +++ b/src/Engines/OpenAiEngine.php @@ -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')) @@ -68,7 +78,7 @@ private function saveObjects($objects) 'foreign_id' => $object['objectID'], ], [ 'content' => $object['content'], - 'embedding' => '['.implode(',', $embed).']', + 'embedding' => '['.implode(',', $embed).']' ]); } }