Word embeddings for Indic languages like Hindi are crucial for advancing Natural Language Processing (NLP) tasks such as machine translation, question answering, and information retrieval. These embeddings capture semantic properties of words, enabling more accurate and context-aware NLP applications. Given the vast number of Hindi speakers and the growing digital content in Indic languages, high-quality embeddings are essential for improving NLP performance in these languages. Customized embeddings can particularly address the unique linguistic features and resource constraints of Indic languages. The newly released Gemini Embedding model represents a significant advancement in multilingual text embeddings, leveraging Google’s powerful Gemini AI framework to deliver state-of-the-art performance across over 100 languages.
Gemini Embedding model excels in tasks such as classification, retrieval, and semantic search, offering enhanced efficiency and accuracy. By supporting larger input sizes and higher-dimensional outputs, Gemini Embedding provides richer text representations, making it highly versatile for diverse applications.
This article was published as a part of the Data Science Blogathon.
In March 2025, Google released a new experimental Gemini Embedding text model (gemini-embedding-exp-03-07) available in the Gemini API.
Developed from the Gemini model, this advanced embedding model is claimed to have inherited Gemini’s profound grasp of language and subtle contextual nuances, rendering it versatile for diverse applications. It has grabbed the top position on the MTEB Multilingual leaderboard.
Gemini Embedding represents text as dense vectors where semantically similar text inputs
are mapped to vectors near one another in the vector space. Currently it supports more than 100+
languages, and its embeddings can be used for various tasks such as retrieval and classification.
At its core, Gemini Embedding is built on a transformer architecture, initialized from the Gemini LLM. This foundation provides the model with a deep understanding of language structure and semantics. The model uses bidirectional attention mechanisms to process input sequences, allowing it to consider the full context of a word or phrase when generating embeddings.
Loss Function. The Gemini Embedding model was trained with a noise-contrastive estimation (NCE) loss with in-batch negatives. The exact loss differs slightly depending on the stage of training. In general, a training example includes a query, a positive target and (optionally) a hard negative target.
Also Read: Gemini Embedding: Generalizable Embeddings from Gemini
We compare the retrieval from Hindi Documents with the newly released state of the art Gemini Embeddings and then compare it against Jina AI Embeddings & Multilingual-e5-large embeddings. As shown in the Table below, with respect to the number of max tokens, Gemini Embeddings and Jina AI embeddings are high, enabling the models to handle long documents or intricate queries. In terms. Also as seen from the Table below, the Gemini embeddings have a higher embedding dimension that can capture more nuanced and fine-grained semantic relationships between words, enabling models to represent complex linguistic patterns and subtle distinctions in meaning.
Number of Parameters | Embedding Dimension | Max Tokens | Number of Languages | Matryoshka Embeddings | |
gemini-embedding-exp-03-07 | Unknown | 3072 | 8192 | 100 | Enables truncation to various sizes, such as 2048, 1024, 512, 256, and 128 dimensions, |
jinaai/jina-embeddings-v3 | 572M | 1024 | 8194 | 100 | Supports flexible embedding sizes (32, 64, 128, 256, 512, 768, 1024), allowing for truncating embeddings to fit your application |
multilingual-e5-large-instruct | 560M | 1024 | 514 | 94 | NA |
In the following hands on tutorial, we will compare retrieval from Hindi Documents with the newly released state of the art Gemini Embeddings and then compare it against Jina AI Embeddings & Multilingual-e5-large embeddings.
!pip install langchain-community
!pip install chromadb
We use Hindi data from a website to assess how the Gemini Embeddings perform with respect to retrieval in Hindi Language.
from langchain_community.document_loaders import WebBaseLoader
loader = WebBaseLoader("https://ckbirlahospitals.com/rbh/blog/pregnancy-early-symptoms-in-hindi")
data = loader.load()
The code below uses the RecursiveCharacterTextSplitter to split large text documents into smaller chunks of 500 characters each, with no overlap. It then applies this splitting to the data variable and stores the results in all_splits. We use only 10 of the splits because of the rate limits in Gemini Embedding API.
from langchain_text_splitters import RecursiveCharacterTextSplitter
text_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=0)
all_splits = text_splitter.split_documents(data)
all_splits = all_splits[:10]
We first create a class “GeminiEmbeddingFunction” that helps in querying the Gemini Embedding API and returns the values of the embeddings for the input query. We then create a function “create_chroma_db” for creating a collection in ChromaDB that will store the data along with the embeddings.
import chromadb
from chromadb import Documents, EmbeddingFunction, Embeddings
class GeminiEmbeddingFunction(EmbeddingFunction):
def __call__(self, input: Documents) -> Embeddings:
title = "Custom query"
return client.models.embed_content(
model="gemini-embedding-exp-03-07",
contents=input).embeddings[0].values
def create_chroma_db(documents, name):
chroma_client = chromadb.Client()
db = chroma_client.create_collection(name=name, embedding_function=GeminiEmbeddingFunction())
for i, d in enumerate(documents):
db.add(
documents=d.page_content,
ids=str(i)
)
return db
db = create_chroma_db(all_splits, "datab")
def get_relevant_passage(query, db):
passage = db.query(query_texts=[query], n_results=1)['documents'][0][0]
return passage
passage = get_relevant_passage("आपको प्रेगनेंसी टेस्ट कब करवाना चाहिए?", db)
print(passage)
The code below defines a custom embedding function using a Hugging Face transformer model and a method for processing text inputs to generate embeddings.
from transformers import AutoTokenizer, AutoModel
from chromadb import EmbeddingFunction
tokenizer = AutoTokenizer.from_pretrained('jinaai/jina-embeddings-v3')
model = AutoModel.from_pretrained('jinaai/jina-embeddings-v3')
# the model returns many hidden states per document so we must aggregate them
def average_pool(last_hidden_states, attention_mask):
last_hidden = last_hidden_states.masked_fill(~attention_mask[...,None].bool(), 0.0)
return last_hidden.sum(dim=1) / attention_mask.sum(dim=1)[...,None]
class CustomHuggingFace(EmbeddingFunction):
def __call__(self, texts):
queries = [f'query: {text}' for text in texts]
batch_dict = tokenizer(texts, max_length=512, padding=True, truncation=True, return_tensors='pt')
outputs = model(**batch_dict)
embeddings = average_pool(outputs.last_hidden_state, batch_dict['attention_mask'])
return embeddings.tolist()
Querying
def get_relevant_passage(query, db):
passage = db.query(query_texts=[query], n_results=1)['documents'][0][0]
return passage
passage = get_relevant_passage("आपको प्रेगनेंसी टेस्ट कब करवाना चाहिए?", db)
print(passage)
For selecting the Multilingual-e5-large embeddings, we can just replace the tokenizer and model as “intfloat/multilingual-e5-large-instruct”
Question Number | Query | Gemini Embeddings | jinaai/jina-embeddings-v3 | intfloat/multilingual-e5-large-instruct |
1 | आपको प्रेगनेंसी टेस्ट कब करवाना चाहिए? | यदि आप प्रेगनेंसी के शुरुआती लक्षणों (early symptoms of pregnancy) के बारे में विस्तार से जानना चाहते हैं, तो यह ब्लॉग आपके लिए ख़ास है। आपको प्रेगनेंसी टेस्ट कब करवाना चाहिए? – WRONG |
यदि आप प्रेगनेंसी के शुरुआती लक्षणों (early symptoms of pregnancy) के बारे में विस्तार से जानना चाहते हैं, तो यह ब्लॉग आपके लिए ख़ास है।\nआपको प्रेगनेंसी टेस्ट कब करवाना चाहिए? – WRONG | यदि आप प्रेगनेंसी के शुरुआती लक्षणों (early symptoms of pregnancy) के बारे में विस्तार से जानना चाहते हैं, तो यह ब्लॉग आपके लिए ख़ास है। आपको प्रेगनेंसी टेस्ट कब करवाना चाहिए? – WRONG |
2 | Pregnancy के kuch symptoms क्या होते हैं? | प्रेगनेंसी के शुरुआती लक्षण क्या है? प्रेगनेंसी के दौरान महिलाओं के शरीर में कई हार्मोनल बदलाव आते हैं। प्रेगनेंसी के शुरुआती लक्षणों में जी मचलना, उल्टी आना, बार-बार पेशाब आना, और थकान जैसे लक्षण शामिल है, जिसके बारे में हम इस ब्लॉग में बात भी करने वाले हैं। – CORRECT |
प्रेगनेंसी के संकेत: शुरुआती लक्षणों की पूरी जानकारी! Home Quick Enquiry Patient LoginCall Us: 08062136530 Emergency No: 07340054470 Open main menuServicesPatients & VisitorsInternational Patients About Us Book an Appointment Call BackWhatsApp प्रेगनेंसी के शुरूआती लक्षण के बारे में जाने।Obstetrics and Gynaecology |by Dr. C. P. Dadhich| Published on 06/02/2025Table of Contentsआपको प्रेगनेंसी टेस्ट कब करवाना चाहिए?प्रेगनेंसी के शुरुआती लक्षण क्या है?प्रेगनेंसी के शुरुआती लक्षणगर्भावस्था के – WRONG | प्रेगनेंसी के शुरुआती लक्षण क्या है? प्रेगनेंसी के दौरान महिलाओं के शरीर में कई हार्मोनल बदलाव आते हैं। प्रेगनेंसी के शुरुआती लक्षणों में जी मचलना, उल्टी आना, बार-बार पेशाब आना, और थकान जैसे लक्षण शामिल है, जिसके बारे में हम इस ब्लॉग में बात भी करने वाले हैं। – CORRECT |
3 | गर्भावस्था के दौरान एंटीबायोटिक दवा लेने से कब बचना चाहिए? | प्रेगनेंसी के पहले कुछ दिनों में अंडा स्पर्म से फर्टिलाइज होता है, जिसके कारण ब्लीडिंग और पेट में ऐंठन जैसे लक्षण दिखते हैं। इस दौरान स्वस्थ प्रेगनेंसी के लिए महिलाओं को सलाह दी जाती है कि वह एंटीबायोटिक दवा लेने से बचें, क्योंकि इससे मां और बच्चे दोनों को ही खतरा हो सकता है। प्रेगनेंसी के शुरुआती लक्षण हमेशा पीरियड का मिस होना या उल्टी होना गर्भधारण के शुरुआती लक्षण नहीं होते हैं। इसके अतिरिक्त अन्य लक्षण भी हो सकते हैं, जिन पर ध्यान देना बहुत ज्यादा जरूरी होता है जैसे कि – CORRECT |
प्रेगनेंसी के पहले कुछ दिनों में अंडा स्पर्म से फर्टिलाइज होता है, जिसके कारण ब्लीडिंग और पेट में ऐंठन जैसे लक्षण दिखते हैं। इस दौरान स्वस्थ प्रेगनेंसी के लिए महिलाओं को सलाह दी जाती है कि वह एंटीबायोटिक दवा लेने से बचें, क्योंकि इससे मां और बच्चे दोनों को ही खतरा हो सकता है। प्रेगनेंसी के शुरुआती लक्षण हमेशा पीरियड का मिस होना या उल्टी होना गर्भधारण के शुरुआती लक्षण नहीं होते हैं। इसके अतिरिक्त अन्य लक्षण भी हो सकते हैं, जिन पर ध्यान देना बहुत ज्यादा जरूरी होता है जैसे कि – CORRECT |
जिनके बारे में हर महिला को पता होना चाहिए। गर्भधारण के संबंध में किसी भी प्रकार की समस्या के लिए हम आपको सलाह देंगे कि आप हमारे स्त्री रोग विशेषज्ञ से संपर्क करें और हर प्रकार की जटिलताओं को दूर भगाएं। – WRONG |
4 | कब गर्भावस्था में एंटीबायोटिक दवा लेने से बचाया जाए? | प्रेगनेंसी के पहले कुछ दिनों में अंडा स्पर्म से फर्टिलाइज होता है, जिसके कारण ब्लीडिंग और पेट में ऐंठन जैसे लक्षण दिखते हैं। इस दौरान स्वस्थ प्रेगनेंसी के लिए महिलाओं को सलाह दी जाती है कि वह एंटीबायोटिक दवा लेने से बचें, क्योंकि इससे मां और बच्चे दोनों को ही खतरा हो सकता है। प्रेगनेंसी के शुरुआती लक्षण हमेशा पीरियड का मिस होना या उल्टी होना गर्भधारण के शुरुआती लक्षण नहीं होते हैं। इसके अतिरिक्त अन्य लक्षण भी हो सकते हैं, जिन पर ध्यान देना बहुत ज्यादा जरूरी होता है जैसे कि – CORRECT |
प्रेगनेंसी के पहले कुछ दिनों में अंडा स्पर्म से फर्टिलाइज होता है, जिसके कारण ब्लीडिंग और पेट में ऐंठन जैसे लक्षण दिखते हैं। इस दौरान स्वस्थ प्रेगनेंसी के लिए महिलाओं को सलाह दी जाती है कि वह एंटीबायोटिक दवा लेने से बचें, क्योंकि इससे मां और बच्चे दोनों को ही खतरा हो सकता है। प्रेगनेंसी के शुरुआती लक्षण हमेशा पीरियड का मिस होना या उल्टी होना गर्भधारण के शुरुआती लक्षण नहीं होते हैं। इसके अतिरिक्त अन्य लक्षण भी हो सकते हैं, जिन पर ध्यान देना बहुत ज्यादा जरूरी होता है जैसे कि – CORRECT |
जिनके बारे में हर महिला को पता होना चाहिए। गर्भधारण के संबंध में किसी भी प्रकार की समस्या के लिए हम आपको सलाह देंगे कि आप हमारे स्त्री रोग विशेषज्ञ से संपर्क करें और हर प्रकार की जटिलताओं को दूर भगाएं। – WRONG |
5 | गर्भधारण का सबसे पहला सामान्य लक्षण क्या है? | पीरियड का मिस होना: यह प्रेगनेंसी का सबसे पहला और सामान्य लक्षण है। सिर्फ इस लक्षण के आधार पर प्रेगनेंसी की पुष्टि करना बिल्कुल भी सही नहीं होता है। हालांकि जब पीरियड एक हफ्ते या उससे अधिक समय तक नहीं आते हैं, तो इसके बाद प्रेगनेंसी टेस्ट कराने की सलाह दी जाती है। स्तनों में बदलाव आना: प्रेगनेंसी में स्तन में सूजन, कोमलता या इसके रंग में बदलाव आ जाता है। मुख्य रूप से निप्पल (एरिओला) के आकार और रंग में बदलाव देखने को मिलता है। – CORRECT |
को देखते हुए प्रेगनेंसी को कैसे कंफर्म करें?प्रेगनेंसी के पहले महीने में कैसे ध्यान रखें?गर्भावस्था की जांच कैसे करें?गर्भावस्था के दौरान किसी को कैसे बैठना चाहिए?क्या गर्भावस्था के दौरान किसी को सेक्स करना चाहिए?गर्भावस्था के दौरान किसी को कौन सा फल खाना चाहिए?प्रेगनेंसी के दौरान कितना पानी पीना चाहिए?मां बनने का सुख इस संसार का सबसे बड़ा सुख है। प्रेगनेंसी के दौरान एक महिला के शरीर में अनेक शारीरिक एवं मानसिक बदलाव आते हैं। आप इन्ही बदलावों को प्रेगनेंसी के शुरुआती लक्षण के नाम से जानते हैं, – WRONG | प्रेगनेंसी के शुरुआती लक्षण क्या है? प्रेगनेंसी के दौरान महिलाओं के शरीर में कई हार्मोनल बदलाव आते हैं। प्रेगनेंसी के शुरुआती लक्षणों में जी मचलना, उल्टी आना, बार-बार पेशाब आना, और थकान जैसे लक्षण शामिल है, जिसके बारे में हम इस ब्लॉग में बात भी करने वाले हैं। – CORRECT |
6 | गर्भधारण के पहले संकेत क्या होते हैं? | प्रेगनेंसी के संकेत: शुरुआती लक्षणों की पूरी जानकारी! Home Quick Enquiry Patient LoginCall Us: 08062136530 Emergency No: 07340054470 Open main menuServicesPatients & VisitorsInternational Patients About Us Book an Appointment Call BackWhatsApp प्रेगनेंसी के शुरूआती लक्षण के बारे में जाने।Obstetrics and Gynaecology |by Dr. C. P. Dadhich| Published on 06/02/2025Table of Contentsआपको प्रेगनेंसी टेस्ट कब करवाना चाहिए?प्रेगनेंसी के शुरुआती लक्षण क्या है?प्रेगनेंसी के शुरुआती लक्षणगर्भावस्था के – WRONG | को देखते हुए प्रेगनेंसी को कैसे कंफर्म करें?प्रेगनेंसी के पहले महीने में कैसे ध्यान रखें?गर्भावस्था की जांच कैसे करें?गर्भावस्था के दौरान किसी को कैसे बैठना चाहिए?क्या गर्भावस्था के दौरान किसी को सेक्स करना चाहिए?गर्भावस्था के दौरान किसी को कौन सा फल खाना चाहिए?प्रेगनेंसी के दौरान कितना पानी पीना चाहिए?मां बनने का सुख इस संसार का सबसे बड़ा सुख है। प्रेगनेंसी के दौरान एक महिला के शरीर में अनेक शारीरिक एवं मानसिक बदलाव आते हैं। आप इन्ही बदलावों को प्रेगनेंसी के शुरुआती लक्षण के नाम से जानते हैं, – WRONG | प्रेगनेंसी के शुरुआती लक्षण क्या है? प्रेगनेंसी के दौरान महिलाओं के शरीर में कई हार्मोनल बदलाव आते हैं। प्रेगनेंसी के शुरुआती लक्षणों में जी मचलना, उल्टी आना, बार-बार पेशाब आना, और थकान जैसे लक्षण शामिल है, जिसके बारे में हम इस ब्लॉग में बात भी करने वाले हैं। –CORRECT |
7 | गर्भावस्था की पुष्टि के लिए कौन से हार्मोन का पता लगाना होता है? | प्रेगनेंसी टेस्ट के लिए सबसे अच्छा समय कम से कम एक बार पीरियड का मिस हो जाने के 7 दिन बाद है। आप घर पर ही होम प्रेगनेंसी टेस्ट किट से hCG के स्तर का पता लगा सकते हैं। प्रेगनेंसी के दौरान इस हार्मोन के स्तर में अच्छी खासी वृद्धि देखी जाती है। यहां आपको एक बात का ध्यान रखना होगा कि बहुत जल्दी टेस्ट करने से भी गलत परिणाम आ सकते हैं, इसलिए यदि आपके पीरियड देर से आ रहे हैं और टेस्ट नेगेटिव आता है, तो आपको सलाह दी जाती है कि कम से कम 3 दिन और रुकें और फिर से टेस्ट करें। – CORRECT | इसे करने का भी एक सही तरीका होता है, जो आप टेस्ट किट के निर्देशन वाली पर्ची पर भी देख सकते हैं। सटीक परिणामों के लिए आपको सुबह के सबसे पहले पेशाब का इस्तेमाल करना होता है, क्योंकि इसी दौरान hCG हार्मोन के सही स्तर को मापा जा सकता है। इसके अतिरिक्त यदि आपको प्रेगनेंसी के शुरुआती लक्षणों का अनुभव होता है, और टेस्ट का परिणाम भी नेगेटिव आ रहा है, तो तुरंत डॉक्टर के पास जाकर ब्लड टेस्ट कराएं। किसी भी प्रकार के कन्फ्यूजन की स्थिति में डॉक्टरी सलाह बहुत ज्यादा अनिवार्य है। – CORRECT | प्रेगनेंसी के शुरुआती लक्षण क्या है? प्रेगनेंसी के दौरान महिलाओं के शरीर में कई हार्मोनल बदलाव आते हैं। प्रेगनेंसी के शुरुआती लक्षणों में जी मचलना, उल्टी आना, बार-बार पेशाब आना, और थकान जैसे लक्षण शामिल है, जिसके बारे में हम इस ब्लॉग में बात भी करने वाले हैं। – WRONG |
As seen from the above Hindi outputs, with Gemini Embeddings, we get 5 correct outputs from the 7 queries, while Jina AI embeddings and Multilingual-e5-large, we get 3 correct responses only.
This shows that Gemini Embeddings, as reflective on the MTEB benchmark, can perform well and better than other embeddings models for multilingual languages as well like Hindi.
In conclusion, Gemini Embeddings represent a significant advancement in multilingual NLP, particularly for Indic languages like Hindi. With its robust multilingual capabilities, support for large input sizes, and superior performance on benchmarks like MTEB, Gemini excels in tasks such as retrieval, classification, and semantic search. As demonstrated through hands-on comparisons, Gemini outperforms other models, offering enhanced accuracy and efficiency, making it a valuable tool for advancing NLP in diverse languages.
The media shown in this article is not owned by Analytics Vidhya and is used at the Author’s discretion.
Ans. The Gemini Embedding model, built on Google’s Gemini AI, offers top-tier multilingual text embedding for 100+ languages, including Hindi.
Ans. Gemini Embedding excels in multilingual support, handles 8,000 tokens, and outputs 3,072 dimensions, ensuring efficiency in classification, retrieval, and semantic search.
Ans. Gemini Embedding performs well in both high-resource languages like English and low-resource ones like Assamese and Macedonian. It ranks top on the MTEB Multilingual leaderboard, showcasing its strong multilingual capabilities.
Ans. The model, initialized from the Gemini LLM, uses a transformer architecture with bidirectional attention to generate high-quality text embeddings that capture context and meaning.
Ans. Gemini Embedding was trained using noise-contrastive estimation (NCE) loss with in-batch negatives. It underwent two training stages: pre-finetuning on a large dataset and fine-tuning on task-specific datasets for better NLP performance.