AutocompleteEngine
AutocompleteEngine is Brinicle’s high-level engine for autocomplete and suggestion search.
Use it for:
- query suggestions
- title suggestions
- product-name suggestions
- category suggestions
- curated search phrases
AutocompleteEngine uses the same disk-first HNSW infrastructure as the other Brinicle engines, but it encodes suggestion text internally before indexing and searching.
It supports:
- build
- insert
- upsert
- delete
- single-query search
- batch search
- search with distances
- compact rebuild
- graph optimization
When to Use Autocomplete
UseAutocompleteEngine when you need:
- Search-as-you-type — suggest completions as users type in a search box
- Popular query suggestions — index and serve frequently searched queries
- Title suggestions — autocomplete item titles from your catalog
- Category suggestions — suggest category names as users browse
Constructor
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
index_path | str/Path | required | Base path for the index files |
dim | int | 48 | Dimension used for encoded autocomplete tokens |
tokenizer_path | str/Path/None | None | Optional custom tokenizer path |
text_prep | None | None | Optional text preprocessing |
delta_ratio | float | 0.10 | Maintenance threshold for delta and deleted records |
M | int | 16 | HNSW graph connectivity |
ef_construction | int | 200 | Build-time search width |
ef_search | int | 64 | Default query-time search width |
build_n_threads | int | 1 | Number of build threads |
seed | int | 0 | Random seed for graph construction |
autocomplete_config | AutocompleteConfig/None | None | Optional autocomplete scoring configuration |
Suggestion Format
Each suggestion has anexternal_id and a text value.
text value is encoded and indexed.
The external_id is what search returns. It can be the suggestion text itself, an item ID, a query ID, or any caller-defined identifier.
Example with separate IDs:
Ingest Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
external_id | str | required | ID returned by search for this suggestion |
text | str | required | The suggestion text to index |
normalize | bool | True | Whether to normalize text before encoding |
How Autocomplete Scoring Works
Autocomplete search is prefix-oriented. Brinicle compares query tokens with suggestion tokens from the beginning of the text. Earlier token matches matter more than later token matches. Example:Query Length and Thresholds
AutocompleteEngine works cautiously. It usually gives clearer results when the query contains at least one complete term.
Very short partial inputs such as:
threshold to filter weak or irrelevant suggestions:
Building an Autocomplete Index
Searching
Basic Search
Usesearch(...) to return suggestion IDs.
Search with Distance
Usesearch_with_distance(...) to return suggestion IDs and distances.
Search Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
query | str | required | Search query (partial text) |
k | int | 10 | Maximum number of suggestions |
efs | int/None | None | Query-time search width |
threshold | float | inf | Maximum accepted distance |
normalize | bool | True | Whether to normalize encoded query values |
efs usually improves recall, but increases query latency.
Batch Search
Usesearch_batch(...) to search multiple autocomplete queries.
n_jobs controls parallel query execution when parallel execution is available.
Insert
Useinsert mode to add new suggestions to an existing index.
Upsert
Useupsert mode to replace existing suggestions or insert new ones.
Delete
Usedelete_items(...) to delete suggestions by external ID.
return_not_found=False, the second returned value is None.
Deletes are logical until compact rebuild.
Autocomplete Scoring Configuration
UseAutocompleteConfig when you want direct control over autocomplete scoring.
AutocompleteConfig has separate build-time and search-time parameters.
Build-time parameters affect graph construction.
Search-time parameters affect query ranking.
Available AutocompleteConfig Fields
| Field | Type | Default | Description |
|---|---|---|---|
build_position_decay | float | — | Controls how much later token positions matter during graph construction |
search_position_decay | float | — | Controls how much later token positions matter during search |
build_length_penalty | float | — | Length penalty used during graph construction |
search_length_penalty | float | — | Penalizes suggestions that are much longer than the query during search |
Tuning Tips
position_decay controls how quickly later token positions lose importance.
Lower values make early tokens much more important.
Higher values make later tokens matter more.
length_penalty controls how strongly longer suggestions are penalized.
Higher values make autocomplete stricter toward long suggestions.
Lower values allow longer completions more easily.
Rebuild and Optimize
Autocomplete indexes use the same maintenance model asVectorEngine.
Close and Destroy
Close loaded index resources:destroy() removes the index from disk.
Complete API Reference
init
build, insert, upsert
ingest
finalize
search
search_with_distance
(external_id, distance) pairs.