Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 2

Comparing Embedding Models: Performance, Cost, and Suitability

Recommended resources

Hello! Let's continue our journey into building a production-grade RAG system.

In our last lesson, we demystified the process of creating embeddings, exploring how transformer models use self-attention to convert text into context-aware dense vectors. You now understand the mechanics behind how an embedding is made.

Today, we address the next logical and critical engineering question: Which embedding model should I use? As you've noted, moving from a script to a system means understanding the "why" behind your choices. The selection of an embedding model is one of the most impactful decisions you'll make, with direct consequences for your RAG system's performance, cost, and architecture.

This lesson is designed to equip you with a framework to compare popular embedding models, such as those from OpenAI and open-source alternatives like Sentence Transformers. We will evaluate them across three crucial dimensions: performance, cost, and domain suitability.

1. The Key Dimensions for Comparison

Choosing an embedding model isn't about finding the "best" one in a vacuum; it's about finding the best one for your specific use case. This involves a trade-off between several factors. Let's break them down.

a) Performance (Accuracy)

How do we quantify a model's ability to capture meaning? Fortunately, the NLP community has developed standardized benchmarks. The most important one for our purposes is the Massive Text Embedding Benchmark (MTEB).

MTEB evaluates models on a variety of tasks (e.g., classification, clustering, retrieval). For a RAG system, the most relevant task is Retrieval. The MTEB leaderboard, hosted on Hugging Face, ranks models based on their performance on various retrieval datasets.

To get a feel for the landscape of embedding models and the idea of benchmarks, the following video provides an excellent introduction. It pits OpenAI's models against open-source alternatives and introduces the key considerations.

$0 Embeddings (OpenAI vs. free & open source)

This video, '$0 Embeddings', provides a fantastic overview of the trade-offs between paid API-based models like OpenAI's and free, open-source alternatives. It will introduce you to the MTEB leaderboard, which is the central tool for our analysis.

Please watch the segment from 09:41 to 28:31. As you watch, focus on these key points: The different categories of models (general-purpose vs. specialized for tasks like search). The detailed walkthrough of the MTEB leaderboard and its columns (dimensions, sequence length, task scores). How the speaker uses the leaderboard to analyze and select models based on different criteria.

As you saw, the MTEB leaderboard is an indispensable tool. When we talk about "performance," we are often referring to a model's average score on the relevant MTEB retrieval tasks. A key metric used is NDCG@10 (Normalized Discounted Cumulative Gain at 10), which measures the quality of the top 10 retrieved results. A higher score is better. We'll delve deeper into this metric in a future lesson on evaluation.

b) Cost

Cost is more than just a price tag. It encompasses both direct and indirect expenses.

  • API-based Models (e.g., OpenAI, Cohere):

    • Direct Cost: You pay per unit of usage, typically per 1,000 or 1 million tokens processed. This is predictable and scales with use.
    • Indirect Cost: Minimal. There is no infrastructure to manage, saving engineering time.
  • Open-Source Models (e.g., BGE, all-MiniLM from Hugging Face):

    • Direct Cost: The models themselves are free to download.
    • Indirect Cost: This is the hidden cost. You must account for:
      • Compute: Running the model requires CPU or GPU resources, especially for high-throughput applications. This translates to server costs (e.g., an AWS EC2 instance).
      • Storage: Storing the embeddings in a vector database has associated costs.
      • Engineering Overhead: Your team needs to set up, maintain, and scale the infrastructure to host the model.

This Ailog RAG article provides a concise cost analysis for processing 1 million documents with different models. It's a great real-world illustration of these trade-offs.

MTEB Scores & Leaderboard (Cohere, OpenAI, BGE) | Ailog RAG

The article 'Best Embedding Models 2025' contains a useful table that breaks down the estimated costs for several popular models.

Read the section titled 'Cost Analysis (1M documents)'. Note how it separates embedding costs, storage, and inference, and compare the total cost of ownership between a self-hosted model like all-MiniLM and an API-based one like OpenAI-3-large.

c) Domain Suitability and Other Architectural Factors

Beyond raw performance and cost, several other factors influence your choice.

  • Hosting and Privacy: API-based models require sending your data to a third party. For sensitive internal documents (legal, financial, medical), this may be a non-starter. Self-hosting an open-source model ensures your data never leaves your environment.
  • Vector Dimensions: The size of the embedding vector (e.g., 384 for all-MiniLM-L6-v2 vs. 3072 for text-embedding-3-large).
    • Higher dimensions can capture more nuance but lead to larger storage requirements, slower similarity search (without indexing), and higher computational cost.
    • Lower dimensions are faster, cheaper to store and query, but may sacrifice some accuracy.
  • Sequence Length: The maximum number of tokens a model can accept as input. This influences your chunking strategy. If a model has a small sequence length (e.g., 512 tokens), you must ensure your document chunks are smaller than this limit.
  • Licensing: Open-source models come with licenses (e.g., Apache 2.0, MIT). It's crucial to check that the license permits your intended use (e.g., commercial application).

2. A Tale of Two Philosophies: OpenAI vs. Hugging Face

This decision often boils down to a choice between two ecosystems, each with its own philosophy. This table provides a great head-to-head comparison.

OpenAI vs HuggingFace: Feature Comparison
This table provides a feature comparison between OpenAI and HuggingFace for embedding models. It highlights the key trade-offs across dimensions like hosting (Cloud vs. Local), speed, cost, accuracy, customization, and privacy. OpenAI excels in ease-of-use and general accuracy, while HuggingFace offers control, privacy, and cost-effectiveness through self-hosting.

3. A Decision Framework

Now, let's synthesize this into a practical framework for choosing your model.

  1. Define Your Constraints:

    • Privacy: Is self-hosting mandatory? If yes, you are limited to open-source models.
    • Budget: What are your cost constraints for both initial embedding and ongoing inference?
    • Performance Requirement: How good does the retrieval need to be? Is "good enough" acceptable for an MVP, or do you need state-of-the-art from day one?
  2. Consult the MTEB Leaderboard:

    • Go to the Hugging Face MTEB Leaderboard.
    • Filter by Task Category: Retrieval. This is the most important view for RAG.
    • Observe the top performers. Note their average scores, dimensions, and whether they are proprietary (API) or open-source. You'll often see that top open-source models (like BGE-M3 or others) are highly competitive with, and sometimes even outperform, older proprietary models.
  3. Make an Initial Selection based on Use Case:

The following video provides a concise summary and clear recommendations based on a similar head-to-head experiment.

OpenAI vs. Open-source Embedding Model Showdown

The video 'OpenAI vs. Open-source Embedding Model Showdown' offers clear, actionable recommendations based on an empirical test.

Watch the final recommendations from 08:58 to 10:02. The speaker gives clear advice on when to choose OpenAI versus when to opt for an open-source model.

Here's a summary of common heuristics, which echoes the video's conclusion:

  • For rapid prototyping, MVPs, or when ease-of-use is paramount: Start with an API-based model like OpenAI's text-embedding-3-small. It's cost-effective and provides strong performance.
  • For production systems where quality is critical and budget allows: Use a top-tier API model like OpenAI's text-embedding-3-large or Cohere's embed-english-v3.0.
  • For applications with strict privacy requirements or tight budgets: Use a top-performing open-source model from the MTEB leaderboard. BAAI/bge-large-en-v1.5 or the newer BGE-M3 are excellent, well-regarded starting points.
  • For lightweight local testing or CPU-only deployment: A small, fast model like sentence-transformers/all-MiniLM-L6-v2 is perfect. Its performance is lower, but it's incredibly efficient.
Test your understanding!

You are tasked with building a RAG-based chatbot for a financial services company. The chatbot will answer questions using the company's internal, highly confidential investment strategy documents. The company has a dedicated ML engineering team and a reasonable cloud budget but cannot risk data leaks.

Based on the framework we've discussed, what category of embedding model would you choose? Justify your choice based on the key dimensions (performance, cost, suitability) and name one or two specific models you might evaluate first.

Show answer

The best choice would be a high-performing, self-hosted open-source model.

  • Justification:

    • Suitability (Privacy): The documents are "highly confidential," which makes using a third-party API like OpenAI a non-starter. Data privacy is the overriding constraint, mandating a self-hosted solution.
    • Performance: As this is for a financial services company, accuracy is crucial. You would select a model from the top of the MTEB Retrieval leaderboard, not a small, low-quality one.
    • Cost: The company has a "reasonable cloud budget" and an "ML engineering team," indicating they can handle the indirect costs of hosting and maintaining the model infrastructure. The "free" cost of the model weights is a bonus.
  • Potential Model Candidates:

    • BAAI/bge-m3: A top-tier, multilingual model on the MTEB leaderboard with a permissive license. It's a strong general-purpose choice for high-quality retrieval.
    • sentence-transformers/all-mpnet-base-v2: Another strong performer, often considered a great baseline for sentence similarity tasks.

You would start by benchmarking these models on a sample of the company's documents to see which one performs better on their specific domain.


Conclusion

You are now equipped with an analytical framework to make an informed, defensible decision about which embedding model to use for your RAG system. This is a critical step in moving from a "script-level" developer to a systems engineer.

Here are the key takeaways:

  • No Single Best Model: The choice of an embedding model is a trade-off between performance (accuracy), cost (direct and indirect), and suitability (privacy, dimensions, domain).
  • The MTEB Leaderboard is Your Guide: Use the MTEB leaderboard's "Retrieval" tab as your primary tool for evaluating the performance of potential models.
  • API vs. Open-Source is the Core Decision: API models (like OpenAI) offer ease-of-use and top-tier performance at a monetary cost and with privacy trade-offs. Open-source models (from Hugging Face) offer control, privacy, and no direct cost, but require you to manage the infrastructure.

In our next lesson, we will put this knowledge into practice. We will move beyond relying solely on general benchmarks like MTEB and explore how to evaluate embedding models directly on your own data for your specific task. This is the ultimate test of a model's suitability and a crucial skill for building a truly effective RAG system.