<!-- Source: https://docs.squirro.com/en/latest/technical/search/features/typeahead.html -->
# Typeahead Suggestions

Profiles: Project Creator, Search User

The search bar within Squirro Cognitive Search offers a rich set of suggestions out of the box. Upon activation, it immediately provides a rich set of suggestions, even before any inputs.

[![Search Suggestions Before Inputs](https://s3.amazonaws.com/download.squirro.net/docs/technical/search/search-suggestions-before-1721107038.png)](https://s3.amazonaws.com/download.squirro.net/docs/technical/search/search-suggestions-before-1721107038.png)

By default, the search offers the users suggestions as they type, based on configurable settings the project creator can adjust.

[![Search Suggestions During Inputs](https://s3.amazonaws.com/download.squirro.net/docs/technical/search/search-suggestions-during-1721107803.png)](https://s3.amazonaws.com/download.squirro.net/docs/technical/search/search-suggestions-during-1721107803.png)

After performing a search, new suggestions appear based on the context of the initial query. This feature ensures that the recommendations are more relevant and dynamically updated. By continuously refining the suggestions based on user input, the user experience becomes more intuitive and efficient.

[![Search Suggestions During Inputs](https://s3.amazonaws.com/download.squirro.net/docs/technical/search/search-suggestions-after-1721111958.png)](https://s3.amazonaws.com/download.squirro.net/docs/technical/search/search-suggestions-after-1721111958.png)

## Based on Document Features

Typeahead suggestions can come from three different sources:

- Content (Key Phrases), as described on this page.
- Document title.
- [Labels](../../data-loading/labels.md#data-loading-labels) and their values.
- [Communities](../../communities/index.md#communities).

### Content-based Typeahead

Squirro provides search completion based on document features. This is in addition to the typeahead based on label values.

#### Features

- Matching on key-phrases
- Fuzzy phrase-term matching

  - Optional enforcing of in-order term matching
  - Support for phrase slop: maximum number of intervening unmatched positions

    [![image32](https://s3.amazonaws.com/download.squirro.net/docs/migrated-attachments/2396061784/2396356885.png)](https://s3.amazonaws.com/download.squirro.net/docs/migrated-attachments/2396061784/2396356885.png)

#### Setup

To enable the content-based typeahead, add the `NLP Keyphrase Tagger` (see [Discover (NLP Tagger) Pipeline Step](../../data-processing/pipeline-steps/discover.md#pipeline-steps-discover)) step to the corresponding pipeline.

Add the `NLP Keyphrase Tagger` pipelet (found in the `Discover` section) to a pipeline workflow:

[![image33](https://s3.amazonaws.com/download.squirro.net/docs/migrated-attachments/2396061784/2455896322.png)](https://s3.amazonaws.com/download.squirro.net/docs/migrated-attachments/2396061784/2455896322.png)

This enrichment creates a hidden label `nlp_tag__phrases` which contains the extracted key phrases:

[![image34](https://s3.amazonaws.com/download.squirro.net/docs/migrated-attachments/2396061784/2396389536.png)](https://s3.amazonaws.com/download.squirro.net/docs/migrated-attachments/2396061784/2396389536.png)

## Based on User Interaction

- User’s Saved Searches
- User’s Search History
- Popular queries (see [Popular Query Suggestions](popular-query.md#search-popular-query)) across the project (or for a single user).
- User’s Collections

## Using SquirroClient

All suggestions can be accessed programmatically via the [SquirroClient (Python SDK)](../../api/squirro_client/index.md#squirro-client).

For this, see [`TopicApiBaseMixin`](../../../api/squirro_client.topic.TopicApiBaseMixin.md#squirro_client.topic.TopicApiBaseMixin), specifically [`get_typeahead_suggestions()`](../../../api/squirro_client.topic.TopicApiBaseMixin.md#squirro_client.topic.TopicApiBaseMixin.get_typeahead_suggestions).

## Configuration

Typeahead Suggestions can be configured in Setup > Settings > Project Configuration.

You can configure what typeahead suggesters to use at different search states.

Project Configuration `frontend.userapp.search.typeahead-suggesters`

For the full list of suggesters and their descriptions, see the [`get_typeahead_suggestions()`](../../../api/squirro_client.topic.TopicApiBaseMixin.md#squirro_client.topic.TopicApiBaseMixin.get_typeahead_suggestions) method.

## Suggestions Based on Document Content

Project Configuration `topic.typeahead.content.configuration`

**`pydantic model ContentTypeaheadConfig`**

Content-based Typeahead configuration.

For more information about the Typeahead Suggestions feature in Squirro see:
[https://docs.squirro.com/en/latest/technical/search/features/typeahead.html](https://docs.squirro.com/en/latest/technical/search/features/typeahead.html)

Fields

- [`fuzziness (str)`](#squirro.common.config_schema.typeahead.ContentTypeaheadConfig.fuzziness)
- [`fuzzy_max_expansions (int)`](#squirro.common.config_schema.typeahead.ContentTypeaheadConfig.fuzzy_max_expansions)
- [`fuzzy_prefix_length (int)`](#squirro.common.config_schema.typeahead.ContentTypeaheadConfig.fuzzy_prefix_length)
- [`highlighter (squirro.common.config_schema.typeahead.TypeaheadHighlighter)`](#squirro.common.config_schema.typeahead.ContentTypeaheadConfig.highlighter)
- [`in_order (bool)`](#squirro.common.config_schema.typeahead.ContentTypeaheadConfig.in_order)
- [`slop (int)`](#squirro.common.config_schema.typeahead.ContentTypeaheadConfig.slop)
- [`terminate_after (int)`](#squirro.common.config_schema.typeahead.ContentTypeaheadConfig.terminate_after)

**`field fuzziness: str = 'AUTO'`**

Specifies the maximum edit distance allowed for matching. The fuzziness parameter can be specified as: 0, 1, 2: The maximum allowed Levenshtein Edit Distance (or number of edits), AUTO: Generates an edit distance based on the length of the term.

**`field fuzzy_max_expansions: int = 1`**

Maximum number of variations created.

**`field fuzzy_prefix_length: int = 2`**

Number of beginning characters left unchanged when creating expansions.

**`field highlighter: TypeaheadHighlighter = TypeaheadHighlighter.UNIFIED`**

Highlighter type.

**`field in_order: bool = False`**

Require matched spans to be in-order.

**`field slop: int = 6`**

Maximum number of intervening unmatched positions.

**`field terminate_after: int = 100000`**

Tradeoff between accurate matching and speed. The typeahead search request gets terminated after N matching documents (per shard) are found. Potentially higher scoring results may be missed out.

## Suggestions Based on Document Title

Project Configuration `topic.typeahead.title.configuration`

**`pydantic model TitleTypeaheadConfig`**

Title-based Typeahead configuration.

For more information about the Typeahead Suggestions feature in Squirro see:
[https://docs.squirro.com/en/latest/technical/search/features/typeahead.html](https://docs.squirro.com/en/latest/technical/search/features/typeahead.html)

Fields

- [`enabled (bool)`](#squirro.common.config_schema.typeahead.TitleTypeaheadConfig.enabled)
- [`fuzziness (str)`](#squirro.common.config_schema.typeahead.TitleTypeaheadConfig.fuzziness)
- [`fuzzy_max_expansions (int)`](#squirro.common.config_schema.typeahead.TitleTypeaheadConfig.fuzzy_max_expansions)
- [`fuzzy_prefix_length (int)`](#squirro.common.config_schema.typeahead.TitleTypeaheadConfig.fuzzy_prefix_length)
- [`highlighter (squirro.common.config_schema.typeahead.TypeaheadHighlighter)`](#squirro.common.config_schema.typeahead.TitleTypeaheadConfig.highlighter)
- [`in_order (bool)`](#squirro.common.config_schema.typeahead.TitleTypeaheadConfig.in_order)
- [`query_builder (squirro.common.config_schema.typeahead.TitleTypeahedQueryBuilder)`](#squirro.common.config_schema.typeahead.TitleTypeaheadConfig.query_builder)
- [`slop (int)`](#squirro.common.config_schema.typeahead.TitleTypeaheadConfig.slop)
- [`terminate_after (int)`](#squirro.common.config_schema.typeahead.TitleTypeaheadConfig.terminate_after)

**`field enabled: bool = True`**

Enable title based typeahead suggestions

**`field fuzziness: str = 'AUTO'`**

Specifies the maximum edit distance allowed for matching. The fuzziness parameter can be specified as: 0, 1, 2: The maximum allowed Levenshtein Edit Distance (or number of edits), AUTO: Generates an edit distance based on the length of the term.

**`field fuzzy_max_expansions: int = 1`**

Maximum number of variations created.

**`field fuzzy_prefix_length: int = 2`**

Number of beginning characters left unchanged when creating expansions.

**`field highlighter: TypeaheadHighlighter = TypeaheadHighlighter.UNIFIED`**

Highlighter type.

**`field in_order: bool = False`**

Require matched spans to be in-order. This option is applicable only to the ‘span’ query builder.

**`field query_builder: TitleTypeahedQueryBuilder = TitleTypeahedQueryBuilder.SPAN`**

The type of query builder to be used. If set to ‘span’ the span near query will be utilized. If set to ‘match’, the match query will be built. This option is intended for advanced users who understand its implications.

**`field slop: int = 6`**

Maximum number of intervening unmatched positions. This option is applicable only to the ‘span’ query builder.

**`field terminate_after: int = 100000`**

Tradeoff between accurate matching and speed. The typeahead search request gets terminated after N matching documents (per shard) are found. Potentially higher scoring results may be missed out.

## Suggestions Based on Label Values

Project Configuration `topic.typeahead.facetvalue.configuration`

```text
{
    "terminate_after": string,
    "sample_shard_size": int,
    "aggregation_method": "significant_terms",
    "community_drill_down": {
        "enabled": true,
        "for_top_n": 1
    }
}
```

**`terminate_after`**

Type: int

Required: False

Default: 15000

Tradeoff between accurate matching and speed.
The typeahead search request gets terminated after N matching documents (per shard) are found.
Potentially higher scoring results may be missed out.

**`sample_shard_size`**

Type: int

Required: False

Default: 100

Facet Value suggestions is based on the Terms aggregation on the matching subset of Items.
The sample_shard_size parameter limits how many top-scoring documents are collected in the sample processed on each shard.
Lower values tend to return label-value suggestions faster (but with less accurate order) and tightens the focus to high-relevance matches rather than the potentially very long tail of low-quality matches.

**`aggregation_method`**

Type: string

Required: False

Default: significant_terms

Choose between `significant_terms` or `terms` aggregation to find best matching label values.

**`community_drill_down`**

Type: json

Required: False

Enable drilling down of top-ranked communities by setting `community_drill_down.enabled:true`
