feat: sync wrapper for ONNX embeddings function - #46
Open
vkozyura wants to merge 19 commits into
Open
Conversation
vkozyura
marked this pull request as draft
July 30, 2026 15:35
vkozyura
marked this pull request as ready for review
July 31, 2026 09:53
Contributor
There was a problem hiding this comment.
The PR introduces a useful SQLite VECTOR_EMBEDDING shim for local development, but has several substantive correctness issues: a race condition in prototype patching, repeated model initialization per connection, missing null-guards before synchronous inference, a chunking off-by-one that silently drops tokens, and unsafe file download handling that can leave corrupt cached models. Please address the comments above (including those from the prior review round) before merging.
PR Bot Information
Version: 1.29.9
- Correlation ID:
adee7d50-8cc5-11f1-8581-44e300807992 - Event Trigger:
pull_request.ready_for_review - Experiment Variant:
control - File Content Strategy: Full file content
- LLM:
anthropic--claude-4.6-sonnet
sjvans
reviewed
Aug 6, 2026
| "srv" | ||
| ], | ||
| "dependencies": { | ||
| "onnxruntime-node": "^1.20.1" |
There was a problem hiding this comment.
adds almost 300 MB to build even though not needed in production
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.
🆕 Add Local
VECTOR_EMBEDDINGSupport via ONNX RuntimeThis PR introduces local semantic search capabilities by implementing a
VECTOR_EMBEDDINGfunction powered by the ONNX runtime and theXenova/all-MiniLM-L6-v2model, enabling embedding generation without external service dependencies.What Changed
New Files:
lib/vector_embedding/index.js— Exports a synchronousvector_embedding(text, text_type, model_and_version)function. Auto-initializes the ONNX model on import and returns a JSON-stringified 384-dimensional float array. Returns a zero-filled vector for null/empty input.lib/vector_embedding/embedding.js— Core embedding logic: WordPiece tokenization, overlapping chunked processing for long texts, mean pooling, and L2 normalization using the ONNX model.lib/vector_embedding/InferenceSession.js— A synchronous wrapper aroundonnxruntime-common'sInferenceSession, adapted to bypass async worker threads so it is compatible with SQLite's synchronous user-defined function API.lib/vector_embedding/model-utils.js— Utilities for file checks, on-demand model downloading from Hugging Face (~10MB, cached locally), vocabulary loading, pre-tokenization, and WordPiece tokenization.Modified Files:
package.json— Addsonnxruntime-node ^1.20.1as a runtime dependency.CHANGELOG.md— Documents the newVECTOR_EMBEDDINGfunction under Version 1.2.0.README.md— Adds documentation for the exportedvector_embeddingAPI, including function signature, parameters, return value, and error handling.New Tests:
tests/vector.test.js— Covers embedding dimensions (384), determinism, semantic similarity, edge cases (null/empty input), and multi-model support.Have you...
Added relevant entry to the change log?
🔄 Regenerate and Update Summary
PR Bot Information
Version:
1.29.18pull_request.editedanthropic--claude-4.6-sonnet22c18060-90d0-11f1-9a98-bc3a3f408703