Usage Pattern

Get Started

Get a retriever from index:

retriever = index.as_retriever()

Retrieve relevant context for a question:

nodes = retriever.retrieve('Who is Paul Graham?')

Note: To learn how to build an index, see Index

High-Level API

Selecting a Retriever

You can select the index-specific retriever class via retriever_mode. For example, with a ListIndex:

retriever = list_index.as_retriever(

This creates a ListIndexLLMRetriever on top of the list index.

See Retriever Modes for a full list of (index-specific) retriever modes and the retriever classes they map to.

Configuring a Retriever

In the same way, you can pass kwargs to configure the selected retriever.

Note: take a look at the API reference for the selected retriever class’ constructor parameters for a list of valid kwargs.

For example, if we selected the β€œllm” retriever mode, we might do the following:

retriever = list_index.as_retriever(

Low-Level Composition API

You can use the low-level composition API if you need more granular control.

To achieve the same outcome as above, you can directly import and construct the desired retriever class:

from llama_index.indices.list import ListIndexLLMRetriever

retriever = ListIndexLLMRetriever(