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

# RAG lifecycle

> How AutoSage retrieves private knowledge-base content and returns cited answers.

Retrieval-augmented generation (RAG) grounds an answer in the documents stored in a knowledge base. AutoSage searches at query time, gives the model only the most relevant passages, and returns source metadata with the answer.

## Retrieval boundaries

Every knowledge base has an isolated retrieval boundary. A search is always executed against the knowledge base selected for the chat or agent, so passages from another knowledge base are not mixed into the result.

<Info>
  Tenant isolation controls who can reach a knowledge base; the knowledge-base partition controls what can be retrieved. See [Tenancy](/developers/concepts/tenancy) for the full hierarchy.
</Info>

## From question to source

<Steps>
  <Step title="Discover available data">
    The runtime receives a short preview of processed document summaries and connected data. This helps it decide what to search without placing the full corpus in the prompt.
  </Step>

  <Step title="Form a search">
    In Deep mode, the agent decides when and how to search. It can refine the query and search more than once as it learns from earlier results.
  </Step>

  <Step title="Retrieve passages">
    AutoSage embeds the search query and finds the most semantically relevant passages in the knowledge base's private partition.
  </Step>

  <Step title="Organize context">
    Results are deduplicated, grouped by document, and can be expanded to nearby pages when more context is useful.
  </Step>

  <Step title="Answer with citations">
    The passages return to the agent as tool results. The final response uses them as evidence and includes source references.
  </Step>
</Steps>

Quick mode uses a direct, single-pass retrieval path. Deep mode can repeat the lifecycle until it has enough evidence or reaches the run's step limit. See [Agent runtime](/developers/concepts/runtime).

## Search filters

The retrieval tool can narrow a search when the model or your query already identifies the likely source:

| Filter    | Use                                    |
| --------- | -------------------------------------- |
| Document  | Search one document by identifier      |
| Filename  | Focus on a named source                |
| Page      | Retrieve a specific page or page range |
| File type | Limit results to a document format     |

Source objects carry enough metadata to present useful citations, including the document identifier, filename, and page information when the source format provides it.

## Connected databases

In Deep mode, connected databases complement document RAG. The agent can inspect available tables, run read-only SQL, and build charts from query results. Database results remain a separate tool result from document passages, so your client can present each source type appropriately.

## Empty knowledge bases

A new knowledge base with no processed documents returns no passages. The runtime is told that there is nothing available to search, so it can answer from general reasoning when appropriate or ask for source documents.

<Note>
  Only documents with a `processed` status are searchable. Wait for ingestion to finish before evaluating retrieval quality.
</Note>

## Improving retrieval quality

<Tip>
  Upload the original, well-titled source files instead of pasting very large blocks of text into a prompt. Clear headings, meaningful filenames, and focused sections give the ingestion pipeline better boundaries for chunking and retrieval.
</Tip>

For document processing details, see [Ingestion lifecycle](/developers/lifecycles/ingestion) and the [upload guide](/developers/guides/upload-documents).

## Next steps

<CardGroup cols={2}>
  <Card title="Knowledge bases" icon="book" href="/knowledge-bases/overview">
    Organize source documents, connected data, prompts, and agents.
  </Card>

  <Card title="Agent runtime" icon="robot" href="/developers/concepts/runtime">
    Understand the multi-step tool loop around retrieval.
  </Card>
</CardGroup>
