外观
本页尚未翻译
本页内容仍为英文原文,源自官方文档 geneva/udfs/providers/gemini。中文翻译正在分批进行中。
Gemini
Embed text and generate completions using Google's Gemini models. See the API reference for Gemini UDFs and Embedding UDFs for all parameters.
bash
pip install 'geneva[udf-text-gemini]'注意
Gemini UDFs make API calls that incur per-token costs. Each row processed results in one or more API requests billed to your account. Review Gemini pricing before running on large tables.
说明
Set the GEMINI_API_KEY environment variable before calling any factory function below.
bash
export GEMINI_API_KEY="your-api-key"The key is read at UDF creation time and serialized with the UDF — no cluster-level env_vars configuration is needed.
Embeddings
Embed text with optional task-type hints for retrieval, classification, and clustering scenarios. See the API reference for all parameters.
Multiple embeddings tuned for different retrieval tasks:
python
from geneva.udfs import gemini_embedding_udf
table.add_columns({
# Full-dimension embedding for document retrieval
"embedding_doc": gemini_embedding_udf(
column="body",
model="gemini-embedding-001",
task_type="RETRIEVAL_DOCUMENT",
),
# Compact embedding for semantic similarity
"embedding_sim_256": gemini_embedding_udf(
column="body",
model="gemini-embedding-001",
task_type="SEMANTIC_SIMILARITY",
output_dimensionality=256,
),
})Generation
Generate text from Gemini models. Supports text, image, audio, video, and document inputs. See the API reference for all parameters.
Enrich a table with sentiment, captions, and transcriptions at once:
python
from geneva.udfs import gemini_udf
table.add_columns({
# Classify review sentiment with a fast model
"sentiment": gemini_udf(
column="review",
prompt="Classify the sentiment as positive, negative, or neutral. Return only the label.",
model="gemini-2.5-flash",
),
# Caption product images with a more capable model
"caption": gemini_udf(
column="image",
prompt="Describe the main subject of this image in one sentence",
model="gemini-2.5-pro",
mime_type="image/jpeg",
),
# Transcribe audio clips
"transcript": gemini_udf(
column="audio",
prompt="Transcribe this audio clip",
model="gemini-2.5-flash",
mime_type="audio/mp3",
),
})API Reference
- Gemini —
gemini_udf()parameters:column,prompt,model,mime_type, and more - Embeddings —
gemini_embedding_udf()parameters:column,model,task_type,dimensionality,normalize