A query encoder converts a user question into a vector representation that supports similarity search over indexed document vectors. In a RAG system, it forms the retrieval boundary: the encoded query selects passages, which the generator then uses with the original question to produce an answer. section 4.1 section 4.6
Figure 4.3 An end-to-end RAG pipeline for question answering, in which a user question is embedded for vector search, top-k documents are retrieved, and a generator produces an answer using the retrieved context.

Trace the online path from a user question through query embedding and top-k retrieval to answer generation. section 4.6
Separate the query encoder’s online role from the document-side and training-side decisions:
- At query time, encode the question, search the vector index, retrieve document chunks, and pass them with the question to the generator. section 4.6
- In canonical RAG, keep the document encoder and prebuilt index fixed while fine-tuning the query encoder alongside the generator. section 4.1
- For low-data adaptation, query-side fine-tuning is efficient and can regularize against overfitting by leaving the document encoder unchanged. section 6.5
A basic retrieval call
A RAG question-answering function passes a question to similarity search, joins the returned passages as context, and invokes the generator. The query encoder is implicit in the configured embedding and vector-store components; the returned page numbers support inspection of retrieval quality. section 4.6
