feat: add AI-enabled SQLite service - #53
Conversation
SummaryThe following content is AI-generated and provides a summary of the pull request: feat: Introduce
|
There was a problem hiding this comment.
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
* 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>
* 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>
* 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>
Co-authored-by: Paul <paul.erlenwein@gmail.com>
* 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>
Summary
Extends CAP's standard
sqliteservice and itssqlite:memorypreset for local development with:VECTOR_EMBEDDINGbacked by a locally managed ONNX encoder modelsentence-transformers/all-MiniLM-L6-v2as the current replaceable default<cds.root>/.cds/models/<model>npx @cap-js/ai install-model <model>npx @cap-js/ai check-model <model>SPARQL_EXECUTEandsparql_tablesupport backed by OxigraphThe 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.1and@cap-js/sqlite^3.1. The package-wide@sap/cdspeer remains>=9for the other capabilities.SQLite kind integration
@cap-js/aioverrides only the basesqliteimplementation. The standardsqlite:memorypreset supplied by@sap/cdsinherits 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-localsqlite:memoryworkaround.Quick configuration
{ "cds": { "requires": { "db": { "kind": "sqlite" } } } }Installing
@cap-js/airedirects the base SQLite kind. With@sap/cds^10.1,sqlite:memoryinherits the same AI-enabled implementation. The default model is therefore provisioned and initialized when either SQLite service starts, even if the application never callsVECTOR_EMBEDDING. HANA services are unaffected.sentence-transformers/all-MiniLM-L6-v2was 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. Setcds.requires.db.embedding.modelexplicitly when the model choice must remain stable.embedding.directoryis 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 fromcds.root, while absolute and home-relative paths can be shared across projects. Additionalembeddingproperties 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 passednpm run lintsqliteand inheritedsqlite:memory, including the one-connection pool