VectorPCAwithEmbeddings¶
- class hana_ml.text.pal_embeddings.VectorPCAwithEmbeddings(model_version=None, pca_dim_num=None)¶
Principal component projection for PAL text embedding vectors.
This class wraps the PAL procedure
PAL_TEXTEMBEDDING_PCA_PROJECTspecified for the SAP HANA PAL Embedding.- Parameters
- model_version: {'SAP_NEB.20240715', 'SAP_GXY.20250407'}, optional
PAL Embedding model version to use.
Options:
'SAP_NEB.20240715'
'SAP_GXY.20250407'
Defaults to None (uses 'SAP_NEB.20240715' by default).
- pca_dim_numint, optional
Specifies the reduced dimension to keep in the output. Allowed values include 64, 128, 256, 384, 512, 768.
If not provided, the model's default vector dimension is used.
- Attributes
- result_DataFrame
Projection result with ID and
SCORE_VECTOR.
Methods
fit_transform(data[, key, vector_col, ...])Project embedding vectors to lower dimensions.
Examples
If you have a DataFrame df_embed with columns 'ID' and 'EMBEDDING_VECTOR' (REAL_VECTOR), you can project the embedding vectors to 64 dimensions as follows:
>>> from hana_ml.text.pal_embeddings import VectorPCAwithEmbeddings >>> pe = VectorPCAwithEmbeddings(model_version='SAP_NEB.20240715', pca_dim_num=64) >>> result = pe.fit_transform(data=df_embed, key='ID', vector_col='EMBEDDING_VECTOR', thread_ratio=0.5) >>> print(result.collect())
- fit_transform(data, key=None, vector_col=None, thread_ratio=None)¶
Project embedding vectors to lower dimensions.
- Parameters
- dataDataFrame
Input data table.
- keystr, optional
Name of the ID column. Mandatory if
datais not indexed, or the index ofdatacontains multiple columns.Defaults to the single index column of
dataif not provided.- vector_colstr, optional
Name of the embedding vector column.
If not provided, it is inferred as the first non-key column.
- thread_ratiofloat, optional
Specifies the ratio of total available threads. The valid range is [0, 1], where 0 means single thread and 1 means all available threads.
Defaults to 1.0.
- Returns
- DataFrame
Projection result table with:
First column: same as the ID column in
data.Second column:
SCORE_VECTOR(REAL_VECTOR).