Model Summary:
Granite-Embedding-30m-Sparse is a 30M parameter sparse biencoder embedding model from the Granite Experimental suite that can be used to generate high quality text embeddings. This model produces variable length bag-of-word like dictionary, containing expansions of sentence tokens and their corresponding weights and is trained using a combination of open source relevance-pair datasets with permissive, enterprise-friendly license, and IBM collected and generated datasets. While maintaining competitive scores on academic benchmarks such as BEIR, this model also performs well on many enterprise use cases. This model is developed using retrieval oriented pretraining, contrastive finetuning and knowledge distillation for improved performance.
Intended use:
The model is designed to produce variable length bag-of-word like dictionary, containing expansions of sentence tokens and their corresponding weights, for a given text, which can be used for text similarity, retrieval, and search applications.
Usage with Milvus:
The model is compatible with Milvus Vector DB and is very easy to use:
First, install the pymilvus library
pip install pymilvus[model]
The model can then be used to encode pairs of text and find the similarity between their representations
python
12from pymilvus import model
3from pymilvus import MilvusClient, DataType
45client = MilvusClient("./milvus_demo.db")67client.drop_collection(collection_name="my_sparse_collection")89schema = client.create_schema(10 auto_id=True,11 enable_dynamic_fields=True,12)1314schema.add_field(field_name="pk", datatype=DataType.VARCHAR, is_primary=True, max_length=100)15schema.add_field(field_name="id", datatype=DataType.VARCHAR, is_primary=False, max_length=100)16schema.add_field(field_name="embeddings", datatype=DataType.SPARSE_FLOAT_VECTOR)1718index_params = client.prepare_index_params()1920index_params.add_index(field_name="embeddings",21 index_name="sparse_inverted_index",22 index_type="SPARSE_INVERTED_INDEX",23 metric_type="IP",24 params={"drop_ratio_build":0.2})25client.create_collection(26 collection_name="my_sparse_collection",27 schema=schema,28 index_params=index_params
29)3031embeddings_model = model.sparse.SpladeEmbeddingFunction(32 model_name="ibm-granite/granite-embedding-30m-sparse",33 device="cpu",34 batch_size=2,35 k_tokens_query=50,36 k_tokens_document=19237)3839# Prepare documents to be ingested40docs =[41"Artificial intelligence was founded as an academic discipline in 1956.",42"Alan Turing was the first person to conduct substantial research in AI.",43"Born in Maida Vale, London, Turing was raised in southern England.",44]4546# SpladeEmbeddingFunction.encode_documents returns sparse matrix or sparse array depending47# on the milvus-model version. reshape(1,-1) ensures the format is correct for ingestion.48doc_vector =[{"embeddings": doc_emb.reshape(1,-1),"id":f"item_{i}"}for i, doc_emb inenumerate(embeddings_model.encode_documents(docs))]495051client.insert(52 collection_name="my_sparse_collection",53 data=doc_vector
54)5556# Prepare search parameters57search_params ={58"params":{"drop_ratio_search":0.2},# Additional optional search parameters59}6061# Prepare the query vector6263queries =[64"When was artificial intelligence founded",65"Where was Turing born?"66]67query_vector = embeddings_model.encode_documents(queries)6869res = client.search(70 collection_name="my_sparse_collection",71 data=query_vector,72 limit=1,#top k documents to return73 output_fields=["id"],74 search_params=search_params,75)7677for r in res:78print(r)79
Usage with Sentence Transformers:
First install the Sentence Transformers library:
pip install -U sentence-transformers
Then you can load this model and run inference.
python
12from sentence_transformers import SparseEncoder
34# Download from the 🤗 Hub5model = SparseEncoder("ibm-granite/granite-embedding-30m-sparse")67# Run inference8docs =[9"Artificial intelligence was founded as an academic discipline in 1956.",10"Alan Turing was the first person to conduct substantial research in AI.",11"Born in Maida Vale, London, Turing was raised in southern England.",12]13docs_embeddings = model.encode_document(docs, max_active_dims=192)14print(docs_embeddings.shape)15# [3, 50265]1617queries =["When was artificial intelligence founded","Where was Turing born?"]18queries_embeddings = model.encode_query(queries, max_active_dims=50)19print(queries_embeddings.shape)20# [2, 50265]2122# Get the similarity scores for the embeddings23similarities = model.similarity(queries_embeddings, docs_embeddings)24print(similarities.shape)25# [2, 3]2627for i, query inenumerate(queries):28 best_doc_index = similarities[i].argmax().item()2930print(f"Query: {query}")31print(f"Best doc associate: Similarity: {similarities[i][best_doc_index]:.4f}, Doc: {docs[best_doc_index]}")32 intersection = model.intersection(queries_embeddings[i], docs_embeddings[best_doc_index])33 decoded_intersection = model.decode(intersection, top_k=10)34print("Top 10 tokens influencing the similarity:")35for token, score in decoded_intersection:36print(f"Token: {token}, Score: {score:.4f}")3738# Query: When was artificial intelligence founded39# Best doc associate: Similarity: 12.3641, Doc: Artificial intelligence was founded as an academic discipline in 1956.40# Top 10 tokens influencing the similarity:41# Token: ĠAI, Score: 2.759142# Token: Ġintelligence, Score: 2.297143# Token: Ġartificial, Score: 1.765444# Token: Ġfounded, Score: 1.325445# Token: Ġinvention, Score: 0.980846# Token: Ġlearning, Score: 0.484747# Token: Ġcomputer, Score: 0.478948# Token: Ġrobot, Score: 0.346649# Token: Ġestablishment, Score: 0.337150# Token: Ġscientific, Score: 0.280451# Query: Where was Turing born?52# Best doc associate: Similarity: 17.1359, Doc: Born in Maida Vale, London, Turing was raised in southern England.53# Top 10 tokens influencing the similarity:54# Token: uring, Score: 2.976155# Token: ĠTuring, Score: 2.454456# Token: Ġborn, Score: 2.431457# Token: ing, Score: 1.776058# Token: ure, Score: 1.762659# Token: Ġcomput, Score: 1.335660# Token: Ġraised, Score: 1.328561# Token: able, Score: 1.194062# Token: Ġphilosopher, Score: 0.411863# Token: Ġmachine, Score: 0.397764
Evaluation:
Granite-Embedding-30m-Sparse is competive in performance to the naver/splade-v3-distilbert despite being half the parameter size. We also compare the sparse model with similar sized dense embedding counterpart ibm-granite/granite-embedding-30m-english. The performance of the models on MTEB Retrieval (i.e., BEIR) is reported below.
To maintain consistency with results reported by naver/splade-v3-distilbert, we do not include CQADupstack and MS-MARCO in the table below.
Model
Paramters (M)
Vocab Size
BEIR Retrieval (13)
naver/splade-v3-distilbert
67
30522
50.0
granite-embedding-30m-english
30
50265
50.6
granite-embedding-30m-sparse
30
50265
50.8
Model Architecture:
Granite-Embedding-30m-Sparse is based on an encoder-only RoBERTa like transformer architecture, trained internally at IBM Research.
Model
granite-embedding-30m-sparse
Embedding size
384
Number of layers
6
Number of attention heads
12
Intermediate size
1536
Activation Function
GeLU
Vocabulary Size
50265
Max. Sequence Length
512
# Parameters
30M
Training Data:
Overall, the training data consists of four key sources: (1) unsupervised title-body paired data scraped from the web, (2) publicly available paired with permissive, enterprise-friendly license, (3) IBM-internal paired data targetting specific technical domains, and (4) IBM-generated synthetic data. The data is listed below:
Notably, we do not use the popular MS-MARCO retrieval dataset in our training corpus due to its non-commercial license.
Infrastructure:
We train Granite Embedding Models using IBM's computing cluster, Cognitive Compute Cluster, which is outfitted with NVIDIA A100 80gb GPUs. This cluster provides a scalable and efficient infrastructure for training our models over multiple GPUs.
Ethical Considerations and Limitations:
The data used to train the base language model was filtered to remove text containing hate, abuse, and profanity. Granite-Embedding-30m-Sparse is trained only for English texts, and has a context length of 512 tokens (longer texts will be truncated to this size).
@misc{awasthy2025graniteembeddingmodels,
title={Granite Embedding Models},
author={Parul Awasthy and Aashka Trivedi and Yulong Li and Mihaela Bornea and David Cox and Abraham Daniels and Martin Franz and Gabe Goodhart and Bhavani Iyer and Vishwajeet Kumar and Luis Lastras and Scott McCarley and Rudra Murthy and Vignesh P and Sara Rosenthal and Salim Roukos and Jaydeep Sen and Sukriti Sharma and Avirup Sil and Kate Soule and Arafat Sultan and Radu Florian},
year={2025},
eprint={2502.20204},
archivePrefix={arXiv},
primaryClass={cs.IR},
url={https://arxiv.org/abs/2502.20204},
}