这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions server/models/vectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,26 @@ const DocumentVectors = {
},
bulkInsert: async function (vectorRecords = []) {
if (vectorRecords.length === 0) return;

const db = await this.db();

// Build a single query string with multiple placeholders for the INSERT operation
const placeholders = vectorRecords.map(() => "(?, ?)").join(", ");

const stmt = await db.prepare(
`INSERT INTO ${this.tablename} (docId, vectorId) VALUES (?, ?)`
`INSERT INTO ${this.tablename} (docId, vectorId) VALUES ${placeholders}`
);
for (const record of vectorRecords) {
const { docId, vectorId } = record;
stmt.run([docId, vectorId]);
}

// Flatten the vectorRecords array to match the order of placeholders
const values = vectorRecords.reduce(
(arr, record) => arr.concat([record.docId, record.vectorId]),
[]
);

stmt.run(values);
stmt.finalize();
db.close();

return { documentsInserted: vectorRecords.length };
},
deleteForWorkspace: async function (workspaceId) {
Expand Down