Gemini Text Embeddings
Turn text into vectors for search, clustering, and RAG
- embedding_json
- dim
Embeddings are the quiet workhorse of the "text in, meaning out" world: a model turns a piece of text into a vector of numbers such that similar texts land near each other. Once you have vectors, you can search semantically, cluster related prompts, classify content, or feed a retrieval step in a RAG pipeline. This node gives you Gemini's embedding vectors directly inside ComfyUI - the odd node out in a pack otherwise full of generators, and genuinely useful if you're building anything that organizes text at scale.
Required inputs: api_key, model (gemini-embedding-001 by default, with the newer gemini-embedding-2 and its preview in the list), and text - the content to embed.
The controls that matter:
task_type- optimize the embedding for the downstream job:SEMANTIC_SIMILARITY,CLASSIFICATION,CLUSTERING,RETRIEVAL_QUERY,RETRIEVAL_DOCUMENT,QUESTION_ANSWERING,FACT_VERIFICATION,CODE_RETRIEVAL_QUERY. This isn't flavor - Gemini tunes the vector differently per task, and using the wrong one measurably hurts results. Query vs. document is the pairing to get right in retrieval setups: embed your search queries asRETRIEVAL_QUERYand your corpus asRETRIEVAL_DOCUMENT.output_dim- 128 to 3072 in steps of 128, default 768. Bigger = more expressive but more storage and slower matching. Start at the default; bump it only if your task needs the headroom.custom_model- escape hatch for new model IDs.
Outputs: embedding_json (the vector as a JSON string - this is the thing you store and compare) and dim (the actual dimension, an INT).
Where it fits in a workflow
The realistic ComfyUI pattern is batch-and-store: embed a folder of prompts or captions into a file (via a save node), then later embed a query and compare. ComfyUI has no native vector database, so you'll be doing the comparison in a Python node or exporting the JSON - but this node gets you the vectors in the first place, which is the hard part. dim is handy for downstream node config that needs to know the vector size up front.
Installing it
Part of the ComfyUI API Toolkit pack. Manager: search "API Toolkit". Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/IxMxAMAR/ComfyUI-API-Toolkit
cd ComfyUI-API-Toolkit
pip install -r requirements.txt
Restart. Needs google-genai>=0.8.0.
Gotchas
embedding_jsonis a string, not a tensor - there's no native vector type in ComfyUI, so plan to parse it. That's a pack limitation, not a bug.- Embedding calls are metered per token too, and the pack re-runs API nodes every queue, so bulk-embedding a large corpus through this node in a loop is doable but costs real money. Batch it once, store the result, don't leave it live in a hot workflow.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| api_key | STRING | — | |
| model | COMBO | gemini-embedding-001 | 3 options: gemini-embedding-2, gemini-embedding-2-preview, gemini-embedding-001 |
| text | STRING | — | |
| custom_modelopt | STRING | — | |
| task_typeopt | COMBO | SEMANTIC_SIMILARITY | Optimize the embedding for this downstream task. |
| output_dimopt | INT | 768128–3072 | Output dimensionality. 768 is default. Larger = more expressive. |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| embedding_json | STRING | — |
| dim | INT | — |