Automation library · Data collection

Serve a RAG chat backend for Next.js with OpenAI and Redis

Started by another system calling it, and works across Pinecone, Postgres and Redis. It puts OpenAI behind a retrieval step, so answers are drawn from documents you supply rather than from the model alone. 23 steps, 3 branches: large, and worth reading before you trust it with anything live.

LargeCalls a model: OpenAIRetrieval

23 stepsLarge: read it before trusting it with anything live
3Branches: places the flow splits
0Loops or waits
3Services it connects to

The flow

Starts it 4Model 6Logic 9Service 4

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

  1. 1Webhook - RAG Agent RequestWebhookStarts it
  2. 2OpenAI Chat ModelLm Chat Open AiModel
  3. 3Window Buffer MemoryMemory Buffer WindowModel
  4. 4Embeddings - OpenAIEmbeddings Open AiModel
  5. 5Set - ConfigSetLogic
  6. 6AI Agent - RAG AssistantAgentModel
  7. 7Vector Store - Retrieve ContextVector Store PineconeModel
  8. 8Code - Validate Request SchemaCodeLogic
  9. 9Code - Parse & Validate Agent OutputCodeLogic
  10. 10Tool - Search Knowledge BaseTool Vector StoreModel
  11. 11IF - Validation PassedIfLogic
  12. 12Redis - Write Query CacheRedisService
  13. 13Code - Build Cache KeyCodeLogic
  14. 14Respond - Validation Error (400)Respond To WebhookStarts it
  15. 15Postgres - Log Conversation TurnPostgresService
  16. 16Redis - Check Query CacheRedisService
  17. 17Respond - Success (200)Respond To WebhookStarts it
  18. 18IF - Content Changed Requires RevalidationIfLogic
  19. 19IF - Cache HitIfLogic
  20. 20HTTP Request - Notify Next.js RevalidationHttp RequestService
  21. 21NoOp - Revalidation SkippedNo OpLogic
  22. 22Respond - Success (Cached)Respond To WebhookStarts it
  23. 23Code - Handle Revalidation FailureCodeLogic

How it's built

Starts on
Another system calling it
Steps
23, with 3 branches
Size
Large: read it before trusting it with anything live
Connects to
Pinecone, Postgres, Redis
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 Pinecone, Postgres and Redis 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 23 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 23 steps before you point it at anything that matters.