Skip to content

feat: sync wrapper for ONNX embeddings function - #46

Merged
sjvans merged 24 commits into
AISQLiteServicefrom
sqlite-embeddings
Aug 25, 2026
Merged

feat: sync wrapper for ONNX embeddings function#46
sjvans merged 24 commits into
AISQLiteServicefrom
sqlite-embeddings

Conversation

@vkozyura

@vkozyura vkozyura commented Jul 30, 2026

Copy link
Copy Markdown

Local VECTOR_EMBEDDING through ai-sqlite

Based on #53.

This PR adds local semantic embeddings backed by ONNX Runtime and integrates them through AISQLiteService instead of modifying or being imported by @cap-js/sqlite.

  • Initializes the model when an ai-sqlite service starts.
  • Registers VECTOR_EMBEDDING for each SQLite connection.
  • Supports the three-argument HANA form and the optional fourth remote_source argument.
  • Preserves SQL NULL semantics.
  • Keeps the synchronous inference required by SQLite user-defined functions.
  • Adds an integration test proving that the ai-sqlite kind replaces SQLite's hash embedding implementation.

The ONNX dependency is optional for regular @cap-js/ai consumers and is required only when ai-sqlite is selected.

@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 Outdated
Comment thread lib/vector_embedding/embedding.js Outdated
Comment thread lib/vector_embedding/InferenceSession.js Outdated
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 Outdated
"srv"
],
"dependencies": {
"onnxruntime-node": "^1.20.1"

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.

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

Comment thread package.json Outdated
Comment on lines +11 to +18
"exports": {
".": "./cds-plugin.js",
"./cds-plugin": "./cds-plugin.js",
"./cds-plugin.js": "./cds-plugin.js",
"./vector_embedding": "./lib/vector_embedding/index.js",
"./srv/*": "./srv/*",
"./lib/*": "./lib/*"
},

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.

why?

Comment thread package.json Outdated
"format:check": "npx -y prettier@3 --check . && format-cds --check"
},
"files": [
"cds-plugin.js",

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.

Suggested change
"cds-plugin.js",

already defined as main

vkozyura and others added 8 commits August 25, 2026 22:17
The exports field was blocking CDS from loading:
- cds-plugin.js (plugin registration)
- srv/* (AICoreService, MockAICoreService)
- lib/* (internal modules)

Without these exports, Node.js blocks access to these paths,
causing "Navigation property SAP_Recommendations is not defined"
errors because the CSN enhancement never registers.
Without this, npm pack excludes cds-plugin.js from the tarball,
breaking plugin auto-registration when installed as a dependency.
This caused MTX integration tests to fail with 'ResourceGroup undefined'
because the plugin never loaded.
@sjvans
sjvans force-pushed the sqlite-embeddings branch from b0d7f8b to e6cf3dd Compare August 25, 2026 20:35
@sjvans
sjvans changed the base branch from main to AISQLiteService August 25, 2026 20:35
@sjvans
sjvans force-pushed the sqlite-embeddings branch from e6cf3dd to 447f21c Compare August 25, 2026 20:37
@sjvans
sjvans merged commit bc0d084 into AISQLiteService Aug 25, 2026
6 of 10 checks passed
@sjvans
sjvans deleted the sqlite-embeddings branch August 25, 2026 22:03
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