Agentic AI

Evaluating Domain Specific Embedding Models

Domain-tuned embeddings beat general ones for retrieval. The benchmark results, on legal and finance data.

Key takeaways

  • Generic encoders like BERT and RoBERTa often miss domain nuance; domain-specific embedding models learn specialized representations tuned to the task.
  • Benefits in RAG pipelines: improved retrieval accuracy, higher generation quality, and reduced training time.
  • Dataworkz lets you plug custom embedding models into RAG pipelines, configure and fine-tune them, and evaluate against ground-truth datasets before deploying.
  • On the LegalBench-RAG and a finance benchmark, Voyage AI's domain models (voyage-legal-2, voyage-finance-2) outperformed OpenAI and ModernBERT on key metrics like context_F1 and reciprocal rank.
  • The domain-specific models led even without a re-ranker, while the comparison models were given re-rankers — underscoring the value of domain-tuned embeddings.
On this pagesections

    These tasks include question answering, summarization, and machine translation. RAG models utilize pre-trained encoders to convert text into dense vector representations, which are then used for the efficient retrieval of relevant documents and the subsequent generation of responses.

    Benefits of Domain-Specific Embedding Models

    While pre-trained encoders like BERT and RoBERTa have achieved impressive results on a wide range of tasks, they may not capture the nuances of specific domains. Domain-specific embedding models, on the other hand, are trained on data from a particular domain, allowing them to learn specialized representations that are more relevant to the task at hand.

    Here are some of the benefits of using domain-specific embedding models in RAG pipelines:

    • Improved Retrieval Accuracy: Domain-specific embedding models can better distinguish between relevant and irrelevant documents, leading to more accurate retrieval of information.
    • Enhanced Generation Quality: By leveraging domain-specific knowledge, RAG models with domain-specific embedding models can generate more coherent and informative responses that are tailored to the specific domain.
    • Reduced Training Time: Since domain-specific embedding models are pre-trained on domain-specific data, they require less training time compared to training a RAG model from scratch.

    Dataworkz Support for Custom Embedding Models

    Dataworkz, a leading provider of AI and NLP solutions, offers robust support for adding custom embedding models to its platform. Here’s how Dataworkz makes it easy to integrate domain-specific embedding models into RAG pipelines:

    • Seamless Integration: Dataworkz allows users to seamlessly integrate their custom embedding models with its RAG pipelines.
    • Flexible Configuration: Users have the flexibility to specify the embedding model to be used, as well as the parameters for training and fine-tuning the model.
    • Simplified Deployment: Dataworkz provides a user-friendly interface for deploying RAG pipelines with custom embedding models, making it easy to operationalize these models for real-world applications.

    By leveraging Dataworkz’s platform, organizations can easily incorporate domain-specific embedding models into their RAG pipelines, evaluating the performance against ground truth datasets, quickly deploying these into production environments.

    Evaluation Results 

    In our research, we leveraged two distinct embedding models developed by Voyage AI, specifically voyage-legal-2 and voyage-finance-2. We conducted a comparative analysis of these models against other widely-used models, such as those from OpenAI and Modernbert. To facilitate efficient and scalable hosting of the open-source Modernbert embedding model, we utilized the Modal platform, which specializes in providing hosting solutions for Huggingface models. For accessing the OpenAI and Voyage AI models, we interacted with their respective REST API endpoints, enabling seamless integration and utilization of these models within our research framework.

    Case Study: LegalbenchRAG Dataset

    In our research endeavor, we harnessed the power of legalbenchRAG repositories, employing them as the foundational datasets for our experimental investigations. These datasets were methodically uploaded into an S3 bucket, and baseline Retrieval Augmented Generation (RAG) pipelines were meticulously constructed to process this data.

    For the purpose of this rigorous evaluation, we relied upon the golden dataset that had been meticulously generated from the legalbenchrag repository. This dataset, curated with utmost precision, served as a reliable benchmark against which we could objectively compare the results of our experiments, ensuring the integrity and validity of our findings.

    The results gleaned from our experiments on the dataset are visually presented in the graph below. It is pertinent to note that the two experiments were conducted with distinct embedding models, each contributing unique insights to the overall analysis. To establish a high standard of performance and ensure a robust evaluation of the Voyage AI models, we strategically employed the other two models with re-rankers. This deliberate approach effectively set a higher bar for the F1 and Precision scores, challenging the Voyage AI model to demonstrate its superior capabilities.

     

    Fig1: Plot of Context_F1, Context_Precision, Context_Recall, NDCG, Reciprocal rank for various RAG experimentation

    From the results obtained, it is evident that the Voyage AI model consistently outperformed the other two RAG pipelines across key metrics, showcasing its remarkable efficacy and precision. Notably, this exceptional performance was achieved without the assistance of a re-ranker, further highlighting the inherent capabilities of the model. Thus, it can be confidently concluded that a domain-specific model, such as the Voyage AI model, possesses the potential to significantly enhance retrieval performance and provide superior generated answers compared to a generic embedding model. 

    Case Study: Finance RAG Dataset

    In this evaluation of Retrieval Augmented Generation (RAG), we utilized a subset of the finance benchmark repository, containing 80 documents, each with 150-200 pages of content. This dataset was chosen to ensure the robustness and reliability of our evaluation, as it provided a diverse and representative sample of financial information.

    To ensure accuracy and provide a basis for comparison, we employed an open-source “golden truth set” comprising 80 questions, each accompanied by their respective answers and relevant context excerpts. This “golden truth set” served as a ground truth benchmark, allowing us to objectively measure the performance of our RAG models.

    The core of our RAG experiment involved the alteration of the embedding model. We specifically focused on comparing the performance of the voyage-finance-2 model against the OpenAI and Modernbert models. These models were chosen due to their widespread use and recognized performance in natural language processing tasks.

    The results of our experiment show that while on most metrics the OpenAI and Modernbert models are able to hold their own, the voyage-finance-2 model demonstrates superior performance in key areas. Specifically, the voyage-finance-2 model achieved a higher context_f1 score and reciprocal rank scores.

     

    Fig2: Plot of Context_F1, Context_Precision, Context_Recall, NDCG, Reciprocal rank for various RAG experimentation

    The context_f1 score measures the model’s ability to retrieve relevant and accurate contextual information. A higher context_f1 score indicates that the model is better at identifying and extracting pertinent information from the source documents. This is crucial for RAG, as it directly impacts the quality and coherence of the generated output.

    Similarly, a higher reciprocal rank score signifies that the model is more likely to present the most relevant and precise information first. This is particularly important in real-world applications, where users often prioritize the top results and may not have the time or inclination to sift through numerous irrelevant or less precise results.

    By achieving better context_f1 and reciprocal rank scores, the voyage-finance-2 model ensures a balance of precision and recall in our retrieval. This means that the model is not only able to retrieve relevant information but also to do so with a high degree of accuracy. Furthermore, the model’s ability to prioritize the most precise results ensures that users are presented with the most valuable and informative content first.

    References – 

    1. https://docs.voyageai.com/docs/embeddings 
    2. https://huggingface.co/Alibaba-NLP/gte-modernbert-base 
    3. https://github.com/dataworkz-dev/dataworkz-rag-eval 

    Frequently asked questions

    What is a domain-specific embedding model?

    An embedding model trained on data from a particular domain (for example legal or finance) so it captures specialized nuance that general-purpose models like BERT or RoBERTa tend to miss.

    Why use domain-specific embeddings in a RAG pipeline?

    They improve retrieval accuracy, produce more coherent and informative generated answers, and require less training time than building a model from scratch.

    How did domain-specific models compare to general ones in testing?

    Voyage AI's legal and finance embedding models consistently outperformed OpenAI and ModernBERT on metrics such as context_F1 and reciprocal rank — and did so without a re-ranker, while the other models used one.

    Can I bring my own embedding model to Dataworkz?

    Yes. Dataworkz supports integrating custom embedding models, configuring their training and fine-tuning parameters, and deploying them into production RAG pipelines through a guided interface.

    See what your engineers can ship in production

    Dataworkz is the agentic AI platform enterprises trust to put AI agents into production. Teams build production-ready agents in days, every decision stays traceable, and every agent has ROI attached.

    Explore the platform