Repository navigation
perf: bind the query vector in knowledge base vector search - #4042
Merged
themez merged 1 commit intoNov 12, 2026
Merged
Conversation
@mastra/libsql 0.13.2 (pinned by the overrides) inlines the query vector into the SQL text of LibSQLVector.query(), so libSQL parses the whole vector literal again for every row it scans. Knowledge base and session attachment searches run this in the main process, which blocks the app for seconds on a medium knowledge base and for over a minute on large ones (chatboxai#3989). Patch it to pass the vector as a bound vector32(?) parameter, the same change upstream made in mastra-ai/mastra#27895 (@mastra/libsql 1.27.0). Results are unchanged.
Contributor
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Knowledge base search can freeze the app (#3989). The cause is
LibSQLVector.query()in@mastra/libsql0.13.2, which Chatbox pins throughoverrides. It puts the query vector into the SQL text as a string literal,vector_distance_cos(embedding, '[0.1,0.2,...]'), so libSQL parses the whole vector again for every row it scans. The search runs in the main process and libSQL runs synchronously, so the window stops responding until the query finishes.This adds a pnpm patch for
@mastra/[email protected]that binds the vector as a parameter,vector_distance_cos(embedding, vector32(?)). It's the same change upstream made in mastra-ai/mastra#27895, released in@mastra/libsql1.27.0. Moving to 1.x would also mean a major@mastra/coreupgrade, so patching the pinned version seemed like the smaller step. Knowledge base search and session attachment search both use this method.Results don't change: same ids and same scores, with and without a metadata filter.
Additional Notes
Measured on Windows 11, Node 24.15,
@libsql/client0.15.15, callingquery({ topK: 20 })the waysearchKnowledgeBasedoes, 7 alternating rounds each:createIndexWhile the 4096-dim query ran, the event loop didn't get a turn at all (one 5,132 ms gap), which is the freeze users see.
pnpm install --frozen-lockfileaccepts the updated lockfile, and pnpm applies the patch to bothdist/index.jsanddist/index.cjs.The DiskANN index mentioned in the issue still isn't used by
query(); that would be a separate change.Fixes #3989
Screenshots
N/A
Contributor Agreement
By submitting this Pull Request, I confirm that I have read and agree to the following terms:
Please check the box below to confirm:
[x] I have read and agree with the above statement.