LLM Learning Hub

workspace/llm-course/home

Retrieval

Retrieval is the end-to-end step of embedding a user query, searching the vector store, and returning the top-k relevant chunks that will be inserted into the LLM prompt as grounding context.

What is Retrieval?

Retrieval is the end-to-end step of embedding a user query, searching the vector store, and returning the top-k relevant chunks that will be inserted into the LLM prompt as grounding context.

Retrieval is the end-to-end step of embedding a user query, searching the vector store, and returning the top-k relevant chunks that will be inserted into the LLM prompt as grounding context.

Where is it used?

LangChain `retriever.get_relevant_documents(query)` and LlamaIndex `index.as_retriever().retrieve(query)` wrap this step; production systems add hybrid search and reranking on top.

How to build it

Create `retriever = vectorstore.as_retriever(search_kwargs={"k": 5})`, call `docs = retriever.invoke(query)`, and concatenate `doc.page_content` for each result into a context string.