1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const axios = require('axios');
const api_key = "YOUR API-KEY";
const url = "https://api.segmind.com/v1/gemini-embedding-2";
const data = {
"input": "Segmind provides fast and affordable AI model APIs for image generation, video creation, and more.",
"task_type": "RETRIEVAL_DOCUMENT",
"output_dimensionality": 768
};
(async function() {
try {
const response = await axios.post(url, data, { headers: { 'x-api-key': api_key } });
console.log(response.data);
} catch (error) {
console.error('Error:', error.response.data);
}
})();Text string to embed; supports up to ~8,192 tokens. Use shorter, focused sentences for best retrieval accuracy.
Optimizes embedding direction for your use case. Use RETRIEVAL_DOCUMENT for corpus, RETRIEVAL_QUERY for user queries, SEMANTIC_SIMILARITY for pair comparison.
Allowed values:
Truncates vector length; 768 balances quality and storage. Use 256-512 for speed-sensitive pipelines.
Optional image to embed into the same vector space as text (URL or base64). PNG/JPEG; up to 6 per request via the `images` array. Combined with `input` text into one aggregated vector.
Optional audio file to embed (URL or base64). MP3/WAV, up to 180 seconds.
Optional video file to embed (URL or base64). MP4/MOV, up to 120 seconds.
Optional PDF file to embed (URL or base64). 1 file, up to 6 pages.
To keep track of your credit usage, you can inspect the response headers of each API call. The x-remaining-credits property will indicate the number of remaining credits in your account. Ensure you monitor this value to avoid any disruptions in your API usage.
Gemini Embedding 2 is Google's state-of-the-art text embedding model, built to convert natural language into dense numerical vectors that capture semantic meaning. With the top MTEB score of 68.16 — outperforming OpenAI text-embedding-3-large (64.6) and Cohere embed-v4 (65.2) — it delivers industry-leading retrieval and similarity accuracy across 100+ languages.
Via the Segmind API, you send a text string and receive a float vector ready for indexing in any vector database (Pinecone, Qdrant, Weaviate, pgvector). Eight task-specific modes let you tune the embedding direction to exactly match your use case — from document retrieval to code search to fact verification.
Retrieval-Augmented Generation (RAG): Use RETRIEVAL_DOCUMENT to embed your knowledge base and RETRIEVAL_QUERY for user questions. The asymmetric task pairing significantly improves precision over single-task embeddings.
Semantic search: Embed a product catalog, documentation site, or support knowledge base. Users get semantically relevant results even when they phrase queries differently from how the content was written.
Classification and clustering: Feed embeddings into a lightweight classifier or k-means cluster to categorize support tickets, content tags, or customer feedback without fine-tuning a full LLM.
Code search: CODE_RETRIEVAL_QUERY produces embeddings tuned for function signatures, docstrings, and code snippets — ideal for developer tools and IDE assistants.
Multilingual pipelines: With 69.9 MTEB multilingual score, a single index handles queries and documents in different languages without separate per-language models.
RETRIEVAL_DOCUMENT and query with RETRIEVAL_QUERY. Mixing types degrades recall.Q: What is the difference between RETRIEVAL_QUERY and RETRIEVAL_DOCUMENT? RETRIEVAL_QUERY embeds a user's question or search query; RETRIEVAL_DOCUMENT embeds the passages or documents in your index. Always use them as a matched pair — this asymmetric approach is how the model is optimised and produces the best recall.
Q: Can I mix task types when comparing vectors? No. Cosine similarity is only meaningful between vectors produced with the same task type.
Q: How does output_dimensionality work? The model produces a full-length vector and then truncates it to your specified size. A value of 768 is the recommended default. Smaller values (256, 512) reduce storage and query latency but may slightly lower retrieval accuracy.
Q: Is Gemini Embedding 2 better than OpenAI text-embedding-3-large? On the MTEB leaderboard, Gemini Embedding 2 scores 68.16 vs. 64.6 for text-embedding-3-large. The quality gap is meaningful for multilingual workloads and code retrieval.
Q: What vector databases work with Gemini Embedding 2 embeddings? Any database that accepts float arrays — Pinecone, Qdrant, Weaviate, Chroma, pgvector, Redis, Milvus. Set index dimensions to match your output_dimensionality setting (default: 768).
Q: Does the model support batch input? The Segmind API accepts a single string per request. For batch workloads, send concurrent requests or loop through your corpus sequentially.