vectorisers.gcp.GcpVectoriser

vectorisers.gcp.GcpVectoriser(
    project_id=None,
    api_key=None,
    location='europe-west2',
    model_name='text-embedding-004',
    task_type='CLASSIFICATION',
    **client_kwargs,
)

A class for embedding text using Google Cloud Platform’s GenAI API.

This class provides functionality to embed text using Google’s GenAI API. It supports two authentication methods for setting up the client:

  1. Using project_id and location: This method requires specifying the Google Cloud project ID and the location of the GenAI API. It is suitable for users who have a Google Cloud project and want to authenticate using project-based credentials. It will require local authentication through the Google Cloud SDK.

  2. Using api_key: This method requires providing an API key for authentication. It is suitable for users who want to authenticate using an API key without specifying a project ID and location. This approach does not require local authentication through the Google Cloud SDK.

Attributes

Name Type Description
model_name str The name of the embedding model to use.
vectoriser genai.Client The GenAI client instance for embedding text.
model_config genai.types.EmbedContentConfig Configuration for the embedding task.

Methods

Name Description
transform Transforms input text(s) into embeddings using the GenAI API.

transform

vectorisers.gcp.GcpVectoriser.transform(texts)

Transforms input text(s) into embeddings using the GenAI API.

Parameters

Name Type Description Default
texts (str, list[str]) The input text(s) to embed. Can be a single string or a list of strings. required

Returns

Name Type Description
np.ndarray numpy.ndarray: A 2D array of embeddings, where each row corresponds to an input text.

Raises

Name Type Description
ExternalServiceError If the GenAI API request fails.
VectorisationError If the response format from the GenAI API is unexpected.