Skip to content

feat: add AI-enabled SQLite service - #53

Merged
sjvans merged 39 commits into
mainfrom
AISQLiteService
Sep 1, 2026
Merged

feat: add AI-enabled SQLite service#53
sjvans merged 39 commits into
mainfrom
AISQLiteService

Conversation

@sjvans

@sjvans sjvans commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Extends CAP's standard sqlite service and its sqlite:memory preset for local development with:

  • VECTOR_EMBEDDING backed by a locally managed ONNX encoder model
  • sentence-transformers/all-MiniLM-L6-v2 as the current replaceable default
  • warned, on-demand provisioning into <cds.root>/.cds/models/<model>
  • explicit provisioning with npx @cap-js/ai install-model <model>
  • metadata-only prechecks with npx @cap-js/ai check-model <model>
  • local SPARQL_EXECUTE and sparql_table support backed by Oxigraph

The SQLite embedding runtime, local model management, CLI tooling, and local knowledge graph are intentionally experimental. They exist to improve local development and are expected to change incompatibly. Production vector workloads should use SAP HANA's vector engine.

The standard-kind redirect and synchronous embedding function require @sap/cds ^10.1 and @cap-js/sqlite ^3.1. The package-wide @sap/cds peer remains >=9 for the other capabilities.

SQLite kind integration

@cap-js/ai overrides only the base sqlite implementation. The standard sqlite:memory preset supplied by @sap/cds inherits that implementation, its default embedding model, and @cap-js/sqlite's single-connection pool configuration. This relies on the preset inheritance delivered by cap/cds#6854 and removes the package-local sqlite:memory workaround.

Quick configuration

{
  "cds": {
    "requires": {
      "db": {
        "kind": "sqlite"
      }
    }
  }
}

Installing @cap-js/ai redirects the base SQLite kind. With @sap/cds ^10.1, sqlite:memory inherits the same AI-enabled implementation. The default model is therefore provisioned and initialized when either SQLite service starts, even if the application never calls VECTOR_EMBEDDING. HANA services are unaffected.

sentence-transformers/all-MiniLM-L6-v2 was selected only because, at the time of selection, it was the most-downloaded reasonably small model matching the sentence-similarity task, ONNX format, and Apache-2.0 license filters used for the sample. It is not a recommendation and may change at any time while the feature is experimental. Set cds.requires.db.embedding.model explicitly when the model choice must remain stable.

embedding.directory is optional. Without it, a missing model is downloaded after a startup warning and cached below .cds/models. With it, the directory is treated as a pre-provisioned cache; relative paths resolve from cds.root, while absolute and home-relative paths can be shared across projects. Additional embedding properties remain allowed for extensions.

The README provides a short Bookshop walkthrough. Detailed provisioning, trust-boundary, compatibility, runtime, SAP HANA, recommendations, AI Core, and SPARQL documentation lives under .docs/.

Security and runtime boundaries

Provisioning is trust on first use. The generated lock pins the resolved revision, artifact sizes, and checksums for subsequent integrity checks, but it does not authenticate the publisher or make an untrusted model safe. Installation loads native tokenizer and ONNX code and runs a probe, so users should select trusted public repositories and preferably provision models in a controlled environment.

Embedding generation is synchronous because SQLite user-defined functions cannot await. Tokenization and inference block the Node.js event loop, and input is limited to the first model window. The Oxigraph store is process-local, in-memory, and not transactionally coupled to SQLite.

Included work

Consolidates #46, #49, #51/#55, #57, #58, #61, and #64. Larger architectural follow-ups are tracked in #62; ONNX Runtime version compatibility remains tracked in #54.

Validation

  • npm --ignore-scripts test — 127 tests passed
  • npm run lint
  • targeted Prettier check for all changed files
  • resolved CAP configuration verified for both sqlite and inherited sqlite:memory, including the one-connection pool

@sjvans
sjvans requested a review from a team as a code owner August 25, 2026 13:42
@sjvans
sjvans requested a review from BobdenOs August 25, 2026 13:42
@hyperspace-pr-bot

Copy link
Copy Markdown
Contributor

Summary

The following content is AI-generated and provides a summary of the pull request:


feat: Introduce AISQLiteService with ai-sqlite Kind

This PR adds the groundwork for an AI-enabled SQLite service by introducing a new AISQLiteService class and registering it as a new ai-sqlite CDS kind.

What's changed:

  • lib/sqlite/AISQLiteService.js (new file): Extends SQLiteService from @cap-js/sqlite with an AISQLiteService class. It overrides:

    • init() – entry point for future AI-specific service initialization
    • factory getter – wraps the connection factory's create method to allow augmenting database connections
    • CQN2AISQLite – extends the SQL generation class with a placeholder for future AI-specific SQL functions
  • package.json: Registers the new ai-sqlite kind in cds.env, pointing to the AISQLiteService implementation with an in-memory SQLite database as default credentials. This allows consumers to use kind: ai-sqlite in their CDS configuration.

ℹ️ In the future, kind: sqlite could be overridden directly, but that would require prioritized cds.env resolution.

Have you...

  • Added relevant entry to the change log?

  • 🔄 Regenerate and Update Summary
  • ✏️ Insert as PR Description (deletes this comment)
  • 🗑️ Delete comment
PR Bot Information

Version: 1.29.44

  • Correlation ID: dbae24b0-a08a-11f1-8798-3c02d2a4f852
  • Event Trigger: pull_request.opened
  • Output Template: Repository PR Template
  • File Content Strategy: Full file content
  • LLM: anthropic--claude-4.6-sonnet
  • Summary Prompt: Default Prompt

@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 thin AISQLiteService extension and a new ai-sqlite kind registration, but has two substantive issues: the factory getter mutates the shared parent factory object on every call without a guard, risking infinite recursion on repeated access; and @cap-js/sqlite is imported unconditionally without being declared as a peer or optional dependency, which will cause a module-not-found error for consumers who don't have it installed.

PR Bot Information

Version: 1.29.44

  • Correlation ID: dbae24b0-a08a-11f1-8798-3c02d2a4f852
  • Event Trigger: pull_request.opened
  • File Content Strategy: Full file content
  • LLM: anthropic--claude-4.6-sonnet

Comment thread lib/sqlite/AISQLiteService.js
BobdenOs
BobdenOs previously approved these changes Aug 25, 2026
* Sync wrapper for Sqlite for using ONNX embeddings function

* fix imple and add tests

* add semantic tests

* use LOG

* test 4 params

* small fixes

* fix: address PR bot comments - add division by zero guard and fix lint errors

* chore: run prettier formatting

* fix tests

* dix duplicated function registration

* more frixes

* export vector_embedding directly

* rem unused

* refactor

* refactor

* linter

* remove comment

* Update CHANGELOG.md

* Update README.md

* export embeddings

* fix: add missing exports paths for CDS plugin loading

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.

* fix: include cds-plugin.js in npm package files

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.

* feat: integrate embeddings with ai-sqlite

* fix: harden local embedding runtime

---------

Co-authored-by: Sebastian Van Syckel <sebastian.van.syckel@sap.com>
PDT42
PDT42 previously requested changes Aug 26, 2026
Comment thread lib/vector_embedding/embedding.js Outdated
Comment thread tests/vector.test.js Outdated
Comment thread lib/vector_embedding/InferenceSession.js Outdated
Comment thread lib/vector_embedding/InferenceSession.js Outdated
Comment thread lib/vector_embedding/InferenceSession.js Outdated
Comment thread lib/vector_embedding/model-utils.js Outdated
Comment thread lib/vector_embedding/model-utils.js Outdated
Comment thread CHANGELOG.md Outdated
Comment thread package.json
Comment thread lib/sqlite/AISQLiteService.js
sjvans and others added 3 commits August 27, 2026 14:31
* fix: truncate embeddings to one model window

* Update lib/vector_embedding/embedding.js

Co-authored-by: hyperspace-pr-bot[bot] <209611008+hyperspace-pr-bot[bot]@users.noreply.github.com>

---------

Co-authored-by: hyperspace-pr-bot[bot] <209611008+hyperspace-pr-bot[bot]@users.noreply.github.com>
* Add triple store support for SQLiteService to match HANA capabilities

* fix: harden SQLite knowledge graph loading

* Apply suggestion from @sjvans

---------

Co-authored-by: Sebastian Van Syckel <sebastian.van.syckel@sap.com>
Co-authored-by: sjvans <30337871+sjvans@users.noreply.github.com>
* feat: support configurable local embedding models

* feat: provision embedding models by name (#55)

* feat: add explicit embedding model provisioning

* feat: support lazy embedding model provisioning

* docs: explain embedding model provisioning

* fix: require explicit embedding model

* refactor: require provisioned embedding models

* feat: provision embedding models by name

* fix: make tokenizer an optional peer

---------

Co-authored-by: Sebastian Van Syckel <sebastian.van.syckel@sap.com>
Co-authored-by: sjvans <30337871+sjvans@users.noreply.github.com>
Comment thread .docs/ai-core.md
Comment thread .docs/hana-vector-embeddings.md Outdated
Comment thread .docs/model-selection.md Outdated
Comment thread lib/vector_embedding/embedding.js
Comment thread lib/vector_embedding/model-discovery.js
Comment thread lib/vector_embedding/model-utils.js
Comment thread lib/vector_embedding/model-utils.js
Comment thread lib/vector_embedding/huggingface-hub.js Outdated
Comment thread tests/huggingface-hub.test.js
Comment thread embeddings.md Outdated
Comment thread lib/sqlite/AISQLiteService.js
@PDT42
PDT42 dismissed their stale review August 31, 2026 13:03

stale

PDT42
PDT42 previously approved these changes Aug 31, 2026

@PDT42 PDT42 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.

I would suggest adding: #63, but IMO we should merge this PR regardless 🚀

* docs: clarify goal

* fix: adopt less restrictive modules filtering

* fix: make model discovery catch & use `prompts`

* feat: enable asymmetric models

* chore: lint & format

* chore: remove redundant test

* chore: add explanatory comment

* fix: stop re-using 'bindings' name

* feat: treat empty inputs like null inputs

* chore: remove redundant docs file

* docs: add brief explanation

* docs: explain query document prompt configuration

* chore: lint

* chore: apply hyperspace bot feedback

Co-authored-by: hyperspace-pr-bot[bot] <209611008+hyperspace-pr-bot[bot]@users.noreply.github.com>

* chore: apply review suggestions

Co-authored-by: hyperspace-pr-bot[bot] <209611008+hyperspace-pr-bot[bot]@users.noreply.github.com>

* chore: add explanatory comment

---------

Co-authored-by: hyperspace-pr-bot[bot] <209611008+hyperspace-pr-bot[bot]@users.noreply.github.com>
Comment thread tests/vector.test.js Outdated
Co-authored-by: Paul <paul.erlenwein@gmail.com>
PDT42
PDT42 previously approved these changes Aug 31, 2026
sjvans and others added 2 commits September 1, 2026 01:02
* fix: harden asymmetric model semantics

* fix: integrate feedback on pipeline & passages

* test: align with removed passage alias

* docs: align with removed passage alias

Co-authored-by: Paul <paul.erlenwein@gmail.com>

* chore: format

* docs: clarify

---------

Co-authored-by: I548646 <paul.erlenwein@sap.com>
Co-authored-by: Paul <paul.erlenwein@gmail.com>
PDT42
PDT42 previously approved these changes Sep 1, 2026

@PDT42 PDT42 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.

🚀

@sjvans
sjvans merged commit dee89f3 into main Sep 1, 2026
15 checks passed
@sjvans
sjvans deleted the AISQLiteService branch September 1, 2026 18:33
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.

4 participants