langchain_google_vertexai.embeddings
.VertexAIEmbeddings¶
- class langchain_google_vertexai.embeddings.VertexAIEmbeddings[source]¶
Bases:
_VertexAICommon
,Embeddings
Google Cloud VertexAI embedding models.
Initialize the sentence_transformer.
- param additional_headers: Optional[Dict[str, str]] = None¶
A key-value dictionary representing additional headers for the model call
- param api_endpoint: Optional[str] = None (alias 'base_url')¶
Desired API endpoint, e.g., us-central1-aiplatform.googleapis.com
- param api_transport: Optional[str] = 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: Optional[Callable[[], Tuple[bytes, bytes]]] = 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: Optional[str] = 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: Optional[int] = 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: Optional[str] = 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: Optional['SafetySettingsType'] = 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 stop: Optional[List[str]] = 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: Optional[float] = None¶
Sampling temperature, it controls the degree of randomness in token selection.
- param top_k: Optional[int] = None¶
How the model selects tokens for output, the next token is selected from
- param top_p: Optional[float] = None¶
Tokens are selected from most probable to least until the sum of their
- param tuned_model_name: Optional[str] = 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: Optional[Literal['RETRIEVAL_QUERY', 'RETRIEVAL_DOCUMENT', 'SEMANTIC_SIMILARITY', 'CLASSIFICATION', 'CLUSTERING', 'QUESTION_ANSWERING', 'FACT_VERIFICATION']] = None, dimensions: Optional[int] = 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 (Optional[Literal['RETRIEVAL_QUERY', 'RETRIEVAL_DOCUMENT', 'SEMANTIC_SIMILARITY', 'CLASSIFICATION', 'CLUSTERING', 'QUESTION_ANSWERING', 'FACT_VERIFICATION']]) –
[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 (Optional[int]) – [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: Optional[str] = None) List[float] [source]¶
Embed an image.
- Parameters
image_path (str) – Path to image (local, Google Cloud Storage or web) to generate
for. (embeddings) –
contextual_text (Optional[str]) – Text to generate embeddings for.
- Returns
Embedding for the image.
- Return type
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[Optional[Executor]] = FieldInfo(exclude=True, extra={})¶