@@ -17,8 +17,8 @@ class VertexAITextVectorizer(BaseVectorizer):
1717
1818 Utilizing this vectorizer requires an active GCP project and location
1919 (region), along with appropriate application credentials. These can be
20- provided through the `api_config` dictionary or by setting the corresponding
21- environment variables . Additionally, the vertexai python client must be
20+ provided through the `api_config` dictionary or set the GOOGLE_APPLICATION_CREDENTIALS
21+ env var . Additionally, the vertexai python client must be
2222 installed with `pip install google-cloud-aiplatform>=1.26`.
2323
2424 .. code-block:: python
@@ -29,8 +29,6 @@ class VertexAITextVectorizer(BaseVectorizer):
2929 api_config={
3030 "project_id": "your_gcp_project_id", # OR set GCP_PROJECT_ID
3131 "location": "your_gcp_location", # OR set GCP_LOCATION
32- "google_application_credentials": "path_to_your_creds"
33- # OR set GOOGLE_APPLICATION_CREDENTIALS
3432 })
3533 embedding = vectorizer.embed("Hello, world!")
3634
@@ -51,7 +49,7 @@ def __init__(
5149 model (str): Model to use for embedding. Defaults to
5250 'textembedding-gecko'.
5351 api_config (Optional[Dict], optional): Dictionary containing the
54- API key . Defaults to None.
52+ API config details . Defaults to None.
5553
5654 Raises:
5755 ImportError: If the google-cloud-aiplatform library is not installed.
@@ -79,25 +77,16 @@ def __init__(
7977 "or set the GCP_LOCATION environment variable."
8078 )
8179
82- # Check for Google Application Credentials
83- if "GOOGLE_APPLICATION_CREDENTIALS" not in os .environ :
84- creds_path = (
85- api_config .get ("google_application_credentials" ) if api_config else None
86- )
87- if creds_path :
88- os .environ ["GOOGLE_APPLICATION_CREDENTIALS" ] = creds_path
89- else :
90- raise ValueError (
91- "Missing Google Application Credentials. "
92- "Provide the path to the credentials JSON file in the api_config with\
93- key 'google_application_credentials' or set the \
94- GOOGLE_APPLICATION_CREDENTIALS environment variable."
95- )
80+ # Check for credentials
81+ credentials = api_config .get ("credentials" ) if api_config else None
82+
9683 try :
9784 import vertexai
98- from vertexai .preview . language_models import TextEmbeddingModel
85+ from vertexai .language_models import TextEmbeddingModel
9986
100- vertexai .init (project = project_id , location = location )
87+ vertexai .init (
88+ project = project_id , location = location , credentials = credentials
89+ )
10190 except ImportError :
10291 raise ImportError (
10392 "VertexAI vectorizer requires the google-cloud-aiplatform library. "
0 commit comments