Skip to content

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.

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.

  1. Input: one query.
  2. Output: a ranked list of Document objects.
  3. Metadata: enough provenance to cite and authorize every result.
  4. Evaluation: answer-bearing evidence appears within the chosen k.

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.

Embeddings and vector stores · Callbacks and tracing · RAG evaluation