VertexAIEmbeddings#
- class langchain_google_vertexai.embeddings.VertexAIEmbeddings[source]#
Bases:
_VertexAICommon
,Embeddings
Google Cloud VertexAI embedding models.
Initialize the sentence_transformer.
- param additional_headers: Dict[str, str] | None = None#
A key-value dictionary representing additional headers for the model call
- param api_endpoint: str | None = None (alias 'base_url')#
Desired API endpoint, e.g., us-central1-aiplatform.googleapis.com
- param api_transport: str | None = None#
The desired API transport method, can be either βgrpcβ or βrestβ. Uses the default parameter in vertexai.init if defined.
- param client_cert_source: Callable[[], Tuple[bytes, bytes]] | None = None#
A callback which returns client certificate bytes and private key bytes both
- param credentials: Any = None#
The default custom credentials (google.auth.credentials.Credentials) to use
- param full_model_name: str | None = None#
The full name of the modelβs endpoint.
- param location: str = 'us-central1'#
The default location to use when making API calls.
- param max_output_tokens: int | None = None (alias 'max_tokens')#
Token limit determines the maximum amount of text output from one prompt.
- param max_retries: int = 6#
The maximum number of retries to make when generating.
- param model_name: str = None (alias 'model')#
Underlying model name.
- param n: int = 1#
How many completions to generate for each prompt.
- param project: str | None = None#
The default GCP project to use when making Vertex API calls.
- param request_parallelism: int = 5#
The amount of parallelism allowed for requests issued to VertexAI models.
- param safety_settings: 'SafetySettingsType' | None = None#
The default safety settings to use for all generations.
For example:
from langchain_google_vertexai import HarmBlockThreshold, HarmCategory
- safety_settings = {
HarmCategory.HARM_CATEGORY_UNSPECIFIED: HarmBlockThreshold.BLOCK_NONE, HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE, HarmCategory.HARM_CATEGORY_HATE_SPEECH: HarmBlockThreshold.BLOCK_ONLY_HIGH, HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE, HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: HarmBlockThreshold.BLOCK_NONE,
}
- param seed: int | None = None#
Random seed for the generation.
- param stop: List[str] | None = None (alias 'stop_sequences')#
Optional list of stop words to use when generating.
- param streaming: bool = False#
Whether to stream the results or not.
- param temperature: float | None = None#
Sampling temperature, it controls the degree of randomness in token selection.
- param top_k: int | None = None#
How the model selects tokens for output, the next token is selected from
- param top_p: float | None = None#
Tokens are selected from most probable to least until the sum of their
- param tuned_model_name: str | None = None#
The name of a tuned model. If tuned_model_name is passed model_name will be used to determine the model family
- async aembed_documents(texts: list[str]) list[list[float]] #
Asynchronous Embed search docs.
- Parameters:
texts (list[str]) β List of text to embed.
- Returns:
List of embeddings.
- Return type:
list[list[float]]
- async aembed_query(text: str) list[float] #
Asynchronous Embed query text.
- Parameters:
text (str) β Text to embed.
- Returns:
Embedding.
- Return type:
list[float]
- embed(texts: List[str], batch_size: int = 0, embeddings_task_type: Literal['RETRIEVAL_QUERY', 'RETRIEVAL_DOCUMENT', 'SEMANTIC_SIMILARITY', 'CLASSIFICATION', 'CLUSTERING', 'QUESTION_ANSWERING', 'FACT_VERIFICATION'] | None = None, dimensions: int | None = None) List[List[float]] [source]#
Embed a list of strings.
- Parameters:
texts (List[str]) β List[str] The list of strings to embed.
batch_size (int) β [int] The batch size of embeddings to send to the model. If zero, then the largest batch size will be detected dynamically at the first request, starting from 250, down to 5.
embeddings_task_type (Literal['RETRIEVAL_QUERY', 'RETRIEVAL_DOCUMENT', 'SEMANTIC_SIMILARITY', 'CLASSIFICATION', 'CLUSTERING', 'QUESTION_ANSWERING', 'FACT_VERIFICATION'] | None) β
[str] optional embeddings task type, one of the following
- RETRIEVAL_QUERY - Text is a query
in a search/retrieval setting.
- RETRIEVAL_DOCUMENT - Text is a document
in a search/retrieval setting.
- SEMANTIC_SIMILARITY - Embeddings will be used
for Semantic Textual Similarity (STS).
CLASSIFICATION - Embeddings will be used for classification. CLUSTERING - Embeddings will be used for clustering. The following are only supported on preview models: QUESTION_ANSWERING FACT_VERIFICATION
dimensions (int | None) β [int] optional. Output embeddings dimensions. Only supported on preview models.
- Returns:
List of embeddings, one for each text.
- Return type:
List[List[float]]
- embed_documents(texts: List[str], batch_size: int = 0) List[List[float]] [source]#
Embed a list of documents.
- Parameters:
texts (List[str]) β List[str] The list of texts to embed.
batch_size (int) β [int] The batch size of embeddings to send to the model. If zero, then the largest batch size will be detected dynamically at the first request, starting from 250, down to 5.
- Returns:
List of embeddings, one for each text.
- Return type:
List[List[float]]
- embed_image(image_path: str, contextual_text: str | None = None, dimensions: int | None = None) List[float] [source]#
Deprecated since version langchain-google-vertexai==2.0.1: Use
embed_images()
instead.Embed an image.
- Parameters:
image_path (str) β Path to image (Google Cloud Storage or web) to generate
for. (embeddings)
contextual_text (str | None) β Text to generate embeddings for.
dimensions (int | None)
- Returns:
Embedding for the image.
- Return type:
List[float]
- embed_images(uris: List[str], contextual_text: str | None = None, dimensions: int | None = None) List[List[float]] [source]#
Embed a list of images.
- Parameters:
uris (List[str]) β Paths to image (local, Google Cloud Storage or web) to generate
for. (embeddings)
contextual_text (str | None) β Text to generate embeddings for.
dimensions (int | None)
- Returns:
Embedding for the image.
- Return type:
List[List[float]]
- embed_query(text: str) List[float] [source]#
Embed a text.
- Parameters:
text (str) β The text to embed.
- Returns:
Embedding for the text.
- Return type:
List[float]
- get_num_tokens(text: str) int #
Get the number of tokens present in the text.
Useful for checking if an input will fit in a modelβs context window.
- Parameters:
text (str) β The string input to tokenize.
- Returns:
The integer number of tokens in the text.
- Return type:
int
- property async_prediction_client: PredictionServiceAsyncClient#
Returns PredictionServiceClient.
- property model_type: str#
- property model_version: GoogleEmbeddingModelVersion#
- property prediction_client: PredictionServiceClient#
Returns PredictionServiceClient.
- task_executor: ClassVar[Executor | None] = FieldInfo(annotation=NoneType, required=False, default=None, exclude=True)#