Skip to content

Commit e2cfff7

Browse files
authored
🐛 fix: fix embeddings multi-insert when there is issues with async task (#3530)
1 parent 5568e3f commit e2cfff7

File tree

5 files changed

+3044
-2
lines changed

5 files changed

+3044
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- step 1: create a temporary table to store the rows we want to keep
2+
CREATE TEMP TABLE embeddings_temp AS
3+
SELECT DISTINCT ON (chunk_id) *
4+
FROM embeddings
5+
ORDER BY chunk_id, random();
6+
7+
-- step 2: delete all rows from the original table
8+
DELETE FROM embeddings;
9+
10+
-- step 3: insert the rows we want to keep back into the original table
11+
INSERT INTO embeddings
12+
SELECT * FROM embeddings_temp;
13+
14+
-- step 4: drop the temporary table
15+
DROP TABLE embeddings_temp;
16+
17+
-- step 5: now it's safe to add the unique constraint
18+
ALTER TABLE "embeddings" ADD CONSTRAINT "embeddings_chunk_id_unique" UNIQUE("chunk_id");

0 commit comments

Comments
 (0)