İçeriğe geç
YENİAlaaddin ile tanış: sesi olan yapay zekâ cinin. trig8n 1 Ocak 2027'de yayında. Yeniliklere bak

Kütüphane / RAG ve Bilgi Bankaları

RAG ve Bilgi Bankaları

Serve a RAG chat backend for Next.js using OpenAI, Redis, and Pinecone

When an API call/webhook arrives, it answers questions from your own knowledge base with OpenAI / ChatGPT using Pinecone, Postgres, Redis.

Ne yapar

## n8n as a Backend for Next.js — RAG Agent API This workflow IS the backend for a Next.js app's AI feature. Next.js never calls an LLM or a vector DB directly — it POSTs a chat/query request to this webhook, and n8n does everything server-side: validates the request, checks a short-TTL cache, retrieves relevant chunks from a vector store, runs an agent (LLM + retrieval tool + optional live tools) with per-conversation memory, persists the exchange, and — because this is n8n calling back into Next.js rather than the other way around — tells Next.js which ISR paths/tags just went stale so the app's cached pages (e.g. a public answers/knowledge-base page fed by this same content) revalidate automatically. The webhook responds to the browser immediately after the agent finishes; the Next.js revalidation call happens out-of-band and never blocks the user's response. ### How it works 1. Webhook - RAG Agent Request receives POST /rag-agent-query from a Next.js Server Action or Route Handler (never from the browser directly — see auth note below) 2. Set - Config centralizes the vector store index, embedding/chat models, cache TTL, Next.js revalidation URL + secret, and validation limits 3. Code - Validate Request Schema is a hand-rolled Zod-style validator: checks types, required fields, string length caps, and enum membership for every input field, and short-circuits straight to a typed 400 error response on any failure — the agent and vector store are never touched for a malformed request 4. IF - Validation Passed splits: failures go directly to Respond - Validation Error (400); valid requests continue 5. Code - Build Cache Key derives a deterministic hash from (conversationId-less) normalized query + namespace, for semantically-dumb but cheap exact-match caching 6. Redis - Check Query Cache looks up that key; IF - Cache Hit skips retrieval + the agent entirely and serves the cached answer straight back for identical repeated queries 7. On a cache miss: Embeddings - OpenAI turns the query into a vector; Vector Store - Retrieve Context (Pinecone/Qdrant-style) pulls the top-k relevant chunks, scoped to the tenant/namespace from the request 8. AI Agent - RAG Assistant (LLM + Window Buffer Memory keyed by conversationId, + Tool - Search Knowledge Base as a callable retrieval tool) answers using the retrieved context, can re-query the knowledge base with a refined que

Adımlar

  1. Webhook - RAG Agent Request
  2. Set - Config
  3. Code - Validate Request Schema
  4. IF - Validation Passed
  5. Respond - Validation Error (400)
  6. Code - Build Cache Key
  7. Redis - Check Query Cache
  8. IF - Cache Hit
  9. Respond - Success (Cached)
  10. Tool - Search Knowledge Base
  11. OpenAI Chat Model
  12. Window Buffer Memory
  13. AI Agent - RAG Assistant
  14. Code - Parse & Validate Agent Output

Toplam 23 adım.

Benzer otomasyonlar