-
Notifications
You must be signed in to change notification settings - Fork 168
Refine vector embeddings docs #2826
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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} | ||||||
|
|
||||||
|
|
@@ -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) | ||||||
| ``` | ||||||
|
|
@@ -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. | ||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| - **PostgreSQL:** Not supported. | ||||||
|
|
||||||
| ## Database-Specific Considerations | ||||||
|
|
||||||
|
|
@@ -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. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MattSchur @vkozyura What is your reply to my comment above?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Postgres is usually not used for testing but for production, so simple mock embeddings are not sufficient. For production, I don't think that implementing a |
||||||
| - 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} | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vkozyura would this work with @cap-js/ai? What model would be used? |
||
| ::: | ||
|
|
||
| ##### Computing Vector Embeddings in SAP HANA <Beta /> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vkozyura Node ships ONNX support via
@cap-js/ai, correct?