Retrievers
A retriever accepts an unstructured query and returns Document objects. It is broader than a vector store: it can wrap vector search, keyword search, an external API, or a custom fusion pipeline.
Tiny example
Section titled “Tiny example”retriever = vector_store.as_retriever( search_type="mmr", search_kwargs={"k": 4, "fetch_k": 20},)
documents = await retriever.ainvoke( "What is the refund window for damaged goods?")LangChain retrievers are Runnables, so the familiar invoke, ainvoke, and batch interfaces apply. Vector stores themselves do not subclass Runnable.
Remember the contract
Section titled “Remember the contract”- Input: one query.
- Output: a ranked list of
Documentobjects. - Metadata: enough provenance to cite and authorize every result.
- Evaluation: answer-bearing evidence appears within the chosen
k.
Failure note
Section titled “Failure note”Increasing k can hide poor recall while filling the prompt with irrelevant text. Apply permission filters before generation, log document IDs and scores, and evaluate retrieval separately from the final answer.
Related
Section titled “Related”Embeddings and vector stores · Callbacks and tracing · RAG evaluation