[PR #19] [MERGED] refactor: convert insert loop to 1 insert stmt #3174

Closed
opened 2026-02-22 18:33:11 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Mintplex-Labs/anything-llm/pull/19
Author: @jwaltz
Created: 6/10/2023
Status: Merged
Merged: 6/13/2023
Merged by: @timothycarambat

Base: masterHead: sqlite-bulk-insert


📝 Commits (2)

  • 420b9bc fix: convert insert loop to 1 insert stmt
  • 31ce4fa chore: lint

📊 Changes

1 file changed (+14 additions, -5 deletions)

View changed files

📝 server/models/vectors.js (+14 -5)

📄 Description

I was getting errors when inserting a large .docx ("wordCount": 225518, "token_count_estimate": 47635) file's vectorIds into the document_vectors table:

Error: SQLITE_BUSY: database is locked

I took a look at the bulkInsert() method in server/models/vectors.js and noticed it was executing INSERT statements in a loop. Sqlite supports batch inserts so I converted the INSERT statement to a single insert with multiple parameters to account for all of the vectorIds.

My LSP formatter/linter might have changed a bit of the formatting of the method signatures but I hope the PR is still valuable/valid. Let me know if I can fix anything.

Thanks!


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Mintplex-Labs/anything-llm/pull/19 **Author:** [@jwaltz](https://github.com/jwaltz) **Created:** 6/10/2023 **Status:** ✅ Merged **Merged:** 6/13/2023 **Merged by:** [@timothycarambat](https://github.com/timothycarambat) **Base:** `master` ← **Head:** `sqlite-bulk-insert` --- ### 📝 Commits (2) - [`420b9bc`](https://github.com/Mintplex-Labs/anything-llm/commit/420b9bc332ae19c45e0e00c5fd4e50e3c384cc10) fix: convert insert loop to 1 insert stmt - [`31ce4fa`](https://github.com/Mintplex-Labs/anything-llm/commit/31ce4faf916b21dfe74c7a5c0070efb1a07b71e5) chore: lint ### 📊 Changes **1 file changed** (+14 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `server/models/vectors.js` (+14 -5) </details> ### 📄 Description I was getting errors when inserting a large .docx (`"wordCount": 225518, "token_count_estimate": 47635`) file's vectorIds into the document_vectors table: `Error: SQLITE_BUSY: database is locked` I took a look at the `bulkInsert()` method in `server/models/vectors.js` and noticed it was executing `INSERT` statements in a loop. Sqlite supports batch inserts so I converted the `INSERT` statement to a single insert with multiple parameters to account for all of the vectorIds. My LSP formatter/linter might have changed a bit of the formatting of the method signatures but I hope the PR is still valuable/valid. Let me know if I can fix anything. Thanks! --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-22 18:33:11 -05:00
yindo closed this issue 2026-02-22 18:33:12 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mintplex-Labs/anything-llm#3174