What Is RAG? From PostgreSQL pgrag to Distributed RAG with YugabyteDB pg_dist_rag

Retrieval-Augmented Generation, better known as RAG, has become one of the most common patterns for building AI applications that need to answer questions using information that was not necessarily part of an AI model’s original training data.

Instead of asking a Large Language Model (LLM) to answer a question entirely from what it learned during training, RAG first retrieves information that is relevant to the question and supplies that information to the model as additional context.

At a high level, the process looks like this:

RAG-Pipeline

For example, imagine asking an AI assistant:

  • What is our company’s procedure for approving a production database upgrade?

A general-purpose LLM probably does not know your company’s internal procedures.

With RAG, the application could search an internal knowledge base containing operational runbooks, support procedures, architecture documents, and engineering standards. The most relevant passages are retrieved and supplied to the LLM along with the question.

The resulting prompt might conceptually look like:

				
					QUESTION:

What is our company's procedure for approving a production database upgrade?


RELEVANT INTERNAL INFORMATION:

  [Excerpt from Production Upgrade Runbook]

  [Excerpt from Change Management Policy]

  [Excerpt from Database Operations Guide]


Using the information above, answer the question.
				
			

The LLM can now generate an answer based on information specific to the organization rather than relying only on its pretrained knowledge.

That is the basic idea behind RAG.

RAG in One Sentence

RAG retrieves information relevant to a question and supplies that information to an LLM so the model can generate an answer grounded in your data.

Where Do Vectors Come Into the Picture?

Computers need a way to determine that two pieces of text are conceptually related even when they don’t contain exactly the same words.

For example:

  • How do I reset my password?

and:

  • I forgot my login credentials.

are semantically related even though relatively few words match.

An embedding model converts text into a vector: a list of numbers representing characteristics of the text.

At a high level:

				
					"How do I reset my password?"

             |
             v

[0.021, -0.184, 0.736, 0.115, ...]
				
			

Another piece of text receives another vector.

Vectors that are mathematically close to one another generally represent semantically similar content.

A vector database or vector-capable database can therefore perform searches such as:

  • Find the document chunks whose meaning is most similar to this question.

PostgreSQL users commonly use the pgvector extension to store these vectors and perform vector similarity searches.

YugabyteDB also supports pgvector, allowing vector searches to be combined with YSQL and relational data.

Want to See pgvector Semantic Search in Action?

Check out the YugabyteDB Tip Exploring National Parks with AI. It walks through a simple semantic-search example using embeddings and pgvector, showing how YugabyteDB can find results based on meaning rather than exact keyword matches.

But vector search is only one part of building a RAG system.

RAG Is More Than Vector Search

A common RAG demonstration starts with a few pre-generated embeddings and immediately performs a vector search.

That makes for a simple demo, but a real production RAG application usually has a much larger problem to solve first.

Before vectors can be searched, documents need to be:

RAG-Docs-2-Embeddings

Now add thousands, millions, or potentially tens of millions of documents.

Suddenly you also need to answer questions such as:

  • ● Which documents have been processed?
  • ● Which documents failed?
  • ● Which processing step failed?
  • ● Can the failed documents be retried?
  • ● How many documents remain?
  • ● How many workers should process them?
  • ● What happens if a worker crashes?
  • ● How are new documents discovered?
  • ● How do I track multiple document sources?
  • ● How do I keep tenant data separated?

That preprocessing and ingestion pipeline can become one of the most operationally complicated parts of a production RAG application.

This raises an interesting question: how much of that pipeline can the database help manage?

PostgreSQL projects have explored that idea before, and YugabyteDB now takes it in a distinctly distributed direction.

PostgreSQL pgrag

An interesting earlier attempt to bring more of the RAG pipeline into PostgreSQL was the Neon pgrag project.

pgrag provided experimental PostgreSQL extensions capable of performing tasks such as:

  • ● PDF text extraction
  • ● DOCX text extraction
  • ● HTML-to-Markdown conversion
  • ● Text chunking
  • ● Embedding generation
  • ● Reranking

Some embedding and reranking models could even run locally using PostgreSQL extensions built with Rust and pgrx.

The goal was interesting: allow PostgreSQL to participate in much more of the end-to-end RAG workflow rather than simply acting as the place where vectors were stored.

However, the Neon pgrag project is now deprecated and unmaintained. Its GitHub repository was archived on June 16, 2026.

Enter YugabyteDB pg_dist_rag

YugabyteDB introduced the pg_dist_rag extension as a Tech Preview in the YugabyteDB 2026.1 release series. It is pre-bundled with YugabyteDB and manages distributed RAG pipelines using SQL.

The important architectural difference is that YugabyteDB does not try to perform all of the compute-intensive RAG processing inside YSQL database processes.

Instead, the responsibilities are separated.

YB_pg_dist_rag
Important Distinction

YugabyteDB’s pg_dist_rag should not simply be thought of as a distributed port of Neon’s pgrag. They address similar RAG pipeline problems, but the YugabyteDB implementation uses a substantially different architecture.

The pg_dist_rag extension manages the workflow from YSQL, while long-running Python RAG workers perform the heavy processing outside of the database.

Those workers can crawl document sources, parse documents, split content into chunks, generate embeddings, and write the results back into YugabyteDB.

The workers poll an internal work queue maintained by the extension and claim work using lease-based locking. Multiple workers can process different documents concurrently. Adding workers therefore increases preprocessing parallelism without requiring additional processing to occur inside the database server itself.

PostgreSQL pgrag vs. YugabyteDB pg_dist_rag

Capability PostgreSQL pgrag YugabyteDB pg_dist_rag
Current Status Deprecated / archived Tech Preview
Vector Storage pgvector pgvector on YugabyteDB
Document Processing PostgreSQL extensions External RAG workers
Work Queue Not the central architecture Database-managed distributed work queue
Horizontal Processing Not its primary design Add independent RAG workers
Pipeline Monitoring Application / extension dependent Built-in pipeline tables and views
Multi-Tenant Metadata Not a primary design focus Built-in tenant identifier support

Why Separate the Workers from the Database?

Consider what happens when a document collection contains thousands of PDFs.

Processing may require:

  • ● Downloading files
  • ● Extracting text
  • ● OCR
  • ● Parsing complicated layouts
  • ● Splitting text
  • ● Tokenization
  • ● Calling an embedding model
  • ● Handling API rate limits
  • ● Retrying failures

Those tasks have very different CPU, memory, I/O, and scaling characteristics from a transactional database workload.

With pg_dist_rag, YugabyteDB maintains the state of the workflow, but dedicated workers perform that compute-intensive processing.

YB-Work-Queue

If ingestion demand increases, additional workers can be started.

If no ingestion is happening, the workers do not need to be running at all.

TEXT and PDF workers can also be scaled independently. YugabyteDB notes that workers can run on separate infrastructure from the database so database workloads and AI preprocessing workloads can scale independently.

That separation is an important part of the distributed RAG design.

SQL Becomes the Control Plane

Another interesting aspect of pg_dist_rag is that SQL becomes the interface for managing the RAG pipeline.

The extension creates a dist_rag schema containing objects for managing:

  • ● Sources
  • ● Vector indexes
  • ● Documents
  • ● Source-to-index mappings
  • ● Pipeline execution
  • ● Pipeline statistics
  • ● Work queue tasks
For example, the extension includes tables such as:
  • dist_rag.sources
  • dist_rag.vector_indexes
  • dist_rag.vector_index_source_mappings
  • dist_rag.documents
  • dist_rag.pipeline_details
  • dist_rag.work_queue
It also provides views including:
  • dist_rag.vector_index_pipeline_details
  • dist_rag.pipeline_stats

That means an administrator can use familiar SQL tools to understand what is happening in the RAG preprocessing pipeline.

We will explore these objects in the next YugabyteDB Tip: Build a Distributed RAG Pipeline from YSQL with pg_dist_rag.

One Especially Interesting Feature: Multi-Tenancy

One feature of pg_dist_rag that deserves special attention is its built-in concept of a tenant.

When a document source is registered, dist_rag.create_source() can optionally receive a:
  • tenant_id

The generated vector records also contain that tenant identifier.

The flow looks like this:

Dist-MultiTenant

That can become extremely useful when building SaaS or consolidated enterprise AI platforms.

Imagine a financial-services platform serving hundreds of banks or credit unions.

Each institution could maintain its own:

  • ● Policies
  • ● Operating procedures
  • ● Historical cases
  • ● Knowledge articles
  • ● Product documentation
  • ● Fraud investigation material

while sharing the underlying RAG infrastructure.

A query could combine vector similarity with a tenant filter so retrieved information belongs to the appropriate institution.

pg_dist_rag also stores arbitrary metadata in JSONB, which means vector similarity can be combined with normal relational filtering.

Something like this:

				
					SELECT
    chunk_text,
    embeddings <=> :query_embedding AS distance
FROM knowledge_base
WHERE tenant_id = :tenant_id
  AND metadata_filters @> '{"document_type":"policy"}'
ORDER BY distance
LIMIT 10;
				
			

Now the search is not simply:

  • Find information similar to my question.

It becomes:

  • Find information similar to my question for THIS tenant from THIS type of document.

That combination of vector search and relational filtering is one of the more compelling aspects of building RAG applications on a distributed SQL database.

Why Multi-Tenancy Matters

A multi-tenant RAG platform does not necessarily require a separate vector database or RAG infrastructure stack for every tenant. Tenant identifiers and relational metadata can be stored alongside vectors, allowing applications to combine semantic similarity with tenant-aware filtering.

Where Could Distributed RAG Be Useful?

The pg_dist_rag architecture lends itself to several interesting use cases.

Use Case Example
Enterprise Knowledge Search Search engineering documentation, policies, runbooks, and internal knowledge.
Customer Support Retrieve relevant troubleshooting procedures and historical support information.
Financial Services Assist investigators by retrieving similar fraud cases, policies, and investigation playbooks.
Multi-Tenant SaaS Maintain tenant-specific knowledge while using shared RAG infrastructure.
Compliance Retrieve regulatory guidance, company policies, procedures, and evidence relevant to an investigation.
Healthcare Knowledge Systems Search large collections of approved clinical, operational, or technical documentation.

What pg_dist_rag Does Not Do

It is also useful to understand what this extension is not.

pg_dist_rag is primarily focused on building and managing the preprocessing and embedding pipeline.

It does not magically turn every application into an AI application.

Your application may still need to:

  • ● Generate the user’s query embedding
  • ● Perform retrieval
  • ● Construct the final prompt
  • ● Call the desired LLM
  • ● Apply application security
  • ● Enforce authorization
  • ● Validate responses
  • ● Present citations or sources

Similarly, a fraud application should not assume RAG replaces a fraud detection or transaction-scoring engine.

A fraud engine might identify a suspicious transaction.

RAG can then help an investigator retrieve:

  • ● Similar historical cases
  • ● Investigation procedures
  • ● Fraud playbooks
  • ● Customer-specific policies
  • ● Relevant regulatory guidance

That distinction will become particularly important later in this series.

Current Status and Requirements

As of YugabyteDB 2026.1, pg_dist_rag is a Tech Preview feature. The current dedicated setup documentation lists YugabyteDB v2026.1.1 or later as a prerequisite.

The current implementation uses:

  • ● YugabyteDB
  • ● pgvector
  • ● pg_dist_rag
  • ● Python RAG workers
  • ● S3 document sources
  • ● OpenAI embeddings

The schema contains enums anticipating additional providers, but the current setup documentation states that S3 is the supported document source and OpenAI is the supported AI provider.

Tech Preview

pg_dist_rag is currently a YugabyteDB Tech Preview feature. Evaluate its current limitations and support status before considering it for production workloads.

Final Takeaway

RAG is often demonstrated as little more than:

  • Question -> Vector Search -> LLM

But production RAG systems require much more infrastructure before that search can happen.

Documents must be discovered, parsed, chunked, embedded, tracked, retried, monitored, and ultimately stored in a searchable vector index.

pg_dist_rag takes an interesting approach to that problem.

YugabyteDB manages the RAG pipeline state and work queue through YSQL, while independently scalable RAG workers perform the resource-intensive document processing and embedding generation.

The results are stored directly in YugabyteDB using pgvector, where vector similarity can be combined with the relational capabilities of YSQL… including metadata and tenant-aware filtering.

And that last capability may prove particularly interesting for organizations consolidating many applications or tenants onto shared YugabyteDB infrastructure.

This tip introduced the architecture.

In the next tip, we’ll actually build one.

Up Next

We will walk through:

  • ● Installing the extensions
  • ● Creating a document source
  • ● Creating a vector index
  • ● Starting RAG workers
  • ● Building the index
  • ● Watching the work queue
  • ● Monitoring pipeline progress
  • ● Examining generated chunks and embeddings
  • ● Performing vector similarity searches

and:

  • Part 4: Scale a Multi-Tenant RAG Platform with YugabyteDB

References

Have Fun!

Seems like just yesterday I was buying my first house. Now it’s my son’s turn!

He recently moved into his first home in a town about an hour and a half from Pittsburgh, and I finally got a chance to visit him this weekend and check out the new place.

Really proud of him for taking this big step and getting out on his own… finally! 😄🏡