mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-22 07:01:07 +03:00
Bugfix/Supabase Upserting (#2210)
* fix supabase upserting error * fix supabase upserting error * update pnpm to 9.0.3
This commit is contained in:
@@ -21,7 +21,7 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: pnpm/action-setup@v3
|
||||
with:
|
||||
version: 9.0.2
|
||||
version: 9.0.3
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@
|
||||
"turbo": "1.10.16",
|
||||
"typescript": "^4.8.4"
|
||||
},
|
||||
"packageManager": "pnpm@9.0.2",
|
||||
"packageManager": "pnpm@9.0.3",
|
||||
"pnpm": {
|
||||
"onlyBuiltDependencies": [
|
||||
"faiss-node",
|
||||
|
||||
@@ -130,7 +130,7 @@ class Supabase_VectorStores implements INode {
|
||||
|
||||
try {
|
||||
if (recordManager) {
|
||||
const vectorStore = await SupabaseVectorStore.fromExistingIndex(embeddings, {
|
||||
const vectorStore = await SupabaseUpsertVectorStore.fromExistingIndex(embeddings, {
|
||||
client,
|
||||
tableName: tableName,
|
||||
queryName: queryName
|
||||
@@ -148,7 +148,7 @@ class Supabase_VectorStores implements INode {
|
||||
})
|
||||
return res
|
||||
} else {
|
||||
await SupabaseVectorStore.fromDocuments(finalDocs, embeddings, {
|
||||
await SupabaseUpsertVectorStore.fromDocuments(finalDocs, embeddings, {
|
||||
client,
|
||||
tableName: tableName,
|
||||
queryName: queryName
|
||||
@@ -190,4 +190,33 @@ class Supabase_VectorStores implements INode {
|
||||
}
|
||||
}
|
||||
|
||||
class SupabaseUpsertVectorStore extends SupabaseVectorStore {
|
||||
async addVectors(vectors: number[][], documents: Document[]): Promise<string[]> {
|
||||
if (vectors.length === 0) {
|
||||
return []
|
||||
}
|
||||
const rows = vectors.map((embedding, idx) => ({
|
||||
content: documents[idx].pageContent,
|
||||
embedding,
|
||||
metadata: documents[idx].metadata
|
||||
}))
|
||||
|
||||
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 res = await this.client.from(this.tableName).upsert(chunk).select()
|
||||
if (res.error) {
|
||||
throw new Error(`Error inserting: ${res.error.message} ${res.status} ${res.statusText}`)
|
||||
}
|
||||
if (res.data) {
|
||||
returnedIds = returnedIds.concat(res.data.map((row) => row.id))
|
||||
}
|
||||
}
|
||||
return returnedIds
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { nodeClass: Supabase_VectorStores }
|
||||
|
||||
@@ -108,7 +108,7 @@ class SupabaseUpsert_VectorStores implements INode {
|
||||
finalDocs.push(new Document(flattenDocs[i]))
|
||||
}
|
||||
|
||||
const vectorStore = await SupabaseVectorStore.fromDocuments(finalDocs, embeddings, {
|
||||
const vectorStore = await SupabaseUpsertVectorStore.fromDocuments(finalDocs, embeddings, {
|
||||
client,
|
||||
tableName: tableName,
|
||||
queryName: queryName
|
||||
@@ -125,4 +125,33 @@ class SupabaseUpsert_VectorStores implements INode {
|
||||
}
|
||||
}
|
||||
|
||||
class SupabaseUpsertVectorStore extends SupabaseVectorStore {
|
||||
async addVectors(vectors: number[][], documents: Document[]): Promise<string[]> {
|
||||
if (vectors.length === 0) {
|
||||
return []
|
||||
}
|
||||
const rows = vectors.map((embedding, idx) => ({
|
||||
content: documents[idx].pageContent,
|
||||
embedding,
|
||||
metadata: documents[idx].metadata
|
||||
}))
|
||||
|
||||
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 res = await this.client.from(this.tableName).upsert(chunk).select()
|
||||
if (res.error) {
|
||||
throw new Error(`Error inserting: ${res.error.message} ${res.status} ${res.statusText}`)
|
||||
}
|
||||
if (res.data) {
|
||||
returnedIds = returnedIds.concat(res.data.map((row) => row.id))
|
||||
}
|
||||
}
|
||||
return returnedIds
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { nodeClass: SupabaseUpsert_VectorStores }
|
||||
|
||||
Reference in New Issue
Block a user