# Maintain RAG embeddings with OpenAI and Postgres: n8n workflow

> Started by another system calling it, and works across Postgres and in-memory vectors. It puts OpenAI behind a retrieval step, so answers are drawn from...

Source: https://millionrounds.com/workflow/maintain-rag-embeddings-with-openai-and-postgres (Millionrounds; every figure on the page links to its filing or article)

[Automation library](https://millionrounds.com/workflows) · [Content](https://millionrounds.com/workflows?category=Content#library)

# Maintain RAG embeddings with OpenAI and Postgres

Started by another system calling it, and works across Postgres and in-memory vectors. It puts OpenAI behind a retrieval step, so answers are drawn from documents you supply rather than from the model alone. 27 steps, 1 branch: large, and worth reading before you trust it with anything live.

Large Calls a model: OpenAI Retrieval

[Download free](https://millionrounds.com/login?next=%2Fapp%2Fworkflow%2Fmaintain-rag-embeddings-with-openai-and-postgres)

**27 steps** Large: read it before trusting it with anything live

**1** Branch: places the flow splits

**0** Loops or waits

**2** Services it connects to

## The flow

Starts it 2 Model 9 Logic 7 Service 9

The steps in the order they run, from what starts it.

- 1 **Daily RAG Maintenance Schedule** Schedule trigger *Starts it*
- 2 **Source Change Webhook** Webhook *Starts it*
- 3 **OpenAI Embeddings** Embeddings Open Ai *Model*
- 4 **Recursive Text Splitter** Text Splitter Recursive Character Text Splitter *Model*
- 5 **OpenAI Chat Model** Lm Chat Open Ai *Model*
- 6 **Workflow Configuration** Set *Logic*
- 7 **New Vector Store (Candidate)** Vector Store In Memory *Model*
- 8 **Query New Vector Store (Tool)** Vector Store In Memory *Model*
- 9 **Query Old Vector Store (Tool)** Vector Store In Memory *Model*
- 10 **Document Loader** Document Default Data Loader *Model*
- 11 **Generate Answers (New)** Agent *Model*
- 12 **Generate Answers (Old)** Agent *Model*
- 13 **Fetch Documents from Source** Http Request *Service*
- 14 **Fetch Previous Chunk Hashes** Postgres *Service*
- 15 **Store Embedding Metadata** Code *Logic*
- 16 **Calculate Quality Metrics** Code *Logic*
- 17 **Chunk Documents & Compute Hash** Code *Logic*
- 18 **Detect Changed Chunks** Compare Datasets *Service*
- 19 **Save Embedding Version Metadata** Postgres *Service*
- 20 **Calculate Embedding Drift** Code *Logic*
- 21 **Fetch Golden Questions** Postgres *Service*
- 22 **Fetch Previous Embeddings** Postgres *Service*
- 23 **Quality Improved?** If *Logic*
- 24 **Promote New Embeddings** Postgres *Service*
- 25 **Rollback to Previous Embeddings** Postgres *Service*
- 26 **Flag for Human Review** Set *Logic*
- 27 **Send Notification** Http Request *Service*

## How it's built

- **Starts on:** Another system calling it
- **Steps:** 27, with 1 branch
- **Size:** Large: read it before trusting it with anything live
- **Connects to:** Postgres, in-memory vectors
- **Model:** OpenAI
- **Retrieval:** Answers are drawn from documents you supply, not from the model alone

## Questions

What does it need to run?

An n8n account, plus your own Postgres and in-memory vectors accounts, and a key for OpenAI. You connect your own accounts after importing it; none are included.

What starts it?

It starts on another system calling it.

Does it use AI?

Yes. It calls OpenAI. Its answers draw on documents you give it, not on the model alone. Model calls are billed by the provider, not by n8n.

How long does it take to set up?

Take your time. At 27 steps it is large: read it before trusting it with anything live.

How do I import it?

Copy the workflow, open a new workflow in n8n and paste. The steps appear on the canvas, ready for your own accounts.

**Before you run it**

Nothing here has been tested by us. It is somebody's working automation, read and described from its own steps. Treat the connections it wants as a list of accounts it will touch, and read the 27 steps before you point it at anything that matters.

## Run it in n8n

- **Create your n8n account** Free to start. n8n is where the workflow runs. [Create an n8n account ↗](https://millionrounds.com/n8n)
- **Download the workflow** Free with a Millionrounds account. [Download free](https://millionrounds.com/login?next=%2Fapp%2Fworkflow%2Fmaintain-rag-embeddings-with-openai-and-postgres)
- **Paste it into n8n** Open a new workflow in n8n and paste. Then connect your own accounts.

Stored with the author's traces removed: canvas notes, instance identifiers, saved credential names and any live document they had left behind.

## Connects to

Each opens the other workflows that use it.

[Postgres](https://millionrounds.com/workflows?service=Postgres#library)[in-memory vectors](https://millionrounds.com/workflows?service=in-memory+vectors#library)

## Workflows like it

Also content, with the same services where possible, closest in size first.

- [**Automated Instagram content creation from trending posts** 27 steps · calls a model · Postgres, Telegram](https://millionrounds.com/workflow/automated-instagram-content-creation-from-trending-posts)
- [**Generate Instagram content from top trends with OpenAI** 27 steps · calls a model · Postgres, Telegram](https://millionrounds.com/workflow/generate-instagram-content-from-top-trends-with-openai)
- [**Publish LinkedIn & X posts with Telegram Bot and Gemini** 28 steps · calls a model · Telegram, in-memory vectors](https://millionrounds.com/workflow/publish-linkedin-and-x-posts-with-telegram-bot-and-gemini)
- [**Route and analyze customer feedback with Qwen3-VL and Tally** 26 steps · calls a model · Discord, Postgres](https://millionrounds.com/workflow/route-and-analyze-customer-feedback-with-qwen3-vl-and-tally)
- [**Route weather-based delivery holds with Open-Meteo and Gemini** 26 steps · calls a model · Postgres, Slack](https://millionrounds.com/workflow/route-weather-based-delivery-holds-with-open-meteo-and-gemin)
- [**Send bulk email campaigns with Gmail and SMTP** 28 steps · Gmail, Postgres](https://millionrounds.com/workflow/send-bulk-email-campaigns-with-gmail-and-smtp)
