VertexAITextGenerator
Generate text using Google Vertex AI generative models.
Key Features
- Generates text responses using Vertex AI models (
text-bison,text-unicorn,text-bison-32k). - Authenticates using Google Cloud Application Default Credentials.
- Returns generated replies along with safety attributes and citations.
Configuration
This component authenticates using Google Cloud Application Default Credentials (ADCs). For more information, see the official Google documentation.
Create secrets for GCP_PROJECT_ID and optionally GCP_DEFAULT_REGION. For detailed instructions on creating secrets, see Create Secrets.
- Drag the
VertexAITextGeneratorcomponent onto the canvas from the Component Library. - Click the component to open the configuration panel.
- On the General tab:
- Enter the model name (for example,
text-bison).
- Enter the model name (for example,
- Go to the Advanced tab to configure the project ID, location, and additional model kwargs.
Connections
VertexAITextGenerator accepts a prompt string as input. It outputs a list of generated replies (replies), safety attribute scores (safety_attributes), and citations (citations).
Typically, you connect PromptBuilder to the prompt input and AnswerBuilder to the replies output.
Usage Example
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
| Parameter | Type | Default | Description |
|---|---|---|---|
| prompt | str | The prompt to use for text generation. |
Outputs
| Parameter | Type | Default | Description |
|---|---|---|---|
| replies | List[str] | A list of generated replies. | |
| safety_attributes | Dict[str, float] | Safety scores for each answer. | |
| citations | List[Dict[str, Any]] | Citations for each answer. |
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
| project_id | Optional[str] | None | ID of the GCP project to use. By default, it is set during Google Cloud authentication. |
| model | str | text-bison | Name of the model to use. |
| location | Optional[str] | None | The default location to use when making API calls. If not set, uses us-central-1. |
| kwargs | Any | Additional 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.
| Parameter | Type | Default | Description |
|---|---|---|---|
| prompt | str | The prompt to use for text generation. |
Was this page helpful?