
What is RAG, in one paragraph?
Retrieval-augmented generation, or RAG, means searching your own content for passages relevant to a question and giving those passages to the model along with the question. The model answers from what it was handed instead of from memory, which makes answers current, specific to your business and traceable to a source.
What are the steps to build RAG on Supabase?
- Enable pgvector and create a table with the text, its metadata and a vector column.
- Chunk each document into passages of a few hundred words, keeping headings with their text.
- Embed each chunk with an embedding model and store the vector.
- Index the vector column so search stays fast as the table grows.
- Search at question time: embed the question and return the closest chunks.
- Answer by sending the question and those chunks to the model, and ask it to cite which chunk it used.
sqlcreate extension if not exists vector; create table documents ( id bigserial primary key, tenant_id uuid not null, content text not null, source text, embedding vector(1536) ); create index on documents using hnsw (embedding vector_cosine_ops);
What usually goes wrong?
- Chunks that cut a table or a list in half, so the answer is split across two passages.
- No metadata, so the search cannot filter by product, date or customer.
- Vector search alone. Exact terms such as part numbers need keyword search alongside it.
- No row-level security on the documents table, so one tenant's files can surface for another.
- No test set. Without thirty real questions and their correct answers, you cannot tell whether a change helped.
When is pgvector the right choice?
When your data is already in Postgres and your collection is in the range most business applications reach. Keeping vectors beside the rows they describe means one database to secure, back up and query. We compare the alternatives in our vector database comparison.
Frequently asked questions
What does pgvector do?
pgvector is a Postgres extension that adds a vector data type and similarity search. It lets you store embeddings in a normal table and find the rows closest in meaning to a query.
How big should RAG chunks be?
A few hundred words is a common starting point, split on headings and paragraphs instead of fixed character counts. Test with your own questions, because the best size depends on the documents.
Does RAG stop an AI from making things up?
It reduces it sharply when the model is told to answer only from the retrieved passages and to say when they do not contain the answer. It does not remove the need for testing.
Have a manual workflow that should be an agent?
Tell us the task. In 30 minutes we will tell you whether an AI tool or agent can take it over.
Book a 30-minute agent scoping callTurn Your Vision IntoReality
Get a free consultation and discover how we can accelerate your product development with AI-powered solutions.
Launch 40% Faster
AI-powered development reduces time-to-market significantly
Scale with Confidence
Built for growth with enterprise-grade architecture
24-Hour Response
We'll get back to you within 24 hours with a detailed proposal