Bugfix/Upserting same id with supabase (#2521)

fix upserting same id with supabase
This commit is contained in:
Henry Heng 2024-05-30 00:18:51 +01:00 committed by GitHub
parent 912c8f3d5b
commit d734747ec0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 2 deletions

View File

@ -223,10 +223,17 @@ class SupabaseUpsertVectorStore extends SupabaseVectorStore {
metadata: documents[idx].metadata
}))
let idx = 0
const { count } = await this.client.from(this.tableName).select('*', { count: 'exact', head: true })
if (count) {
idx = count
}
let returnedIds: string[] = []
for (let i = 0; i < rows.length; i += this.upsertBatchSize) {
const chunk = rows.slice(i, i + this.upsertBatchSize).map((row, index) => {
return { id: index, ...row }
const chunk = rows.slice(i, i + this.upsertBatchSize).map((row) => {
idx = idx += 1
return { id: idx, ...row }
})
const res = await this.client.from(this.tableName).upsert(chunk).select()
@ -237,6 +244,7 @@ class SupabaseUpsertVectorStore extends SupabaseVectorStore {
returnedIds = returnedIds.concat(res.data.map((row) => row.id))
}
}
return returnedIds
}
}