fix: isolate Vertex AI credentials within each embedding client
Summary
VertexAIEmbeddingConfig.get_client() currently writes every configuration's service-account key to the same file and replaces the process-wide GOOGLE_APPLICATION_CREDENTIALS setting. Creating one embedding client can therefore replace another component's application-default credential selection, and separate configurations share a mutable credential file.
Parse the provided service-account JSON into a Google Auth credentials object and pass that object and its project directly to VertexAIEmbeddings. Each client retains its own account, and construction no longer changes the environment or creates a key file. The existing explicit register_application_credentials() method remains available.
Testing
- On unchanged
ac932052e6e0ba3feab8a6e96b6d4480218e009f, the seven new regression cases produce 6 failures and 1 passing control. With the fix, the new cases and the neighboring Vertex encoder test produce 8 passes. - Tests construct the real Vertex AI SDK client with locally generated RSA service-account keys. They check credential identity and project, verify a real Google Auth RSA signature, construct two independent clients in both orders, preserve an existing application-default credentials setting, reject malformed JSON, and ensure no credential file is created. They make no embedding or authentication requests.
- Verified with Python 3.12.16,
langchain-google-vertexai3.3.0,google-auth2.62.2 andgoogle-genai2.34.0. SDK-dependent regression cases skip when the optional modern SDK is unavailable; existing tests retain their normal coverage. - Changed-file Ruff checks, Ruff formatting and source integrity checks pass.
Reproducible fork validation: https://github.com/Afloat16/unstructured/actions/runs/43843777142
The full repository suite and hosted Vertex embedding service were not run.