---
title: "CPU Optimized Embeddings with 🤗 Optimum Intel and fastRAG"
description: "Post-training static int8 quantization of BGE embedding models (small, base, large) with Optimum Intel, Intel Neural Compressor and IPEX gives up to 4.5x lower latency and up to 4x higher throughput on 4th-gen Xeon CPUs compared with a bf16 PyTorch baseline."
url: "https://swe.quest/articles/cpu-optimized-embeddings-with-optimum-intel-and-fastrag-e206611a492390e0"
canonical: "https://huggingface.co/blog/intel-fast-embedding"
source: "Hugging Face"
published: "2024-03-15"
difficulty: "medium"
kind: "How-to"
reading_minutes: 11
tags: ["inference","rag","performance","hardware","python"]
---

# CPU Optimized Embeddings with 🤗 Optimum Intel and fastRAG

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2024-03-15, 11 min read, How-to. Original: [https://huggingface.co/blog/intel-fast-embedding](https://huggingface.co/blog/intel-fast-embedding)

## Summary

Post-training static int8 quantization of BGE embedding models (small, base, large) with Optimum Intel, Intel Neural Compressor and IPEX gives up to 4.5x lower latency and up to 4x higher throughput on 4th-gen Xeon CPUs compared with a bf16 PyTorch baseline. Accuracy loss stays small: under 0.3% on MTEB reranking and up to 1.55% on retrieval. The guide covers calibration with a qasper subset, loading the model with IPEXModel, and the benchmark setup (ipexrun, TCMalloc, single socket). It also shows how to plug the quantized models into fastRAG's QuantizedBiEncoderRetriever and QuantizedBiEncoderRanker for RAG indexing and reranking.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Inference & serving](https://swe.quest/tags/inference.md) (AI & ML)
- [RAG & retrieval](https://swe.quest/tags/rag.md) (AI & ML)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Hardware](https://swe.quest/tags/hardware.md) (Infrastructure)
- [Python](https://swe.quest/tags/python.md) (Languages)

## Prerequisites

- text embedding models
- Hugging Face Transformers
- model quantization basics ([easy posts on Inference & serving](https://swe.quest/tags/inference.md?difficulty=easy))
- RAG pipelines ([easy posts on RAG & retrieval](https://swe.quest/tags/rag.md?difficulty=easy))

## Keywords

Optimum Intel, IPEX, Intel Neural Compressor, fastRAG, BGE, MTEB, Intel AMX, Haystack

## Related posts

- [Blazing Fast SetFit Inference with 🤗 Optimum Intel on Xeon](https://swe.quest/articles/blazing-fast-setfit-inference-with-optimum-intel-on-xeon-804c53c4c80ba1a3.md): Hugging Face · 2024-04-03 · Medium · 6 min read · Inference & serving, Performance engineering, Hardware, Python
  Post-training static int8 quantization of a SetFit model body with Optimum Intel and Intel Neural Compressor speeds up inference on Xeon CPUs by up to 7.8x in throughput with negligible accuracy loss.
- [Smaller is better: Q8-Chat, an efficient generative AI experience on Xeon](https://swe.quest/articles/smaller-is-better-q8-chat-an-efficient-generative-ai-experience-on-xeon-67e9bd0a15445b38.md): Hugging Face · 2023-05-16 · Easy · 5 min read · Inference & serving, LLMs, Hardware
  SmoothQuant enables accurate 8-bit (INT8) post-training quantization of LLMs by mathematically shifting activation outliers into the weights, which makes Transformer layers quantization-friendly.
- [Intel and Hugging Face Partner to Democratize Machine Learning Hardware Acceleration](https://swe.quest/articles/intel-and-hugging-face-partner-to-democratize-machine-learning-hardware-0de59c0019e6704c.md): Hugging Face · 2022-06-15 · Medium · 7 min read · Inference & serving, Machine learning, Performance engineering, Hardware
  Intel has joined Hugging Face's Hardware Partner Program, and the two are collaborating on Optimum Intel, an open-source library built on Intel Neural Compressor that applies quantization, pruning and distillation to Transformer models on Xeon CPUs.
- [Accelerating PyTorch Transformers with Intel Sapphire Rapids - part 2](https://swe.quest/articles/accelerating-pytorch-transformers-with-intel-sapphire-rapids-part-2-c41ef6f6c233e349.md): Hugging Face · 2023-02-06 · Medium · 6 min read · Inference & serving, Hardware, Performance engineering, Python
  Intel Sapphire Rapids CPUs with AMX instructions, combined with Hugging Face Optimum Intel running in bfloat16 with JIT compilation, cut p99 inference latency for DistilBERT, BERT and RoBERTa text classification by roughly 3x compared with vanilla Transformers on Ice Lake.
- [Introducing Optimum: The Optimization Toolkit for Transformers at Scale](https://swe.quest/articles/introducing-optimum-the-optimization-toolkit-for-transformers-at-scale-a074b17981960e1a.md): Hugging Face · 2021-09-14 · Easy · 4 min read · Inference & serving, Machine learning, Open source, Hardware
  Optimum is a new open source Hugging Face library that targets production performance for Transformer models by wrapping hardware-specific acceleration tooling built with hardware partners.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
