█

AI/TLDR

Buy me a coffee
Buy me a coffee

Granite Embedding

IBM's open Granite text embedding models for retrieval and search

Embedding Models & InferenceOpen source
Language
Python
License
Apache-2.0
$pip install sentence_transformers
IN SHORT

What is Granite Embedding?

Granite Embedding is a family of open text embedding models from IBM. The models use a bi-encoder (sentence-transformer) architecture to turn text such as queries, passages, and documents into fixed-length vectors, which you can compare with cosine similarity to find relevant matches. It sits in the Embedding Models & Inference category of the Retrieval & Knowledge (RAG) tools and is open-source, written in Python and licensed Apache-2.0.

Overview

Granite Embedding is a family of open text embedding models from IBM. The models use a bi-encoder (sentence-transformer) architecture to turn text such as queries, passages, and documents into fixed-length vectors, which you can compare with cosine similarity to find relevant matches.

The lineup covers different sizes and languages. English models come in 47M and 149M parameter versions, while multilingual models (97M and 311M parameters) support 200+ languages. The smaller models output 384-dimensional vectors and the larger ones 768, so you can trade off speed, memory, and accuracy.

It is aimed at developers building retrieval, semantic search, and RAG systems who want models trained on permissibly licensed data and released under Apache 2.0 for both research and commercial use. As an embedding model family, it fits the retrieval step that sits in front of a vector database or reranker.

What it does

  • Bi-encoder sentence-transformer models that produce fixed-length vectors for queries, passages, and documents
  • English models at 47M and 149M parameters, plus multilingual models at 97M and 311M parameters
  • Multilingual models cover 200+ languages with enhanced retrieval for 52, and a 32,768-token context window on the 97M model
  • Output embedding sizes of 384 (small models) or 768 (larger models), with Matryoshka dimension support on the 311m multilingual model
  • Apache 2.0 licensed, trained on carefully curated, permissibly licensed public datasets
  • Works directly with the Sentence Transformers and Hugging Face Transformers libraries, with optional Flash Attention 2 for faster inference

Getting started

The models load from Hugging Face and work with the Sentence Transformers library. Install it, then encode queries and passages and compare them with cosine similarity.

Install Sentence Transformers

Install the library used to load and run the model.

bashbash
pip install sentence_transformers

Encode text and compare

Load a Granite Embedding model, encode queries and passages, then compute cosine similarity. The model returns unnormalized vectors; pass normalize_embeddings=True to encode if you need normalized output.

pythonpython
from sentence_transformers import SentenceTransformer, util

model_path = "ibm-granite/granite-embedding-english-r2"
# Load the Sentence Transformer model
model = SentenceTransformer(model_path)

input_queries = [
    ' Who made the song My achy breaky heart? ',
    'summit define'
    ]

input_passages = [
    "Achy Breaky Heart is a country song written by Don Von Tress. Originally titled Don't Tell My Heart and performed by The Marcy Brothers in 1991. ",
    "Definition of summit for English Language Learners. : 1 the highest point of a mountain : the top of a mountain. : 2 the highest level. : 3 a meeting or series of meetings between the leaders of two or more governments."
    ]

# encode queries and passages
query_embeddings = model.encode(input_queries)
passage_embeddings = model.encode(input_passages)

# calculate cosine similarity
print(util.cos_sim(query_embeddings, passage_embeddings))

Optional: faster inference with Flash Attention 2

Flash Attention 2 is optional but can speed up inference.

bashbash
pip install flash_attn

Commands and code are distilled from the project's own documentation — always check the official repo for the latest.

When to use it

  • Power the retrieval step of a RAG pipeline by embedding documents and queries for a vector search
  • Build semantic search over a document or passage collection using cosine similarity
  • Match user questions to relevant passages in enterprise knowledge bases
  • Run multilingual search and retrieval across 200+ languages with the multilingual models

How Granite Embedding compares

Granite Embedding alongside other open-source embedding models & inference tools AI/TLDR tracks, ranked by GitHub stars.

ToolStarsWhat it does
Sentence Transformers★ 19.3kThe standard Python framework for loading, training, and computing embeddings with sentence and reranking models.
OpenCLIP★ 14.3kAn open implementation of CLIP for training and running image-text embedding models, with a large catalogue of pretrained checkpoints for zero-shot classification and retrieval.
PyTorch Metric Learning★ 6.3kPyTorch library of losses, miners, distances, samplers, trainers and accuracy testers for training embedding models with deep metric and self-supervised learning.
EmbeddingGemma (Gemma)★ 5.9kGoogle DeepMind's Gemma repo, home to EmbeddingGemma, a 308M multilingual embedding model small enough to run on-device for RAG and semantic search.
Text Embeddings Inference (TEI)★ 5.1kHugging Face's Rust-based server for deploying embedding, reranking, and sequence-classification models with high throughput on GPU or CPU.
text2vec★ 5kPython library for sentence embeddings and text similarity, implementing Word2Vec, BM25, Sentence-BERT, CoSENT and BGE with Chinese and multilingual models.
Infinity (Embeddings)★ 3kA high-throughput serving engine for text embeddings, rerankers, CLIP, and ColPali models, exposing an OpenAI-compatible API.
Granite Embedding★ 88IBM's open Granite text embedding models for retrieval and search