mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 17:01:00 +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: actions/checkout@v4
|
||||||
- uses: pnpm/action-setup@v3
|
- uses: pnpm/action-setup@v3
|
||||||
with:
|
with:
|
||||||
version: 9.0.2
|
version: 9.0.3
|
||||||
- name: Use Node.js ${{ matrix.node-version }}
|
- name: Use Node.js ${{ matrix.node-version }}
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
|
|||||||
+1
-1
@@ -52,7 +52,7 @@
|
|||||||
"turbo": "1.10.16",
|
"turbo": "1.10.16",
|
||||||
"typescript": "^4.8.4"
|
"typescript": "^4.8.4"
|
||||||
},
|
},
|
||||||
"packageManager": "pnpm@9.0.2",
|
"packageManager": "pnpm@9.0.3",
|
||||||
"pnpm": {
|
"pnpm": {
|
||||||
"onlyBuiltDependencies": [
|
"onlyBuiltDependencies": [
|
||||||
"faiss-node",
|
"faiss-node",
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ class Supabase_VectorStores implements INode {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (recordManager) {
|
if (recordManager) {
|
||||||
const vectorStore = await SupabaseVectorStore.fromExistingIndex(embeddings, {
|
const vectorStore = await SupabaseUpsertVectorStore.fromExistingIndex(embeddings, {
|
||||||
client,
|
client,
|
||||||
tableName: tableName,
|
tableName: tableName,
|
||||||
queryName: queryName
|
queryName: queryName
|
||||||
@@ -148,7 +148,7 @@ class Supabase_VectorStores implements INode {
|
|||||||
})
|
})
|
||||||
return res
|
return res
|
||||||
} else {
|
} else {
|
||||||
await SupabaseVectorStore.fromDocuments(finalDocs, embeddings, {
|
await SupabaseUpsertVectorStore.fromDocuments(finalDocs, embeddings, {
|
||||||
client,
|
client,
|
||||||
tableName: tableName,
|
tableName: tableName,
|
||||||
queryName: queryName
|
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 }
|
module.exports = { nodeClass: Supabase_VectorStores }
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ class SupabaseUpsert_VectorStores implements INode {
|
|||||||
finalDocs.push(new Document(flattenDocs[i]))
|
finalDocs.push(new Document(flattenDocs[i]))
|
||||||
}
|
}
|
||||||
|
|
||||||
const vectorStore = await SupabaseVectorStore.fromDocuments(finalDocs, embeddings, {
|
const vectorStore = await SupabaseUpsertVectorStore.fromDocuments(finalDocs, embeddings, {
|
||||||
client,
|
client,
|
||||||
tableName: tableName,
|
tableName: tableName,
|
||||||
queryName: queryName
|
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 }
|
module.exports = { nodeClass: SupabaseUpsert_VectorStores }
|
||||||
|
|||||||
Reference in New Issue
Block a user