Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions guides/databases/vector-embeddings.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ 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.
On H2 and SQLite the `CQL.vectorEmbedding` function is emulated to support local testing.
Both runtimes support a hash-based mock embedding, CAP Java additionally allows using local [ONNX](https://onnx.ai) embeddings models.
:::

> [!warning] Java only and <Beta/>
> The `vector_embedding` function is currently in beta and only supported by the CAP Java runtime.
> [!warning] <Beta/> and not supported on PostgreSQL
> The `vector_embedding` function is currently in beta and not supported on PostgreSQL.

[Learn more about Vector Embeddings in CAP Java](../../java/cds-data#vector-embeddings) {.learn-more}

Expand Down Expand Up @@ -114,7 +115,9 @@ let similarIncidents = await SELECT.from('Incidents')

## Vector Functions

CAP provides equivalent implementations of vector functions for all supported databases based on the function signatures as defined in SAP HANA:
CAP provides equivalent implementations of vector functions for all supported databases based on the function signatures as defined in SAP HANA.

[Learn more about Vector Functions in CAP Java](../../java/working-with-cql/query-api#vector-functions) {.learn-more}

### [cosine_similarity](https://help.sap.com/docs/hana-cloud-database/sap-hana-cloud-sap-hana-database-sql-reference-guide/cosine-similarity-function-vector)
```
Expand All @@ -138,9 +141,9 @@ 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.
- **PostgreSQL:** No default implementation. Application developers must define their own `vector_embedding` function.
- **SAP HANA:** Uses embedding models from the [NLP](https://help.sap.com/docs/hana-cloud-database/sap-hana-cloud-sap-hana-database-predictive-analysis-library/natural-language-processing-nlp) extension or an [SAP AI Core](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/what-is-sap-ai-core) remote source.
- **SQLite & H2:** Hash-based mock embedding. CAP Java additionally allows using local [ONNX](https://onnx.ai) embeddings models.
- **PostgreSQL:** Not supported.

## Database-Specific Considerations

Expand All @@ -150,13 +153,12 @@ vector_embedding(text, text_type, model_name, remote_source) → vector
CREATE EXTENSION IF NOT EXISTS vector;
```
- Vectors stored in native `vector` type
- `vector_embedding()` function must be defined by application developers for both testing and production use.
- `vector_embedding()` function is not supported by CAP.

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.

Isn't the previous sentence more helpful to developers? Or let's say more explicit about what it means for CAP developers if they want to use such a function?

- For Node.js, the `pgvector` npm package is required when reading vector columns from query results or when passing vector values as parameters from the client. It is not needed if vectors are generated entirely within the database using functions like `vector_embedding()`: `npm install pgvector`

### SAP HANA
- Native vector engine with built-in support
- Type mapping: `cds.Vector` → `REAL_VECTOR`
- `vector_embedding()` supports built-in SAP models and external remote sources (such as Azure OpenAI, SAP AI Core)
- Type mapping: `cds.Vector` → [REAL_VECTOR](https://help.sap.com/docs/hana-cloud-database/sap-hana-cloud-sap-hana-database-vector-engine-guide/real-vector-and-half-vector-data-types)

[Learn more about HANA Vector Engine](https://help.sap.com/docs/hana-cloud-database/sap-hana-cloud-sap-hana-database-vector-engine-guide) {.learn-more}

Expand Down
5 changes: 3 additions & 2 deletions java/working-with-cql/query-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1681,8 +1681,9 @@ These methods allow you to compute the difference between timestamps:

Vector functions allow you to compute similarity and distance of [vectors](../cds-data.md#vector-embeddings), as well as [vector embeddings](../../guides/databases/vector-embeddings) of text data directly in the database.

::: warning Not supported with local MTXS on SQLite
Using vector functions in [stored calculated elements](../../cds/cdl#on-write) with [local MTXS](../../guides/multitenancy/mtxs#test-drive-locally) on SQLite isn't supported.
::: warning Local MTXS on SQLite
Using vector functions in [stored calculated elements](../../cds/cdl#on-write) with [local MTXS](../../guides/multitenancy/mtxs#test-drive-locally) on SQLite
calls the custom functions of the CAP Node.js runtime. Using local [ONNX](https://onnx.ai) embedding models is not yet supported.
:::

##### Computing Vector Embeddings in SAP HANA <Beta />
Expand Down
Loading