Skip to content

REUSE status

CAP AI plugin for Node.js

@cap-js/ai adds UI recommendations powered by SAP AI Core, simplified access to SAP AI Core resources, and vector embedding support for CAP applications.

Recommendations

The plugin adds SAP-RPT-1 recommendations to draft-enabled entities. Fields with a value help are included automatically:

@odata.draft.enabled
entity Books {
  key ID    : Integer;
      title : String;
      genre : Association to Genres;
      price : Decimal;
}

annotate Genres with @cds.odata.valuelist;

Recommendations as default values

Use @UI.RecommendationState to opt individual fields in or out:

annotate Books with {
  genre @UI.RecommendationState: 0;
  price @UI.RecommendationState;
}

A production deployment requires an SAP AI Core service binding. Without one, local development uses a mock implementation for UI smoke tests. See Recommendations for regression targets, request behavior, data handling, and deployment lifecycle.

SAP AI Core

The plugin provides an AICore CAP service for managing resource groups, deployments, and configurations:

const aiCore = await cds.connect.to('AICore');
const { resourceGroups, deployments } = aiCore.entities;

const groups = await aiCore.run(SELECT.from(resourceGroups));
await aiCore.stop(deployments, { id: '<deployment id>' });

See SAP AI Core integration for setup, supported queries, helper methods, and multitenancy.

Local vector embeddings with SQLite (experimental)

Warning

The SQLite extensions, local vector embeddings, local model management, and the related tooling are experimental facilities for local development. Breaking changes are expected, including changes caused by SQLite's synchronous function interface and by local model management. Use SAP HANA's vector engine for production vector workloads.

Here is a complete Bookshop example.

  1. Install the local-development dependencies:

    npm add -D @cap-js/ai @cap-js/sqlite@^3.1 @huggingface/hub@^2.15.0 \
      @huggingface/tokenizers@0.1.3 onnxruntime-node@1.20.1

    Local vector embeddings require @sap/cds ^10.1 and @cap-js/sqlite ^3.1; the package's other capabilities continue to support @sap/cds 9.

  2. Use the standard SQLite service. Most CAP projects already do this in development; an explicit configuration looks like this:

    {
      "cds": {
        "requires": {
          "db": {
            "kind": "sqlite"
          }
        }
      }
    }
  3. Add an embedding preview to the Bookshop service. In its service implementation, which imports cds from @sap/cds:

    function embedding(text : String) returns LargeString;
    this.on('embedding', async (req) => {
      const [row] = await cds.db.run(
        `SELECT VECTOR_EMBEDDING(?, 'DOCUMENT', 'local') AS embedding`,
        [req.data.text]
      );
      return row.embedding;
    });
  4. Start the application and call the function:

    cds w

    In another terminal:

    curl 'http://localhost:4004/odata/v4/catalog/embedding(text=%27A%20book%20about%20travel%27)'

@cap-js/ai redirects the standard sqlite implementation to add the local capabilities. With @sap/cds ^10.1, the standard sqlite:memory preset inherits that implementation. The first start warns that the default model is missing, downloads it to .cds/models, and then initializes it. The response's value contains a JSON-encoded vector with 384 numbers. Later starts reuse the installed model.

The current default is sentence-transformers/all-MiniLM-L6-v2. It 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 below. This is not a recommendation, and the default may change at any time while this feature is experimental. Configure cds.requires.db.embedding.model explicitly if the choice must remain stable.

Start model discovery with trending Apache-2.0 sentence-similarity models that provide ONNX artifacts. These filters select a relevant task, a locally runnable format, and a permissive license, but they do not guarantee compatibility. Choose a model as big as necessary and as small as possible, then validate it with the provided tooling.

See Choosing a model and Local vector embeddings for compatibility checks, explicit or shared provisioning, runtime behavior, and limitations.

Advanced

Test the plugin locally

The sample application is in tests/bookshop.

npm test

Integration tests require an SAP AI Core binding:

cds bind ai-core -2 <your-ai-core-service-instance>
npm run test:hybrid

Support, feedback, and contributing

This project welcomes feature requests, bug reports, and contributions through GitHub issues. See the Contribution Guidelines for development information.

Security

Report potential security issues through the project's security policy, not through public issues.

Code of Conduct

Participation in this project is governed by the Code of Conduct.

Licensing

Copyright 2026 SAP SE or an SAP affiliate company and ai contributors. See LICENSE and the REUSE report.

About

A CDS plugin that provides out-of-the box AI features, like recommendations in value helps leveraging SAP-RPT-1 and simplifying the SAP AI Core integration.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

29 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages