> ## Documentation Index
> Fetch the complete documentation index at: https://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 based on criteria that are relevant to your organization.

For example, you might categorize users based on their device type, such as those who favor mobile or desktop devices
Additionally, you might also categorize users by their location such as those from different countries like France, Canada, or Japan.

## Create contextual rules with segments

Once you've identified your user segments, the next step is to 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 initiates 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)
