Skip to content

feat: sync wrapper for ONNX embeddings function - #46

Open
vkozyura wants to merge 19 commits into
mainfrom
sqlite-embeddings
Open

feat: sync wrapper for ONNX embeddings function#46
vkozyura wants to merge 19 commits into
mainfrom
sqlite-embeddings

Conversation

@vkozyura

@vkozyura vkozyura commented Jul 30, 2026

Copy link
Copy Markdown

🆕 Add Local VECTOR_EMBEDDING Support via ONNX Runtime

This PR introduces local semantic search capabilities by implementing a VECTOR_EMBEDDING function powered by the ONNX runtime and the Xenova/all-MiniLM-L6-v2 model, enabling embedding generation without external service dependencies.

What Changed

New Files:

  • lib/vector_embedding/index.js — Exports a synchronous vector_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 around onnxruntime-common's InferenceSession, 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 — Adds onnxruntime-node ^1.20.1 as a runtime dependency.
  • CHANGELOG.md — Documents the new VECTOR_EMBEDDING function under Version 1.2.0.
  • README.md — Adds documentation for the exported vector_embedding API, 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.

Note: Produces 384-dimensional vectors (vs. 768 in SAP HANA), optimized for local development scenarios. Model versions SAP_GXY.20250407 and SAP_GXY.20240715 are supported.

Have you...

  • Added relevant entry to the change log?

  • 🔄 Regenerate and Update Summary

PR Bot Information

Version: 1.29.18

  • Summary Prompt: Default Prompt
  • File Content Strategy: Full file content
  • Event Trigger: pull_request.edited
  • Output Template: Repository PR Template
  • LLM: anthropic--claude-4.6-sonnet
  • Correlation ID: 22c18060-90d0-11f1-9a98-bc3a3f408703

@vkozyura
vkozyura requested a review from a team as a code owner July 30, 2026 15:35
@vkozyura
vkozyura marked this pull request as draft July 30, 2026 15:35
hyperspace-pr-bot[bot]

This comment was marked as outdated.

@vkozyura
vkozyura marked this pull request as ready for review July 31, 2026 09:53

@hyperspace-pr-bot hyperspace-pr-bot Bot left a comment

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 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

Comment thread cds-plugin.js Outdated
Comment thread lib/vector_handling/index.js Outdated
Comment thread lib/vector_embedding/embedding.js
Comment thread lib/vector_embedding/embedding.js
Comment thread lib/vector_embedding/model-utils.js
Comment thread lib/vector_embedding/embedding.js
Comment thread lib/vector_embedding/InferenceSession.js
Comment thread cds-plugin.js Fixed
@vkozyura vkozyura changed the title Sync wrapper for Sqlite for using ONNX embeddings function feat: sync wrapper for ONNX embeddings function Aug 5, 2026
@cap-js cap-js deleted a comment from hyperspace-pr-bot Bot Aug 5, 2026
Comment thread package.json
"srv"
],
"dependencies": {
"onnxruntime-node": "^1.20.1"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

adds almost 300 MB to build even though not needed in production

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.

2 participants