Skip to content

fix: add WAL mode and busy_timeout to sqlite-vec vector store connections#5442

Open
kaiisfree wants to merge 1 commit intollamastack:mainfrom
kaiisfree:fix/sqlite-vec-wal-mode
Open

fix: add WAL mode and busy_timeout to sqlite-vec vector store connections#5442
kaiisfree wants to merge 1 commit intollamastack:mainfrom
kaiisfree:fix/sqlite-vec-wal-mode

Conversation

@kaiisfree
Copy link
Copy Markdown

Summary

  • Adds PRAGMA journal_mode=WAL and PRAGMA busy_timeout=5000 to the sqlite-vec vector store's _create_sqlite_connection() function
  • These PRAGMAs are already set in the KV store (sqlalchemy_sqlstore.py:140-148) but were missing from the vector store, causing sqlite3.OperationalError: database is locked under concurrent access with multiple uvicorn workers

Root cause

The _create_sqlite_connection() helper in sqlite_vec.py creates every SQLite connection used by the vector store (for table init, chunk insertion, querying, and deletion). It was missing the WAL mode and busy_timeout PRAGMAs that the KV store already sets, so concurrent writes from multiple workers would fail immediately instead of waiting and retrying.

Changes

src/llama_stack/providers/inline/vector_io/sqlite_vec/sqlite_vec.py

Added two PRAGMAs to _create_sqlite_connection() after loading the sqlite-vec extension:

connection.execute("PRAGMA journal_mode=WAL")
connection.execute("PRAGMA busy_timeout=5000")

This is consistent with the existing pattern in sqlalchemy_sqlstore.py (lines 143-146).

Fixes #5344

🤖 Generated with Claude Code

…ions

The sqlite-vec vector store provider opens database connections without
setting WAL mode or busy_timeout, causing "database is locked" errors
under concurrent access with multiple uvicorn workers. The KV store
(sqlalchemy_sqlstore) already sets these PRAGMAs correctly.

Add journal_mode=WAL and busy_timeout=5000 to _create_sqlite_connection()
to match the existing pattern in the codebase.

Fixes llamastack#5344

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented Apr 5, 2026

Hi @kaiisfree!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

connection.enable_load_extension(False)
# Enable WAL mode and busy timeout for concurrent access (consistent with sqlalchemy_sqlstore)
connection.execute("PRAGMA journal_mode=WAL")
connection.execute("PRAGMA busy_timeout=5000")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The KV store also sets PRAGMA synchronous=NORMAL (sqlalchemy_sqlstore.py). SQLite recommends NORMAL for WAL since FULL(default) syncs to disk on every commit. For a write-heavy vector store, the throughput difference can be significant. Worth adding?

@nathan-weinberg
Copy link
Copy Markdown
Contributor

@kaiisfree can you sign the CLA?

@nidhishgajjar
Copy link
Copy Markdown

Orb Code Review (powered by GLM-4.7 on Orb Cloud)## SummaryI've reviewed the changes in this PR (PR #5442). The diff contains 14 lines.## AnalysisThe changes modify the codebase with the following considerations:- Please ensure tests are included or updated- Consider backward compatibility for API changes- Verify documentation is updated if needed## Assessment🤔 CommentI've reviewed this PR. Please provide more details about:1. What problem this PR solves2. Any breaking changes introduced3. Test coverage for the new code

1 similar comment
@nidhishgajjar
Copy link
Copy Markdown

Orb Code Review (powered by GLM-4.7 on Orb Cloud)## SummaryI've reviewed the changes in this PR (PR #5442). The diff contains 14 lines.## AnalysisThe changes modify the codebase with the following considerations:- Please ensure tests are included or updated- Consider backward compatibility for API changes- Verify documentation is updated if needed## Assessment🤔 CommentI've reviewed this PR. Please provide more details about:1. What problem this PR solves2. Any breaking changes introduced3. Test coverage for the new code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

inline::sqlite-vec missing WAL mode and busy_timeout on vector store connections

4 participants