> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bindai.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# 05.4 retrievers

# Retrievers

A **Retriever** is responsible for finding the most relevant information from a knowledge source before the language model generates a response.

Rather than searching every document, the retriever selects only the pieces of information that are most useful for answering the user's question.

Retrievers are the bridge between your knowledge base and the language model.

***

# What is a Retriever?

A retriever accepts a query and returns relevant documents or document chunks.

Conceptually:

```text id="h8v2pk" theme={null}
User Question

↓

Retriever

↓

Relevant Documents
```

The retrieved information is then included in the model prompt.

***

# Why Retrievers?

Knowledge bases can contain thousands or even millions of documents.

Sending all of that information to a language model is impossible because of context window limits.

Instead:

```text id="k4r7mt" theme={null}
Knowledge Base

↓

Retriever

↓

Top Results

↓

Language Model
```

Only the most relevant information is passed to the model.

***

# Retrieval Workflow

The complete retrieval process looks like this.

```text id="m3q8cn" theme={null}
User Question

↓

Embedding

↓

Vector Search

↓

Top K Results

↓

Language Model

↓

Final Response
```

The retriever coordinates this entire search process.

***

# Retriever Responsibilities

A retriever typically performs several tasks:

* receive a query
* generate a query embedding
* search the knowledge index
* rank results
* return the best matches

Some retrievers also filter results using metadata.

***

# Example

Knowledge base:

```text id="d6y4aw" theme={null}
Installation Guide

API Reference

FAQ

Troubleshooting Guide
```

User asks:

```text id="t5n9xe" theme={null}
How do I reset my password?
```

Retriever returns:

```text id="b7u1lr" theme={null}
FAQ

Password Recovery
```

Only that relevant section is included in the prompt.

***

# Top-K Retrieval

Most retrievers return the **K** most relevant results.

```text id="n2v6ph" theme={null}
Search Results

↓

1

2

3

4

5

↓

Top 3 Returned
```

Choosing the right value for **K** balances context quality with prompt size.

***

# Metadata Filtering

Retrievers can limit searches using document metadata.

Example:

```text id="f4z8yk" theme={null}
Category = Documentation

Version = 2.0

Language = English
```

Filtering helps avoid returning unrelated documents.

***

# Hybrid Retrieval

Some systems combine multiple search techniques.

```text id="x6m3jq" theme={null}
Keyword Search

+

Semantic Search

↓

Combined Ranking
```

Hybrid retrieval often improves accuracy by combining exact matches with semantic understanding.

***

# Custom Retrievers

Applications can implement their own retrieval strategies.

Examples include:

* SQL database search
* API-based retrieval
* Elasticsearch
* cloud search services
* graph databases
* enterprise search engines

BindAI allows retrievers to be replaced without changing agent logic.

***

# Using a Retriever

Conceptually, attach a retriever to an agent.

```python id="v9r5cb" theme={null}
agent.use_retriever(
    retriever,
)
```

During execution, the retriever supplies relevant context before the language model generates a response.

***

# Retriever vs Knowledge

Knowledge stores information.

Retrievers search that information.

| Knowledge        | Retriever         |
| ---------------- | ----------------- |
| Stores documents | Finds documents   |
| Persistent       | Runtime component |
| Data             | Search logic      |
| Repository       | Retrieval engine  |

Both are required for effective RAG systems.

***

# Performance

Retriever performance depends on:

* embedding quality
* vector database performance
* document chunk size
* search algorithm
* metadata filtering
* ranking strategy

Efficient retrieval is often more important than simply having a larger knowledge base.

***

# Best Practices

* Retrieve only the most relevant documents.
* Keep **K** relatively small.
* Use metadata filtering whenever possible.
* Combine semantic search with keyword search for better accuracy.
* Rank results before sending them to the language model.
* Monitor retrieval quality as your knowledge base grows.

***

# Summary

Retrievers are responsible for selecting the right information from a knowledge base.

By finding only the most relevant documents for each query, they keep prompts efficient, improve response accuracy, and enable BindAI agents to answer questions using large collections of external information.
