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
- Webhook - RAG Agent Request
- Set - Config
- Code - Validate Request Schema
- IF - Validation Passed
- Respond - Validation Error (400)
- Code - Build Cache Key
- Redis - Check Query Cache
- IF - Cache Hit
- Respond - Success (Cached)
- Tool - Search Knowledge Base
- OpenAI Chat Model
- Window Buffer Memory
- AI Agent - RAG Assistant
- Code - Parse & Validate Agent Output
Toplam 23 adım.
Benzer otomasyonlar
RAG ve Bilgi BankalarıStore persistent AI agent memory with Claude, Voyage AI, Postgres, and Redis41 adımRAG ve Bilgi BankalarıRAG ajanı için YouTube transkriptlerini Pinecone'a yükleme15 adımRAG ve Bilgi BankalarıPinecone RAG ile GitHub OpenAPI spesifikasyonuyla sohbet etme14 adımKod, Git ve Geliştirici AraçlarıOpenAI destekli Chrome eklentisi arka ucu23 adım