Retrieval-augmented generation: ground the LLM in your private data by retrieving relevant chunks and injecting them into the prompt.
How a RAG query becomes a grounded answer
Step 1 of 5
Embed query
The API turns the question into an embedding with the same model used at ingestion. A mismatch between the two embedding models silently ruins retrieval.
Step 2 of 5
Vector search
The retriever asks the vector database for the closest chunks, for example the 20 nearest. Similar is not the same as relevant, so these are only candidates.
Step 3 of 5
Rerank
A cross-encoder reads the query and each candidate together and re-scores them. Only the best few survive, which keeps the context window small and on topic.
Step 4 of 5
Build context
The surviving chunks are placed in the prompt with source ids, plus an instruction to answer only from them and to say so when the context has no answer.
Step 5 of 5
Generate
The model writes the answer from the supplied context and cites the chunk ids. The API returns it to the UI, where each citation can link back to its source.
The model never sees your database; retrieval decides which chunks it gets to read.
clientservicemodeldatabaseagentexternal
Explanation
The query is embedded and used to search a vector database for relevant chunks. Candidates are reranked by a cross-encoder, the top results become the LLM context, and the model generates a grounded answer with citations.