forked from lobehub/lobe-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 fix: fix embeddings multi-insert when there is issues with async ta…
…sk (lobehub#3530)
- Loading branch information
Showing
5 changed files
with
3,044 additions
and
2 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
src/database/server/migrations/0007_fix_embedding_table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
-- step 1: create a temporary table to store the rows we want to keep | ||
CREATE TEMP TABLE embeddings_temp AS | ||
SELECT DISTINCT ON (chunk_id) * | ||
FROM embeddings | ||
ORDER BY chunk_id, random(); | ||
|
||
-- step 2: delete all rows from the original table | ||
DELETE FROM embeddings; | ||
|
||
-- step 3: insert the rows we want to keep back into the original table | ||
INSERT INTO embeddings | ||
SELECT * FROM embeddings_temp; | ||
|
||
-- step 4: drop the temporary table | ||
DROP TABLE embeddings_temp; | ||
|
||
-- step 5: now it's safe to add the unique constraint | ||
ALTER TABLE "embeddings" ADD CONSTRAINT "embeddings_chunk_id_unique" UNIQUE("chunk_id"); |
Oops, something went wrong.