From cefadbec1f3937ee31de866c90e8467521889bb0 Mon Sep 17 00:00:00 2001 From: Sebastian Van Syckel Date: Wed, 26 Aug 2026 10:06:28 +0200 Subject: [PATCH 1/4] rm java only --- guides/databases/vector-embeddings.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/guides/databases/vector-embeddings.md b/guides/databases/vector-embeddings.md index 96344915f6..7b0ffd430e 100644 --- a/guides/databases/vector-embeddings.md +++ b/guides/databases/vector-embeddings.md @@ -50,9 +50,6 @@ If the database calculates vector embeddings on write it automatically regenerat On H2 and SQLite the `CQL.vectorEmbedding` function is emulated using a hash-based algorithm to support local testing. For PostgreSQL, customers must define their own `vector_embedding` function for both testing and production use. ::: -> [!warning] Java only and -> The `vector_embedding` function is currently in beta and only supported by the CAP Java runtime. - [Learn more about Vector Embeddings in CAP Java](../../java/cds-data#vector-embeddings) {.learn-more} ### Generate Embeddings Programmatically From 258c0cace6e623aa6e950d1c0feaa45b735fff5d Mon Sep 17 00:00:00 2001 From: Sebastian Van Syckel Date: Wed, 26 Aug 2026 10:12:05 +0200 Subject: [PATCH 2/4] docs: Node.js ai-sqlite embeddings in vector-embeddings guide --- guides/databases/vector-embeddings.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/guides/databases/vector-embeddings.md b/guides/databases/vector-embeddings.md index 7b0ffd430e..23185f12a2 100644 --- a/guides/databases/vector-embeddings.md +++ b/guides/databases/vector-embeddings.md @@ -48,6 +48,8 @@ If the database calculates vector embeddings on write it automatically regenerat ::: info Local Testing with H2 and SQLite On H2 and SQLite the `CQL.vectorEmbedding` function is emulated using a hash-based algorithm to support local testing. For PostgreSQL, customers must define their own `vector_embedding` function for both testing and production use. + +In CAP Node.js, install the [`@cap-js/ai`](https://github.com/cap-js/ai) plugin and set the database kind to `ai-sqlite` to generate real embeddings locally on SQLite with an [ONNX](https://onnx.ai) model instead of the hash-based emulation. ::: [Learn more about Vector Embeddings in CAP Java](../../java/cds-data#vector-embeddings) {.learn-more} @@ -136,11 +138,19 @@ vector_embedding(text, text_type, model_name, remote_source) → vector **Database Implementation:** - **HANA:** Uses real AI models (SAP built-in models or external remote sources) -- **SQLite & H2:** Hash-based deterministic implementation for testing. Can be overridden by application developers to use external embedding services. +- **SQLite & H2:** Hash-based deterministic implementation for testing. Can be overridden by application developers to use external embedding services. In CAP Node.js, the [`@cap-js/ai`](https://github.com/cap-js/ai) plugin with the `ai-sqlite` database kind generates real embeddings locally via an [ONNX](https://onnx.ai) model. - **PostgreSQL:** No default implementation. Application developers must define their own `vector_embedding` function. ## Database-Specific Considerations +### SQLite +- Hash-based, deterministic `vector_embedding` implementation by default, suitable for local testing. +- In CAP Node.js, install [`@cap-js/ai`](https://github.com/cap-js/ai) and set the database kind to `ai-sqlite` to generate real embeddings locally with an [ONNX](https://onnx.ai) model, without any external service. + ```sh + npm add @cap-js/ai onnxruntime-node@1.20.1 + ``` + cds.requires.db: ai-sqlite + ### PostgreSQL - Requires that the [pgvector extension](https://github.com/pgvector/pgvector) is installed on your PostgreSQL instance. Then create the extension in your database: ```sql From a186b59ed9fe860257b708b2c199148af7fd3715 Mon Sep 17 00:00:00 2001 From: Sebastian Van Syckel Date: Wed, 26 Aug 2026 13:29:43 +0200 Subject: [PATCH 3/4] docs: use in-database vector_embedding in Node.js similarity example --- guides/databases/vector-embeddings.md | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/guides/databases/vector-embeddings.md b/guides/databases/vector-embeddings.md index 23185f12a2..80c40106e7 100644 --- a/guides/databases/vector-embeddings.md +++ b/guides/databases/vector-embeddings.md @@ -99,15 +99,13 @@ Select.from(INCIDENTS) ``` ```js [Node.js] -const response = await new AzureOpenAiEmbeddingClient( - 'text-embedding-3-small' -).run({ - input: 'Any incidents with solar inverters this month? How were they resolved?' -}); - -const questionEmbedding = response.getEmbedding(); -let similarIncidents = await SELECT.from('Incidents') - .where`cosine_similarity(embedding, to_real_vector(${questionEmbedding})) > 0.75`; +const question = + 'Any incidents with solar inverters this month? How were they resolved?' + +// Compute the question's embedding and find related incidents, all in the database +const similarIncidents = await SELECT.from('Incidents').where` + cosine_similarity(embedding, + vector_embedding(${question}, 'QUERY', 'SAP_GXY.20250407')) > 0.75` ``` ::: From 78306bd9da8ec0fd6161b52fb682c7d854ab605e Mon Sep 17 00:00:00 2001 From: Sebastian Van Syckel Date: Mon, 31 Aug 2026 09:39:41 +0200 Subject: [PATCH 4/4] docs: align ai-sqlite local embeddings with @cap-js/ai#53 Correct the install command (full peer deps), config (nested embedding.model, no default), and framing (experimental, local dev only) for the ai-sqlite database kind. --- guides/databases/vector-embeddings.md | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/guides/databases/vector-embeddings.md b/guides/databases/vector-embeddings.md index 80c40106e7..302f2cd258 100644 --- a/guides/databases/vector-embeddings.md +++ b/guides/databases/vector-embeddings.md @@ -49,7 +49,7 @@ If the database calculates vector embeddings on write it automatically regenerat ::: info Local Testing with H2 and SQLite On H2 and SQLite the `CQL.vectorEmbedding` function is emulated using a hash-based algorithm to support local testing. For PostgreSQL, customers must define their own `vector_embedding` function for both testing and production use. -In CAP Node.js, install the [`@cap-js/ai`](https://github.com/cap-js/ai) plugin and set the database kind to `ai-sqlite` to generate real embeddings locally on SQLite with an [ONNX](https://onnx.ai) model instead of the hash-based emulation. +In CAP Node.js, the [`@cap-js/ai`](https://github.com/cap-js/ai) plugin adds an `ai-sqlite` database kind that generates real embeddings locally on SQLite with an [ONNX](https://onnx.ai) model. It requires a configured embedding model and is experimental, for local development only. ::: [Learn more about Vector Embeddings in CAP Java](../../java/cds-data#vector-embeddings) {.learn-more} @@ -143,11 +143,23 @@ vector_embedding(text, text_type, model_name, remote_source) → vector ### SQLite - Hash-based, deterministic `vector_embedding` implementation by default, suitable for local testing. -- In CAP Node.js, install [`@cap-js/ai`](https://github.com/cap-js/ai) and set the database kind to `ai-sqlite` to generate real embeddings locally with an [ONNX](https://onnx.ai) model, without any external service. +- In CAP Node.js, the [`@cap-js/ai`](https://github.com/cap-js/ai) plugin adds an `ai-sqlite` database kind that generates real embeddings locally with an [ONNX](https://onnx.ai) model, without any external service. It is experimental and intended for local development only. + + Install the plugin with its peer dependencies: ```sh - npm add @cap-js/ai onnxruntime-node@1.20.1 + npm add -D @cap-js/ai @cap-js/sqlite \ + @huggingface/hub @huggingface/tokenizers onnxruntime-node@1.20.1 + ``` + Then set the database kind and configure an embedding model (there's no default): + ```json + { + "cds": { "requires": { "db": { + "kind": "ai-sqlite", + "embedding": { "model": "sentence-transformers/all-MiniLM-L6-v2" } + } } } + } ``` - cds.requires.db: ai-sqlite + On first start, the model is downloaded to `.cds/models` and reused afterwards. See the [`@cap-js/ai` README](https://github.com/cap-js/ai#local-vector-embeddings-with-sqlite-experimental) for the full walkthrough and model selection. ### PostgreSQL - Requires that the [pgvector extension](https://github.com/pgvector/pgvector) is installed on your PostgreSQL instance. Then create the extension in your database: