This page describes how retrieval and ranking work together to deliver relevant
search results in Agent Search apps.

## Overview

In short, retrieval is finding relevant documents, while ranking is
ordering those retrieved documents. Ranking all the available documents
can be computationally expensive. Therefore, retrieval and ranking work
sequentially.

First, the search model understands the query and rewrites it.
Then, depending on the data sources available and the number of indexed
documents in your data store, the model
retrieves documents in the order of thousands. A relevance score is assigned to
the retrieved documents.

The ranking model then orders the retrieved documents
and serves the top 400 ranked results. The following image shows how
these two processes fit into the search workflow.
![retrieval and ranking in search](https://docs.cloud.google.com/generative-ai-app-builder/images/generic-search-overview.svg) **Figure 1.** Retrieval and ranking in search workflow

## Retrieval methods

Retrieval is the process of selecting a subset of documents from your data store
that are relevant to a user's query. Agent Search model
manages retrieval for your search apps based on different signals, such as the
following, and assigns relevance scores:

- **Topicality**: Includes keyword matching, knowledge graphs, and web
  signals.

- **Embeddings**: Includes embeddings to find conceptually similar content.

- **Cross-attention**: Allows a model to consider the relationship between a
  query and a document to assign a relevance score to the document.

- **Freshness**: Involves ascertaining the age of the documents in the data
  store.

- **User events**: Includes conversion signals used for personalization.

Additionally, in a search request, you can supply
[relevance filters](https://docs.cloud.google.com/generative-ai-app-builder/docs/filter-by-relevance.md.txt) and
metadata filters for [website data](https://docs.cloud.google.com/generative-ai-app-builder/docs/filter-website-search.md.txt)
and [structured or unstructured data](https://docs.cloud.google.com/generative-ai-app-builder/docs/filter-search-metadata.md.txt) to
narrow down the list of relevant documents.

## Ranking methods

Ranking takes the documents that are selected during the retrieval phase,
assigns them a new relevance score according to the following conditions, and
reorders them:

- **Boost** : Promotes and demotes certain results according to custom attributes or freshness. This impacts the first 1,000 retrieved documents and ranks the top 400. For more information, see [Boost search results](https://docs.cloud.google.com/generative-ai-app-builder/docs/boost-search-results.md.txt).
- **Custom ranking** : Controls, tunes, and overrides the default ranking logic with a formula-based ranking algorithm to suit your specific requirements. The relevance score that custom ranking assigns takes a precedence when serving the results. For more information, see [Customize search results ranking](https://docs.cloud.google.com/generative-ai-app-builder/docs/custom-ranking.md.txt).
- **Ordering**: Applies ordering instructions, for example, by date.
- **Search tuning** : Impacts how the model perceives the semantic relevance of your documents and changes the embedding relevance scores. For more information, see [Improve search results with search tuning](https://docs.cloud.google.com/generative-ai-app-builder/docs/tune-search.md.txt).
- **Event-based reranking**: Updates the results at the time of serving using user-events-based personalization model.