Skip to main content
For the complete documentation index for agents and LLMs, see llms.txt.

VertexAITextGenerator

Generate text using Google Vertex AI generative models.

Key Features

  • Text generation using Google Vertex AI models (text-bison, text-unicorn, text-bison-32k)
  • Returns generated replies along with safety attributes and citations
  • Authenticates using Google Cloud Application Default Credentials (ADCs)

Configuration

  1. Drag the VertexAITextGenerator component onto the canvas from the Component Library.
  2. Click on the component to open the configuration panel.
  3. On the General tab:
    1. Enter your GCP project ID. Create a secret with the key GCP_PROJECT_ID. For detailed instructions, see Create Secrets.
    2. Optionally, enter the location. If not set, uses us-central1.
    3. Select a model. Supported models: text-bison, text-unicorn, text-bison-32k.
  4. Go to the Advanced tab to configure additional model keyword arguments.

Connections

VertexAITextGenerator accepts a text prompt (str) through its prompt input. It outputs replies (a list of strings), safety_attributes (a dictionary of safety scores), and citations (a list of citation dictionaries).

Connect PromptBuilder's prompt output to this component's prompt input. Connect the replies output to AnswerBuilder.

Source Code

To check this component's source code, open text_generator.py in the Haystack Core Integrations repository.

Usage Examples

Basic Configuration

  VertexAITextGenerator:
type: haystack_integrations.components.generators.google_vertex.text_generator.VertexAITextGenerator
init_parameters:
model: text-bison

This query pipeline uses VertexAITextGenerator to generate text responses:

components:
bm25_retriever:
type: haystack_integrations.components.retrievers.opensearch.bm25_retriever.OpenSearchBM25Retriever
init_parameters:
document_store:
type: haystack_integrations.document_stores.opensearch.document_store.OpenSearchDocumentStore
init_parameters:
hosts:
index: 'default'
max_chunk_bytes: 104857600
embedding_dim: 768
return_embedding: false
method:
mappings:
settings:
create_index: true
http_auth:
use_ssl:
verify_certs:
timeout:
top_k: 10
fuzziness: 0

PromptBuilder:
type: haystack.components.builders.prompt_builder.PromptBuilder
init_parameters:
template: |
Given the following information, answer the question.

Context:
{% for document in documents %}
{{ document.content }}
{% endfor %}

Question: {{ query }}
required_variables:
variables:

VertexAITextGenerator:
type: haystack_integrations.components.generators.google_vertex.text_generator.VertexAITextGenerator
init_parameters:
project_id:
model: text-bison
location:

AnswerBuilder:
type: haystack.components.builders.answer_builder.AnswerBuilder
init_parameters:
pattern:
reference_pattern:

connections:
- sender: bm25_retriever.documents
receiver: PromptBuilder.documents
- sender: PromptBuilder.prompt
receiver: VertexAITextGenerator.prompt
- sender: VertexAITextGenerator.replies
receiver: AnswerBuilder.replies
- sender: bm25_retriever.documents
receiver: AnswerBuilder.documents

inputs:
query:
- bm25_retriever.query
- PromptBuilder.query
- AnswerBuilder.query

outputs:
answers: AnswerBuilder.answers

max_runs_per_component: 100

metadata: {}

Parameters

Inputs

ParameterTypeDescription
promptstrThe prompt to use for text generation.

Outputs

ParameterTypeDescription
repliesList[str]A list of generated replies.
safety_attributesDict[str, float]Safety scores for each answer.
citationsList[Dict[str, Any]]Citations for each answer.

Init Parameters

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
project_idOptional[str]NoneID of the GCP project to use. By default, it is set during Google Cloud authentication.
modelstrtext-bisonName of the model to use.
locationOptional[str]NoneThe default location to use when making API calls. If not set, uses us-central-1.
kwargsAnyAdditional keyword arguments to pass to the model. See the TextGenerationModel.predict() documentation.

Run Method Parameters

These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.

ParameterTypeDescription
promptstrThe prompt to use for text generation.