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

# Segment users with rule contexts

> Learn how to segment users with rule contexts.

Segments are groups of users that share common characteristics or behaviors.
By grouping users into segments with [`ruleContexts`](/doc/api-reference/api-parameters/ruleContexts),
you can better personalize their experience.

## Identify the user segments

Before you can personalize segments, you need to identify the segments your users belong to.
This lets you group users by criteria relevant to your organization.

For example, you might categorize users by device type, such as those who prefer mobile or desktop.
You might also categorize users by location, such as those from France, Canada, or Japan.

## Create contextual rules with segments

Once you've identified your user segments, create contextual rules for them.
Contextual rules let you adjust search results based on a segment used as a [context](/doc/guides/managing-results/rules/rules-overview/how-to/customize-search-results-by-platform).

## Assign a segment context at query time

When a user starts a search, consider the segment they belong to and treat it as a context.

* [`ruleContexts` with InstantSearch](/doc/guides/managing-results/rules/rules-overview/how-to/customize-search-results-by-platform#assign-context-with-instantsearch)
* [`ruleContexts` with an API client](/doc/guides/managing-results/rules/rules-overview/how-to/customize-search-results-by-platform#assign-context-with-an-api-client)
