{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Google Vertex AI PaLM \n", "\n", ">[Vertex AI PaLM API](https://cloud.google.com/vertex-ai/docs/generative-ai/learn/overview) is a service on Google Cloud exposing the embedding models. \n", "\n", "Note: This integration is seperate from the Google PaLM integration.\n", "\n", "By default, Google Cloud [does not use](https://cloud.google.com/vertex-ai/docs/generative-ai/data-governance#foundation_model_development) Customer Data to train its foundation models as part of Google Cloud`s AI/ML Privacy Commitment. More details about how Google processes data can also be found in [Google's Customer Data Processing Addendum (CDPA)](https://cloud.google.com/terms/data-processing-addendum).\n", "\n", "To use Vertex AI PaLM you must have the `google-cloud-aiplatform` Python package installed and either:\n", "- Have credentials configured for your environment (gcloud, workload identity, etc...)\n", "- Store the path to a service account JSON file as the GOOGLE_APPLICATION_CREDENTIALS environment variable\n", "\n", "This codebase uses the `google.auth` library which first looks for the application credentials variable mentioned above, and then looks for system-level auth.\n", "\n", "For more information, see: \n", "- https://cloud.google.com/docs/authentication/application-default-credentials#GAC\n", "- https://googleapis.dev/python/google-auth/latest/reference/google.auth.html#module-google.auth\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "#!pip install google-cloud-aiplatform" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from langchain.embeddings import VertexAIEmbeddings" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "embeddings = VertexAIEmbeddings()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "text = \"This is a test document.\"" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "query_result = embeddings.embed_query(text)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "doc_result = embeddings.embed_documents([text])" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" }, "vscode": { "interpreter": { "hash": "cc99336516f23363341912c6723b01ace86f02e26b4290be1efc0677e2e2ec24" } } }, "nbformat": 4, "nbformat_minor": 4 }