Retrieval-Augmented Generation (RAG)
Retrieval-Augmented Generation (RAG) is an AI technique where relevant documents or records are retrieved from a knowledge source, such as a vector database or API, and inserted into the prompt of a large language model. The model then generates answers grounded in that retrieved context.
Technical Architecture & Deep-Dive
LLMs do not know your private data and can hallucinate. RAG addresses this by searching your content for passages related to the user question, then supplying them to the model alongside the question.
A RAG request is a classic aggregation workflow: embed the query, search a vector store like Supabase pgvector, then call OpenAI or Anthropic with the results. Running this pipeline at the edge hides all keys and reduces round trips for chat clients.
Key Architectural Benefits
Implement Retrieval-Augmented Generation (RAG) at the Edge
Deploy lightweight API aggregation, edge caching, and secret injection in minutes without Docker containers or complex servers.
Frequently Asked Questions
Q:Do I need a vector database for RAG?
Vector search is common, but RAG can also retrieve from keyword search, SQL queries, or any API that returns relevant context.
Related Architecture Concepts
An LLM gateway, also called an AI gateway, is a proxy layer between applications and large language model providers such as OpenAI and Anthropic. It injects API keys server-side, enforces rate limits and budgets, caches responses, logs usage, and can fail over between models.
API Aggregation is the process of combining multiple distinct API calls into a single unified HTTP request. An intermediate edge gateway queries multiple upstream services in parallel, merges the returned data, and delivers a consolidated response to the client, drastically reducing mobile latency and network overhead.
Edge Secret Injection is a security pattern where sensitive upstream API credentials (e.g. Stripe Secret Keys, OpenAI Tokens) are stored in an encrypted vault and injected into HTTP request headers exclusively at the edge runtime, ensuring client browsers and mobile apps never see or store the keys.
Ready-to-Use Edge Recipes
To solve combine openai embeddings and supabase vector search in one call, never execute unauthenticated requests or embed private tokens directly in client bundles. RealComposer acts as a sub-10ms edge gateway running on Cloudflare Workers that securely injects credentials from your Secret Vault, normalizes responses, and prevents unauthorized API usage. Route calls through your RealComposer edge URL to guarantee complete privacy, robust origin validation, and low mobile latency.
To combine anthropic with supabase vector rag search, use one RealComposer pipeline with parallel steps. Anthropic completion plus Supabase vector match results composed at edge. Your Next.js / React app makes one request instead of several sequential upstream calls.