Webinar Lottie

lakeFS Acquires DVC, Uniting Data Version Control Pioneers to Accelerate AI-Ready Data

webcros
Idan Novogroder
Idan Novogroder Author

Idan has an extensive background in software and DevOps engineering....

Last updated on September 24, 2025

It may be tempting to think large language models (LLMs) can provide commercial value without any additional work, but this is a rare case. Businesses can make the most of these models by adding their own data.

To do this, teams can use a technique called retrieval augmented generation (RAG). What is a RAG pipeline and how do you manage it to stay in line with machine learning best practices? Keep reading to find out!

Key Takeaways

  • RAG bridges LLMs with external knowledge bases: Retrieval Augmented Generation (RAG) enables large language models to access up-to-date, domain-specific information without retraining by querying vector databases built from unstructured data.
  • Core RAG pipeline has distinct indexing and retrieval stages: The pipeline includes ingestion, extraction, transformation, chunking/embedding, persistence, and refreshing, culminating in the generation of answers using LLMs informed by retrieved context.
  • Vector databases and embedding models are foundational: Tools like Milvus, Pinecone, FAISS, and embedding models from OpenAI or Hugging Face enable fast, accurate similarity searches by storing high-dimensional text representations.
  • LangChain, LlamaIndex, and Haystack lead RAG tool ecosystem: These libraries provide modular components for data loading, embedding, vector search, and LLM integration, supporting both dense and keyword-based retrieval strategies.
  • Common RAG challenges include computational cost and explainability: While RAG improves accuracy and contextual relevance, it introduces complexity in retrieval transparency and resource demands, requiring optimization strategies like query reformulation and re-ranking.

What is RAG (Retrieval Augmented Generation)?

Retrieval augmented generation (RAG) is a technique of optimizing the output of a large language mode whereby the model consults a reliable knowledge base outside of its training data sources before producing a response. 

Large Language Models (LLMs) use billions of parameters and massive volumes of data during training to generate unique output for tasks like language translation, sentence completion, and question answering. 

RAG extends the already powerful capabilities of LLMs to specific domains or an organization’s own knowledge base without requiring the model to be retrained. It’s a reasonably priced method of improving LLM output to ensure that it stays relevant, accurate, and useful in a range of contexts thanks to relevant information.

What is a RAG Pipeline?

Retrieval augmented generation (RAG) is a technique of optimizing the output of a large language mode whereby the model consults a reliable knowledge base outside of its training data sources before producing a response. 

Large Language Models (LLMs) use billions of parameters and massive volumes of data during training to generate unique output for tasks like language translation, sentence completion, and question answering. 

RAG extends the already powerful capabilities of LLMs to specific domains or an organization’s own knowledge base without requiring the model to be retrained. It’s a reasonably priced method of improving LLM output to ensure that it stays relevant, accurate, and useful in a range of contexts thanks to relevant information.

A RAG pipeline uses unstructured data as the source that may be stored in a variety of different formats across databases and data lakes. The objective of such a pipeline is to build a trustworthy vector search index that is filled with accurate information and pertinent context.

By doing this, you can ensure that your huge language model will always have the context needed to appropriately reply to user queries that require information from external knowledge sources.

A vector database is where the pipeline ends. A variety of transformation and document preprocessing stages along the way also help to achieve a scalable, dependable RAG architecture.

RAG Pipeline Example: How it Works

The basic retrieval-augmented generation (RAG) pipeline comprises two key phases:

  1. Data Indexing 
  2. Retrieval and Generation

Let’s take a closer look at each of these:

Data Indexing

The following steps are part of data indexing:

  • Data Loading: importing all of the data to be used.
  • Data Splitting: separating large datasets into smaller bits.
  • Data Embedding: an embedding model converts the data into vector form.
  • Data Storage: vector embeddings are maintained in a vector database, which makes them easily searchable.

Retrieval and Generation Process

This process is made of two parts:

  • Retrieval: when a user asks a question, their input is turned into a query vector using the same embedding model as in the Data Indexing step. This query vector is then compared to all vectors in the vector database to identify the most comparable ones that may hold the answer to the user’s question. This stage involves finding relevant knowledge bits.
  • Generation: the LLM model generates a response based on the user’s question and information retrieved from the vector database. This procedure combines the query with the identified data to get an answer.
Diagram of a basic RAG pipeline showing data indexing into a vector DB and query retrieval with LLM for response generation.

Key Components of a RAG Pipeline

1. Ingestion

Initially, the retrieval augmented generation pipeline is fed raw data from various sources, including databases, papers, and live feeds. LangChain offers a range of document loaders that can load data in many formats from numerous sources to pre-process this data.

Source documents don’t always have to be what you would consider normal documents (text files, PDFs, and so forth). LangChain can import data from CSV files, emails, Confluence, and more. 

2. Extraction

We must incorporate extraction logic into our RAG pipeline since a lot of unstructured data sources need some processing to extract the natural language text data stored inside. 

It’s possible that data taken from data sources won’t be immediately helpful. For instance, turning a PDF document into usable text is a well-known challenge. 

In simple scenarios, preprocessing relevant documents using open-source libraries works well. However, to arrange the extracted natural language into a format that more closely matches how a human would read the page, you might need to rely on something more specifically designed for knowledge-intensive natural language processing (NLP) operations for complex PDFs. 

Other cutting-edge choices, like AWS Textract, rely on machine learning and neural network-based solutions to fuel this process. 

3. Transformation

Documents are often altered after they’re loaded. Material-splitting is one transformation technique that divides lengthy material into manageable chunks. 

You need to do that if you want to fit the text into the e5-large-v2 embedding model, which has a maximum token length of 512. Although dividing the text seems straightforward, expect to run into challenges.

4. Chunking/Embedding

Once absorbed, data needs to be converted into a format that the system can process effectively. Data must be transformed into high-dimensional vectors, or numerical representations of text, in order to generate embeddings.

Although these are two separate processes, chunking and embedding are tied to one another. Chunking is the process of dividing the content that has been extracted from the source data into a series of text segments.

When it comes to retrieval augmented generation, the chunking approach is crucial because RAG will use the text chunks you write in this phase to provide context to the LLM during runtime.

The process of embedding involves converting the text chunks into document embeddings, which are then stored in the vector database. These vectors are produced using one of the various embedding models offered by businesses like Mistral AI, or by OpenAI, such as text-embedding-ada-0002 or text-embedding-v3-large. 

Although businesses are experimenting with fine-tuning these models for domain-specific use cases like banking or legal, the majority of embedding models are general-purpose.

Vector databases are specialized databases that hold the generated embeddings and processed data. Because of their optimal handling of vectorized data, these databases allow for quick searches and data retrieval. Data will always be available and promptly accessed during real-time interactions if it is stored in RAPIDS RAFT accelerated vector databases like Milvus.

4. Persistence

An embedding model will typically yield vectors with a set number of dimensions for each vector. You will usually choose the number of dimensions for your search index when you build it in your vector database. New data entered into the index must meet the required dimension length

5. Refreshing

After your vector database is filled, you will need to consider how to maintain synchronization between the vector data and the source data that was utilized to fill it. 

If you skip this step, your language models will produce inaccurate answers to user queries. You will eventually run into issues with your retrieval augmented generation use case because the documents being retrieved are no longer current.

RAG Pipeline Benefits and Challenges

RAG Pipeline Benefits

1. Cost-Efficient

RAG is inexpensive and easy to use compared to other methods of enhancing LLMs with domain-specific data. RAG can be implemented by organizations without requiring model customization. This is particularly helpful when fresh data must be added to models regularly.

2. Improved Contextual Understanding

RAGs help to deliver pertinent, domain-specific answers. By using RAG, the LLM can deliver contextually appropriate answers customized to an organization’s proprietary or domain-specific data.

3. Real-Time Data 

In an enterprise, data is always changing. RAG makes sure that an LLM’s response isn’t based on old, stagnant training data. Instead, the model gets its answers from up to date external data sources.

4. Data privacy

Protecting customer privacy is essential for businesses. Just like the stored data, sensitive data can also be preserved on-premises with a self-hosted LLM.

5. Enhanced Factual Accuracy

When given inaccurate but plausible information, LLMs frequently give incorrect but persuasive answers. This is referred to as hallucination, and by giving the LLM factual and relevant information, RAG reduces their occurrence and produces contextually relevant responses.

6. Greater Autonomy for Developers

Developers can more effectively test and enhance their apps with RAG. They can modify and alter the LLM’s data sources in response to shifting needs or cross-functional usage. Additionally, developers can limit the retrieval of sensitive data to certain authorization levels and make sure the LLM produces relevant results. 

RAG Pipeline Challenges

1. Computational Cost

Processing and retrieving massive volumes of data can come with high computational and financial costs, calling for optimization strategies for real-world applications.

2. Limited Explainability

It can be difficult to comprehend the reasoning behind the passages that were retrieved and how they affect the generated response.

3. Potential for Bias

The generated response may contain biases derived from the retrieved data, underscoring the importance of rigorous data curation and mitigation techniques.

How to Build and Deploy a RAG Pipeline

Architecture Design

Diagram of Databricks RAG workflow showing data prep, embeddings, vector search retrieval, and LLM inference for user queries.
Source: Databricks

A retrieval augmented generation system can be implemented using various methods, based on the particular requirements of the data. 

Databricks suggests the following crucial RAG architecture components:

Vector Database

For quick similarity searches, some (but not all) LLM systems use vector databases; these databases are typically used to supply context or domain knowledge for LLM queries. 

Regular vector database updates can be scheduled as a job to guarantee that the deployed language model has access to current data. 

Note: when using  MLflow PyFunc or LangChain model flavors, the logic to extract data from the vector database and insert it into the LLM context can be packed into the model artifact submitted to MLflow.

MLflow LLM Deployments or Model Serving

MLflow LLM Deployments or Model Serving can support external models. You can implement them as a standard interface to route requests from suppliers like Anthropic and OpenAI in LLM-based apps that use a third-party LLM API. 

The MLflow LLM Deployments or Model Serving not only offers an enterprise-grade API gateway but also centralizes API key management and allows cost limits to be enforced.

Model Serving

If RAG uses a third-party API, you need to make one significant architectural modification. The LLM pipeline will contact external APIs to reach internal or external LLM APIs from the Model Serving endpoint. 

This involves an additional layer of credential management, potential latency, and complexity. In contrast, both the model and its model environment will be deployed in the example of the fine-tuned model.

Implementing the Pipeline 

The three elements listed below serve as the cornerstone of a RAG pipeline that enables users to receive correct, contextually rich replies. For this reason, RAG stands out from the competition when it comes to developing chatbots and other question-answering systems.

Three essential components comprise the RAG pipeline:

Component How it Works
Retrieval For each user inquiry, this component helps retrieve pertinent material from an external knowledge base, such as a vector database. This is an important component because it’s the first step in selecting the relevant and appropriate responses for the given scenario.
Augmentation Enhancing and adding more pertinent context to the received answer for the user query.
Generation A large language model (LLM) is used to present the user with the final output. The LLM responds to the user’s query appropriately by drawing on its knowledge as well as the context that has been provided.

Tools and Libraries to Build RAG Pipelines

1. LangChain.

LangChain is an open-source Python module and ecosystem that provides a solid platform for developing applications that use large language models (LLMs). It combines a modular and flexible design with a high-level interface, making it excellent for creating retrieval-augmented generation systems.

Langchain facilitates the integration of numerous data sources, including papers, databases, and APIs, which can aid in the generating process. This library provides a wide range of capabilities and allows users to customize and mix numerous components to meet specific application requirements, making it easier to build dynamic and resilient language model applications.

Key features:

  • It integrates with vector databases like Chroma, Pinecone, and FAISS.
  • Load and get data from databases, APIs, and local files to provide context.
  • Retrievers include BM25, Chroma, FAISS, Elasticsearch, Pinecone, and others.
  • Loaders for PDF/text, web scraping, and SQL/NoSQL databases
  • Memory management is keeping context across conversations to improve the conversational experience.
  • Generate dynamic prompts with templated structures.
  • Customize prompts based on the retrieved data to improve context.

2. LlamaIndex

LlamaIndex (formerly GPT Index) is a powerful library for creating retrieval-augmented generation (RAG) systems. It focuses on efficient indexing and retrieval of large datasets.

LlamaIndex uses advanced methods like vector similarity search and hierarchical indexing to make it easy to find the information you need quickly and correctly. This makes generative language models more powerful.

The library seamlessly integrates with standard large language models (LLMs), allowing for the incorporation of received data into the creation process and serving as an excellent tool for boosting the responsiveness of LLM-based applications.

Key features:

  • Multiple index types
  • The Vector Store Index stores data as dense vectors, enabling rapid similarity searches in applications like document retrieval and recommendation systems.
  • List Index: A simple, sequential index for smaller datasets that enables speedy linear searches.
  • The Tree Index uses a hierarchical structure to do efficient semantic searches, making it perfect for complex queries that require hierarchical data.
  • Keyword Table Index: A mapping table facilitates keyword-based searches and provides quick access to data based on specific terms or tags.
  • Retrieval Optimization: Effectively retrieves crucial information with low delay.
  • Document Loaders enable data loading from a variety of sources, including files (TXT, PDF, DOC, CSV), APIs, databases (SQL/NoSQL), and web scraping.
  • The system integrates embedding models (OpenAI, Hugging Face) with vector database retrievers (BM25, DPR, FAISS, Pinecone).

3. Haystack

Deepset’s Haystack is an open-source natural language processing platform that specializes in building RAG pipelines for search and question-and-answer applications. Its comprehensive tool set and flexible design enable the development of adaptive and configurable RAG solutions.

The framework includes document retrieval, question answering, and generating components that support a wide range of retrieval methods, including Elasticsearch and FAISS. Haystack also works with cutting-edge language models like BERT and RoBERTa, which increases its ability to handle demanding query workloads.

It also offers an easy-to-use API and a web-based user interface, allowing users to interact with the system and build effective question-and-answer and search apps.

Key features:

  • Supports Elasticsearch, FAISS, SQL, and in-memory storage backends.
  • GenerativePipeline combines retriever and generator (GPT-3/4).
  • Keyword-based retrieval using BM25
  • Transformers Reader: Extractive QA with Hugging Face models.
  • DensePassage Retriever retrieves dense embeddings using DPR.
  • Readers: FARM. Reader: Extractive QA using Transformer models.
  • EmbeddingRetriever: Custom embeddings with Hugging Face models.
  • HybridPipeline: Combines multiple retrievers/readers for optimal performance.
  • Built-in tools for evaluating QA and search procedures.

4. RAGatouille 

This lightweight system combines pre-trained language models with efficient retrieval algorithms to createrelevant and coherent RAG pipelines. It abstracts the difficulties of retrieval and generation while stressing modularity and ease of use.

The framework’s architecture is adaptable and flexible, allowing users to test out various retrieval techniques and generation models. RAGatouille supports a wide range of data sources, including text documents, databases, and knowledge graphs, and it is adaptable to a wide range of domains and use cases, making it an ideal choice for anyonelooking to implement RAG activities rapidly

Key features:

  • Large datasets are efficiently handled via better retrieval.
  • Generate reactions with OpenAI (GPT-3/4), Hugging Face Transformers, or Anthropic Claude.
  • Data retrieval solutions include keyword-based (SimpleRetriever, BM25Retriever) and dense passage retrieval (DenseRetriever).
  • Create customizable prompt templates for consistent question comprehension.
  • Dask and Ray enable distributed processing 

5. EmbedChain

EmbedChain is an open-source platform for creating chatbot-like apps that incorporate tailored information using embeddings and large language models (LLMs). It focuses on embedding-based retrieval for RAG, which quickly pulls useful data from big datasets using dense vector representations.

EmbedChain provides a simple and straightforward API for indexing and querying embeddings, making it simple to incorporate into retrieval-augmented generation workflows. It supports various embedding models, including BERT and RoBERTa, and offers flexibility through similarity metrics and indexing systems, increasing its ability to tailor applications to particular needs.

Key features:

  • It enables embedding models such as OpenAI, BERT, RoBERTa, and Sentence Transformers.
  • It gathers data from various sources such as files (TXT, PDF, DOC, CSV), APIs, and web scraping.
  • Embeddings provide efficient and exact retrieval.
  • A simple UI enables you to quickly design and deploy RAG systems.
  • The system provides a basic API for indexing and querying embeddings.

6. NeMo Guardrails

NeMo Guardrails is an open-source framework for readily incorporating programmable guardrails into LLM-based conversational applications. Guardrails (or rails) are specific methods for managing the output of a big language model, such as refraining from talking politics, reacting in a specific way to specific user requests, following a specified dialog path, employing a given language style, extracting structured data, and so on.

Key features:

  • Building trust, safety, and security. You can construct rails to direct and protect chats, as well as describe your LLM-based application’s behavior on specific topics and prevent it from participating in debates on other concerns.
  • An LLM can connect to other services (also known as tools) in a simple and secure way.
  • You can instruct the LLM to follow predetermined conversational paths, allowing you to construct the interaction in accordance with conversation design best practices and apply standard operating procedures (such as authentication and support).

7. Verba

Verba is an open-source RAG chatbot powered by Weaviate. Verba streamlines data exploration and insight extraction by offering a user-friendly interface from beginning to end. 

The tool distinguishes itself by allowing for local deployments or integration with LLM providers such as OpenAI, Cohere, and HuggingFace, as well as its ease of use and versatility in handling various data formats.

Its main features are simple data import, clever query resolution, and faster searches using semantic caching, making it ideal for creating sophisticated RAG applications.

Key features:

  • Local Embedding and Generation. 
  • Models powered by Ollama
  • HuggingFace drives local embedding models, whereas Cohere, Anthrophic, and OpenAI power generation models.
  • Hybrid search blends semantic search with keyword search.
  • Autocomplete Suggestion: Verba suggests autocomplete.
  • Filtering: You can add filters before completing retrieval-augmented generation (e.g., documents, document types, etc.).
  • Customizable metadata: Free control over metadata.
  • Async Ingestion: Ingest data asynchronously to speed up the process.

8. Phoenix

Phoenix is an open-source AI observability platform that supports experimentation, evaluation, and debugging. Phoenix can run practically anywhere, including your Jupyter notebook, local workstation, containerized deployment, and the cloud.

Key Features:

  • Tracing: Utilize OpenTelemetry-based instrumentation to track the runtime of your LLM application.
  • Evaluation: Use LLMs to benchmark the performance of your application through response and retrieval evaluations.
  • Datasets: Create versioned datasets including examples for experimentation and evaluation with the flexibility of precise tuning.
  • Experiments: Monitor and evaluate changes to cues, LLMs, and retrieval.
  • Phoenix supports common frameworks (LlamaIndex, LangChain, Haystack, DSPy) and  LLM providers (OpenAI, Bedrock) with no preference for vendors or languages.

9. MongoDB

MongoDB is an open-source NoSQL database that focuses on scalability and performance. It uses a document-oriented approach and accepts data types similar to JSON. This flexibility allows for more dynamic and fluid data representation, which makes MongoDB useful for online applications, real-time analytics, and large-scale data management.

MongoDB supports extended queries, full index support, replication, and sharding, as well as sophisticated high availability and horizontal scaling features. MongoDB Atlas Vector Search performs semantic similarity searches on your data, which may be used with LLMs to develop AI-powered applications.

Key Features:

  • Atlas Vector Search allows you to store vector embeddings alongside your source data and metadata, leveraging the document model’s capabilities.
  • When you use an aggregation pipeline to look for semantic similarity in these vector embeddings, you can quickly find it in the data using the approximate closest neighbors method.

Expert Tip: Use Branch-Based RAG Pipelines to Isolate Vector Index Versions Like Code Releases.

Nir Ozeri

Nir Ozeri is a seasoned Software Engineer at lakeFS, with experience across the tech stack from firmware to cloud-native systems. A core developer at lakeFS, he’s also an avid diver and surfer. Whether coding or exploring the ocean, Nir sees both as worlds full of rhythm, mystery, and discovery.

  • Tactical Insight: Version control isn’t just for code. Your vector embeddings and preprocessed unstructured data should be versioned using branch in lakeFS. Create isolated lakeFS branches for each RAG index build (e.g., rag-index-v1, rag-index-v2). When updates or corrections are needed (e.g., chunking logic fix or embedding model upgrade), build on a new branch and merge only after validation.
  • Tech & Workflow Context: RAG systems often run over constantly changing raw sources: PDFs, CSVs, and emails. When chunking and embedding models are adjusted (e.g., moving from text-embedding-ada-002 to e5-large-v2), those changes impact the entire index. Using lakeFS + Spark or LangChain’s loaders over an object store (S3, GCS), you can commit each transformation stage and compare outputs across branches.
  • Engineering Impact or Tradeoff: Branching avoids downtime or degraded QA when rolling out new retrieval logic. The tradeoff is that storing multiple vector index versions  increases object storage costs but this investment provides critical rollback protection and enables side-by-side performance comparisons. 

How to Optimize the RAG Pipeline

Fine-Tuning Retrieval Models

You can enhance the retrieval models’ capacity to recognize pertinent information by fine-tuning them for certain tasks or domains.

Query Reformulation

Reformulating user queries to make them more exact or particular can improve retrieval results, which in turn can boost the accuracy of generated outputs.

Re-Ranking

Using re-ranking algorithms can help identify the texts that are most pertinent to the LLM after an initial set has been retrieved, hence enhancing the quality of the provided response.

RAG Pipeline Use Cases

RAG has a wide variety of usage scenarios. The most typical ones are:

  • Chatbots for questions and answers – By integrating LLMs with chatbots, RAGs may automatically extract more precise responses from corporate documentation and knowledge stores. Chatbots can automate online lead follow-up and customer assistance to promptly address inquiries and fix problems.
  • Augmenting search results with LLM-generated responses – With RAG, search engines respond more effectively to informational questions, making it simpler for users to get the data they require to conduct their tasks.
  • Answering questions – One example is employees who can readily get answers to their questions, including HR-related inquiries about policies and benefits as well as security and compliance concerns, by using company data as context for LLMs.

Conclusion

By bringing together the advantages of dense vector representations and LLMs, retrieval augmented generation has emerged as a method with great potential. RAG models are scalable and ideal for large-scale enterprise applications because they use dense vector representations.

RAG is bound to become crucial in fostering creativity and producing superior, intelligent systems that can comprehend and produce language akin to that of humans as LLMs continue to develop.

Frequently Asked Questions

Both RAG and fine-tuning seek to enhance large language models (LLMs). RAG accomplishes this without affecting the underlying LLM, whereas fine-tuning calls for adjusting the weights and settings of an LLM. A model can often be customized utilizing both fine-tuning and RAG architecture.

By using contextual information, RAG allows AI systems to create responses that are personalized to users’ individual requirements and preferences. RAG also allows enterprises to keep data privacy rather than retraining a model held by a separate entity, allowing data to stay where it is.

RAG enables the LLM to provide accurate information with source attribution. The output may include citations or references to sources. Users can also check for source materials if they need further explanation or detail. This can build trust and confidence in your generative AI solution.

RAG is a model that blends retrieval-based and generation-based strategies to create more precise, contextually appropriate responses. An Agent is a more interactive AI system that can take actions based on its surroundings, often through reasoning and decision-making. An agent does more than just answer to questions; it can also take steps, conduct activities, and communicate with other systems to achieve its objectives.

Semantic search extends keyword search (which is dependent on the presence of certain index words in the search input) to identify contextually relevant facts based on the input string’s conceptual similarity. As a result, it’s an excellent choice for adding context to models like as GPT-4. Semantic search employs a vector database that stores text chunks (taken from various documents) and vectors (mathematical representations of the text). When you query a vector database, the search input (in vector form) is compared to all of the stored vectors, and the text chunks with the highest similarity are returned.

lakeFS