ltr 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/ARCHITECTURE.md +92 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE +21 -0
- data/README.md +186 -0
- data/docs/AGENTS.md +67 -0
- data/docs/aggregation-engines.md +80 -0
- data/docs/config.md +516 -0
- data/docs/data-contracts.md +94 -0
- data/docs/data-splits.md +34 -0
- data/docs/dataset-builder-steps.md +13 -0
- data/docs/dataset-csv.md +73 -0
- data/docs/dataset-enrichers.md +62 -0
- data/docs/errors.md +33 -0
- data/docs/feature-selection.md +108 -0
- data/docs/features.md +202 -0
- data/docs/glossary.md +56 -0
- data/docs/host-integration.md +128 -0
- data/docs/host-run-pipelines.md +48 -0
- data/docs/index.md +50 -0
- data/docs/inference.md +164 -0
- data/docs/label-transformers.md +242 -0
- data/docs/labels-from-behavior.md +94 -0
- data/docs/learning-to-rank.md +119 -0
- data/docs/metrics.md +166 -0
- data/docs/model-files.md +73 -0
- data/docs/optimization.md +72 -0
- data/docs/public-api.md +67 -0
- data/docs/rake-tasks.md +82 -0
- data/docs/relevance-grades.md +80 -0
- data/docs/run-locally.md +584 -0
- data/docs/run-on-aws.md +647 -0
- data/docs/training-objective.md +110 -0
- data/docs/ubi-documents.md +75 -0
- data/docs/ubi-logging.md +125 -0
- data/lib/ltr/README.md +28 -0
- data/lib/ltr/configuration/README.md +12 -0
- data/lib/ltr/configuration/config_loader.rb +326 -0
- data/lib/ltr/configuration/config_validator.rb +476 -0
- data/lib/ltr/configuration/configuration.rb +84 -0
- data/lib/ltr/configuration/example_config.yml +182 -0
- data/lib/ltr/data/README.md +20 -0
- data/lib/ltr/data/csv/README.md +9 -0
- data/lib/ltr/data/csv/typed_columns.rb +101 -0
- data/lib/ltr/data/csv.rb +126 -0
- data/lib/ltr/data/dataframe.rb +80 -0
- data/lib/ltr/data/dataset_loader.rb +29 -0
- data/lib/ltr/data/row_store.rb +188 -0
- data/lib/ltr/data/split_cache.rb +30 -0
- data/lib/ltr/data/splits.rb +86 -0
- data/lib/ltr/dataset_aggregation/README.md +32 -0
- data/lib/ltr/dataset_aggregation/aggregated_sqlite_loader.rb +64 -0
- data/lib/ltr/dataset_aggregation/cascade_actions.rb +58 -0
- data/lib/ltr/dataset_aggregation/column_name.rb +47 -0
- data/lib/ltr/dataset_aggregation/dataset_builder/README.md +15 -0
- data/lib/ltr/dataset_aggregation/dataset_builder/context.rb +159 -0
- data/lib/ltr/dataset_aggregation/dataset_builder/steps/README.md +16 -0
- data/lib/ltr/dataset_aggregation/dataset_builder/steps/behavioural_feature_builder.rb +77 -0
- data/lib/ltr/dataset_aggregation/dataset_builder/steps/dataset_filters.rb +29 -0
- data/lib/ltr/dataset_aggregation/dataset_builder/steps/label_creator.rb +125 -0
- data/lib/ltr/dataset_aggregation/dataset_builder/steps/negative_downsampler.rb +52 -0
- data/lib/ltr/dataset_aggregation/dataset_builder/steps/query_aggregator.rb +163 -0
- data/lib/ltr/dataset_aggregation/dataset_builder/steps/split_assigner.rb +76 -0
- data/lib/ltr/dataset_aggregation/dataset_builder/steps/ubi_joiner.rb +137 -0
- data/lib/ltr/dataset_aggregation/dataset_builder/steps/user_query_aggregator.rb +68 -0
- data/lib/ltr/dataset_aggregation/dataset_builder.rb +82 -0
- data/lib/ltr/dataset_aggregation/dataset_enricher.rb +168 -0
- data/lib/ltr/dataset_aggregation/dataset_finalizer.rb +116 -0
- data/lib/ltr/dataset_aggregation/dataset_pipeline.rb +113 -0
- data/lib/ltr/dataset_aggregation/dataset_saver.rb +79 -0
- data/lib/ltr/dataset_aggregation/derived_features.rb +45 -0
- data/lib/ltr/dataset_aggregation/display_positions.rb +25 -0
- data/lib/ltr/dataset_aggregation/dropped_events.rb +29 -0
- data/lib/ltr/dataset_aggregation/labels/README.md +18 -0
- data/lib/ltr/dataset_aggregation/labels/identity_label_transformer.rb +11 -0
- data/lib/ltr/dataset_aggregation/labels/label_transformer.rb +61 -0
- data/lib/ltr/dataset_aggregation/labels/log_plus_one_label_transformer.rb +18 -0
- data/lib/ltr/dataset_aggregation/labels/per_query_k_means_label_transformer.rb +141 -0
- data/lib/ltr/dataset_aggregation/labels/per_query_label_transformer.rb +52 -0
- data/lib/ltr/dataset_aggregation/labels/per_query_min_max_label_transformer.rb +27 -0
- data/lib/ltr/dataset_aggregation/labels/quantile_label_transformer.rb +73 -0
- data/lib/ltr/dataset_aggregation/labels/sqrt_label_transformer.rb +18 -0
- data/lib/ltr/dataset_aggregation/missing_hit_ids.rb +20 -0
- data/lib/ltr/dataset_aggregation/negative_rank.rb +15 -0
- data/lib/ltr/dataset_aggregation/sql/aggregate.sqlite.sql.erb +209 -0
- data/lib/ltr/dataset_aggregation/sqlite_aggregator.rb +167 -0
- data/lib/ltr/dataset_aggregation/sqlite_event_stager.rb +79 -0
- data/lib/ltr/dataset_aggregation/sqlite_query_stager.rb +148 -0
- data/lib/ltr/dataset_aggregation/sqlite_staging.rb +180 -0
- data/lib/ltr/dataset_aggregation/sqlite_ubi_data_loader.rb +91 -0
- data/lib/ltr/dataset_aggregation/ubi_data_loader.rb +138 -0
- data/lib/ltr/dataset_aggregation/ubi_data_loader_base.rb +147 -0
- data/lib/ltr/dataset_aggregation/ubi_query_fields.rb +54 -0
- data/lib/ltr/deploy/README.md +21 -0
- data/lib/ltr/deploy/artifacts/code/inference.py +371 -0
- data/lib/ltr/deploy/artifacts/code/requirements.txt +1 -0
- data/lib/ltr/deploy/feature_extractor.rb +94 -0
- data/lib/ltr/deploy/feature_store_deployer.rb +88 -0
- data/lib/ltr/deploy/local_deployer.rb +61 -0
- data/lib/ltr/deploy/model_packager.rb +90 -0
- data/lib/ltr/deploy/sagemaker_deployer.rb +85 -0
- data/lib/ltr/deploy/sagemaker_endpoint.rb +199 -0
- data/lib/ltr/deploy/ssm_feature_source.rb +35 -0
- data/lib/ltr/errors/README.md +16 -0
- data/lib/ltr/errors/configuration_error.rb +5 -0
- data/lib/ltr/errors/deploy_error.rb +5 -0
- data/lib/ltr/errors/error.rb +5 -0
- data/lib/ltr/errors/invalid_dataset_error.rb +5 -0
- data/lib/ltr/errors/missing_dependency_error.rb +5 -0
- data/lib/ltr/errors/sqlite_error.rb +14 -0
- data/lib/ltr/features/README.md +19 -0
- data/lib/ltr/features/encoders/README.md +10 -0
- data/lib/ltr/features/encoders/enriched_column_encoder.rb +77 -0
- data/lib/ltr/features/encoders/feature_encoder.rb +61 -0
- data/lib/ltr/features/feature_engineering.rb +194 -0
- data/lib/ltr/features/feature_transformer.rb +92 -0
- data/lib/ltr/features/float32_range.rb +20 -0
- data/lib/ltr/features/transform_steps.rb +34 -0
- data/lib/ltr/features/transform_store.rb +123 -0
- data/lib/ltr/inference/README.md +11 -0
- data/lib/ltr/inference/base.rb +52 -0
- data/lib/ltr/inference/local_reranker.rb +147 -0
- data/lib/ltr/inference/sagemaker_client.rb +62 -0
- data/lib/ltr/metrics/README.md +12 -0
- data/lib/ltr/metrics/metric_scores.rb +67 -0
- data/lib/ltr/metrics/metrics.rb +139 -0
- data/lib/ltr/optimize/README.md +25 -0
- data/lib/ltr/optimize/bayesian_optimizer.rb +212 -0
- data/lib/ltr/optimize/candidate_selector.rb +97 -0
- data/lib/ltr/optimize/cholesky_decomposition.rb +81 -0
- data/lib/ltr/optimize/expected_improvement.rb +33 -0
- data/lib/ltr/optimize/feature_selection/README.md +15 -0
- data/lib/ltr/optimize/feature_selection/greedy_backward.rb +38 -0
- data/lib/ltr/optimize/feature_selection/importance_ranked.rb +23 -0
- data/lib/ltr/optimize/feature_selection/rfe.rb +22 -0
- data/lib/ltr/optimize/feature_selection/strategy.rb +112 -0
- data/lib/ltr/optimize/feature_selection/trial.rb +39 -0
- data/lib/ltr/optimize/gaussian_process.rb +125 -0
- data/lib/ltr/optimize/optimization_dataset.rb +16 -0
- data/lib/ltr/optimize/optimize_features.rb +129 -0
- data/lib/ltr/optimize/optimize_hyperparameters.rb +165 -0
- data/lib/ltr/optimize/optimize_pipeline.rb +105 -0
- data/lib/ltr/optimize/search_space.rb +165 -0
- data/lib/ltr/optimize/update_config.rb +196 -0
- data/lib/ltr/ssm/README.md +11 -0
- data/lib/ltr/ssm/loader.rb +61 -0
- data/lib/ltr/ssm/parameter_paths.rb +19 -0
- data/lib/ltr/ssm/saver.rb +76 -0
- data/lib/ltr/support/README.md +13 -0
- data/lib/ltr/support/callable.rb +10 -0
- data/lib/ltr/support/optional_dependency.rb +31 -0
- data/lib/ltr/support/pipeline_result.rb +22 -0
- data/lib/ltr/support/pipeline_task.rb +81 -0
- data/lib/ltr/support/version.rb +7 -0
- data/lib/ltr/tasks/ltr.rake +24 -0
- data/lib/ltr/train/README.md +19 -0
- data/lib/ltr/train/deploy_gate.rb +77 -0
- data/lib/ltr/train/deploy_metric.rb +63 -0
- data/lib/ltr/train/eval_logger.rb +16 -0
- data/lib/ltr/train/evaluation_cache.rb +101 -0
- data/lib/ltr/train/modelling_pipeline.rb +82 -0
- data/lib/ltr/train/optimization_split_report.rb +54 -0
- data/lib/ltr/train/utils.rb +35 -0
- data/lib/ltr/train/xgb_evaluator.rb +96 -0
- data/lib/ltr/train/xgb_trainer.rb +154 -0
- data/lib/ltr/ubi.rb +86 -0
- data/lib/ltr.rb +61 -0
- data/scripts/seed_ubi.rb +75 -0
- metadata +346 -0
data/docs/data-splits.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Data splits
|
|
2
|
+
|
|
3
|
+
The dataset carries three splits: `train`, `val` and `test`. By the end of this page, you will know why every row for a query is put in the same split, how `split_ratios` and the top-level `seed` set the size of each split, and which config key picks the split that each stage reads.
|
|
4
|
+
|
|
5
|
+
## How queries are split
|
|
6
|
+
|
|
7
|
+
`SplitAssigner` groups the rows by `user_query`, so every row for a query is put in the same split. The model is therefore never tested on a query that it trained on. Two `qid` values that differ only in `additional_qid_fields` have the same query text, so they also share a split.
|
|
8
|
+
|
|
9
|
+
With `should_shuffle_data: true`, the queries are shuffled with the top-level `seed` before they are cut by `split_ratios`. The shipped ratios are 0.7, 0.15 and 0.15. `test` takes whatever queries are left after the `train` and `val` counts are rounded.
|
|
10
|
+
|
|
11
|
+
## Which split each stage reads
|
|
12
|
+
|
|
13
|
+
The diagram shows the shipped choices, and the table names the key that sets each one.
|
|
14
|
+
|
|
15
|
+
```mermaid
|
|
16
|
+
flowchart TB
|
|
17
|
+
Q["All queries"] -->|"shuffle with seed 1967"| S["Shuffled queries"]
|
|
18
|
+
S --> TR["70% train"]
|
|
19
|
+
S --> VA["15% val"]
|
|
20
|
+
S --> TE["15% test"]
|
|
21
|
+
TR --> FIT["Fit the trees"]
|
|
22
|
+
VA --> OPT["Feature and hyperparameter search"]
|
|
23
|
+
TE --> ES["Early stopping"]
|
|
24
|
+
TE --> REP["Reported metrics"]
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
| Stage | Config key | Shipped value |
|
|
28
|
+
|---|---|---|
|
|
29
|
+
| Fit the trees | always `train` | `train` |
|
|
30
|
+
| Feature and hyperparameter search | `optimization.split` | `val` |
|
|
31
|
+
| Early stopping | `training.early_stopping_split` | `test` |
|
|
32
|
+
| Reported metrics | `evaluation.split` | `test` |
|
|
33
|
+
|
|
34
|
+
If a configured split has no rows, the gem falls back to `test` and logs a warning. If `test` has no rows either, it raises `InvalidDatasetError`. See [Config](config.md#training).
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Dataset builder steps
|
|
2
|
+
|
|
3
|
+
This page explains the ordered steps that `DatasetBuilder` runs, which of them an alternative aggregation engine replaces, and how the cascade examination model decides each document's `impression_count`. The label target itself is in [Labels from behavior](labels-from-behavior.md).
|
|
4
|
+
|
|
5
|
+
`DatasetBuilder` (`lib/ltr/dataset_aggregation/dataset_builder.rb`) is the most involved component. It threads a shared `Context` (config + field names + split settings) through an ordered chain of step objects under `dataset_builder/steps/`, mutating/replacing a working dataset and clearing intermediates as it goes to bound memory:
|
|
6
|
+
|
|
7
|
+
`UbiJoiner` → `QueryAggregator` → `UserQueryAggregator` → `NegativeDownsampler` (`ruby` engine, when `negative_downsample_ratio` is set) → **`DatasetFinalizer`**: split off the negatives (rows with no impressions, when `cascade_cutoff` is `false`) → `LabelCreator` → label transformer → append the negatives with label 0 → `DatasetFilters#filter_queries_below_min_documents` → `FeatureEncoder` → `FeatureEngineering` → `SplitAssigner` → `BehaviouralFeatureBuilder` → `FeatureTransformer`.
|
|
8
|
+
|
|
9
|
+
The first three steps are the aggregation — join, per-session cascade examination, cross-session aggregation — and are the only part an alternative engine replaces. Everything from `LabelCreator` on lives in `DatasetFinalizer` (`dataset_aggregation/dataset_finalizer.rb`), which takes a `Context` and an aggregate and cannot tell which engine produced it. Two other pieces are shared for the same reason: `CascadeActions` (derives the cascade action set and its `*_count` columns from `conversion_rate_targets`) and `DerivedFeatures` (`query_length_tokens`, `bm25_fields_matched`). `Context.build(config)` is the single place config becomes a `Context`, so no two engines can drift on a default.
|
|
10
|
+
|
|
11
|
+
Hosts can set the label transformer and enricher class names in config. The label transformer receives an `Ltr::Data::RowStore`. The finalizer also uses that type for the training feature engineering and transform steps.
|
|
12
|
+
|
|
13
|
+
**Cascade examination impressions.** `QueryAggregator` computes an `impression_count` per document via a per-session cascade examination model, before cross-session aggregation. Within one session (one `ubi_queries` record), each `(doc, action_type)` count is capped at 1 — per-session binarization — so a document viewed three times in a session has `view_count = 1`, not 3. The examination cutoff for a session is the deepest ranked position at which any *configured* action occurred; "configured" means the action appears as a numerator *or* a denominator in the host's `dataset_builder.conversion_rate_targets` (example_config.yml) — a rate dividing by `view_count` needs views to count as examination evidence just as much as a rate counting them — any action a host builds a rate from is treated as evidence the document was examined, not a hardcoded action set (and not a separate config key: an action with no rate carries no signal toward what's being labelled, so it isn't cascade-examination evidence either). Every document at or above the cutoff is credited one impression for that session, regardless of how many actions it had; documents below the cutoff are unexamined and dropped at this pre-aggregation step (a RAM optimisation — no low-count filtering happens before aggregation, only this strict zero-impression drop). `dataset_builder.cascade_cutoff: false` keeps them with `impression_count` 0 instead: a `(qid, doc)` never examined in any session becomes a negative that `DatasetFinalizer` labels 0 outside `LabelCreator`, optionally capped per query by `negative_downsample_ratio` (see [Negatives](labels-from-behavior.md#negatives)). `UserQueryAggregator`'s existing `_count`-summing handles `impression_count` with no additional code, since every new column ends in `_count`. This is **BREAKING for feature semantics**: `view_count` / `add_to_cart_count` / `purchase_count` and any `conversion_features` derived from them now measure sessions-with-the-action rather than total events — retrain required.
|
data/docs/dataset-csv.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Modelling dataset CSV
|
|
2
|
+
|
|
3
|
+
The columns, split values and reading rules of the file the dataset pipeline writes. For the UBI documents that feed it, see [UBI documents](ubi-documents.md).
|
|
4
|
+
|
|
5
|
+
The dataset pipeline writes this file. Training, evaluation, optimization, and feature store deployment read it.
|
|
6
|
+
One row is one document for one query group. If several query records share a group, their rows for the same doc are merged. Counts are summed. The scores come from the session that examined the doc. If several sessions examined it, the most recent one wins. The sqlite engine orders by `impression_count`, then `timestamp`. The ruby engine uses `max_by` on the same two values.
|
|
7
|
+
|
|
8
|
+
### Required columns
|
|
9
|
+
|
|
10
|
+
| Column | Type | Meaning |
|
|
11
|
+
|---|---|---|
|
|
12
|
+
| `qid` | integer | Query group id. One id per distinct combination of lowercased `user_query` and `additional_qid_fields`. The ids start at 1 and have no gaps. |
|
|
13
|
+
| `label` | number | Relevance grade of the row. Higher is more relevant. |
|
|
14
|
+
| `split` | string | One of `train`, `val`, `test`. |
|
|
15
|
+
|
|
16
|
+
A file without all three columns raises `Ltr::InvalidDatasetError`.
|
|
17
|
+
|
|
18
|
+
### Other columns the pipeline writes
|
|
19
|
+
|
|
20
|
+
| Column | Meaning |
|
|
21
|
+
|---|---|
|
|
22
|
+
| `user_query` | The lowercased query text. |
|
|
23
|
+
| `<doc_id_field>` | The doc id. The column name is `dataset_builder.doc_id_field`. |
|
|
24
|
+
| `raw_label` | The label before the label transformer ran. |
|
|
25
|
+
| `original_position` | 1-based display position. |
|
|
26
|
+
| `query_length_tokens` | Count of whitespace-separated words in `user_query`. |
|
|
27
|
+
| `bm25_fields_matched` | Number of distinct `bm25_` field names with a score above 0. The suffix after `bm25_` up to the next underscore names the field. |
|
|
28
|
+
| One column per score name | Taken from the `scores` objects in the query documents. |
|
|
29
|
+
| `<action>_count` | Per-doc action total. Present for each cascade action. |
|
|
30
|
+
| Conversion columns | One per entry in `dataset_builder.conversion_features`, for example `cart_conversion`. |
|
|
31
|
+
| `<feature>_rank`, `<feature>_relative_score` | Per-query features. Built for `relevancy` and every `bm25_` score, except `bm25_fields_matched`. Only the methods in `feature_engineering` are built. |
|
|
32
|
+
| `<column>_<value>` | One-hot columns. They replace each column whose values are all text, other than `user_query`, `qid` and the doc id. A column that mixes text with numbers raises `Ltr::InvalidDatasetError`. |
|
|
33
|
+
| Enricher columns | Any columns your `dataset_enricher` class adds. A text column is replaced by `<column>_<value>` flags of 0 and 1, like the one-hot columns above. |
|
|
34
|
+
|
|
35
|
+
`impression_count` is removed from the final file unless `dataset_builder.debug_mode` is `true`.
|
|
36
|
+
Do not train on a `debug_mode` file.
|
|
37
|
+
|
|
38
|
+
### How the pipeline builds rows
|
|
39
|
+
|
|
40
|
+
The pipeline builds rows from the UBI query documents and joins the UBI event documents to them. The rules the host app must follow are in [UBI documents](ubi-documents.md#query-documents).
|
|
41
|
+
|
|
42
|
+
- `original_position` is the 1-based index of the doc in the hit ids. A doc listed twice keeps its first position.
|
|
43
|
+
- A doc gets a row only when it is in the hit ids and has a non-empty score object. A hit id with no scores still takes its position, so the positions of later docs do not shift.
|
|
44
|
+
- An event joins the query document with the same `query_id`. It counts only when that document has a `user_query` and the event's doc is in the hit ids with a non-empty score object. A query document with no events gives no rows.
|
|
45
|
+
- Each cascade action, as [UBI event documents](ubi-documents.md#event-documents) defines it, gets a column named `<action>_count`. The action `add_to_cart` makes the column `add_to_cart_count`. An action that is not a cascade action gets no column.
|
|
46
|
+
|
|
47
|
+
### Split values
|
|
48
|
+
|
|
49
|
+
- `train`, `val` and `test` are the only split names. Queries are assigned at the query group level, so one group never spans two splits.
|
|
50
|
+
- Sizes come from `dataset_builder.split_ratios`. The three keys must sum to 1, and `train` must be above 0.
|
|
51
|
+
- Each consumer reads one split. Early stopping reads `training.early_stopping_split` (default `test`). Evaluation reads `evaluation.split` (default `test`). Optimization reads `optimization.split` (default `val`).
|
|
52
|
+
- If the configured split has no rows, the consumer falls back to `test` and logs a warning. If `test` has no rows either, it raises `Ltr::InvalidDatasetError`.
|
|
53
|
+
|
|
54
|
+
### Feature columns
|
|
55
|
+
|
|
56
|
+
- The model features are `optimized_features` when it is set. `ltr:optimize` writes it. Otherwise they are `search_time_features`, then the derived names from `feature_engineering`, then `feature_store.features`. Duplicates are removed.
|
|
57
|
+
- Derived names are `<feature>_<method>` for each search time feature that qualifies and each method in `feature_engineering`. The methods are `rank` and `relative_score`.
|
|
58
|
+
- When SSM is enabled, the feature list comes from SSM instead.
|
|
59
|
+
- Features missing from the CSV are logged and skipped. If none remain, training raises `ArgumentError`.
|
|
60
|
+
- Feature columns must be numeric. Text columns are not features.
|
|
61
|
+
|
|
62
|
+
### Reading rules
|
|
63
|
+
|
|
64
|
+
- The path is `training.modelling_dataset_path`. It may be a local path or an `s3://bucket/key` URL. A relative local path starts at `Ltr.config.root`. See [Config](config.md#training).
|
|
65
|
+
- The path in the config ends in `.csv`. The pipeline always writes `<path>.gz`, which is the gzip-compressed CSV.
|
|
66
|
+
- The reader looks for `<path>.gz` first. If it is not there, it reads `<path>`.
|
|
67
|
+
- Deploy also needs the [`.serving.json` file](model-files.md#dataset-serving-file) that aggregation writes next to the CSV.
|
|
68
|
+
- The first row is the header. Blank lines are skipped. A file with no header raises `Ltr::InvalidDatasetError`.
|
|
69
|
+
- A column is numeric if its first 500 data rows all parse as numbers or are missing. Any other column stays text.
|
|
70
|
+
- The `dataset_builder.doc_id_field` column always stays text, even when every value is digits. An id such as `00123` keeps its zeros.
|
|
71
|
+
- A numeric column is an integer column until a value has a decimal point or is missing. Then it becomes a float column.
|
|
72
|
+
- An empty cell and the text `NaN` both load as NaN in a numeric column.
|
|
73
|
+
- If a numeric column holds a non-number after row 500, the reader raises `Ltr::InvalidDatasetError`.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Dataset enrichers
|
|
2
|
+
|
|
3
|
+
An enricher joins host-app features into the dataset after it is built. The pipeline picks the class by name from config. You do not change the gem.
|
|
4
|
+
|
|
5
|
+
Subclass `Ltr::DatasetAggregation::DatasetEnricher` and implement `fetch_features`. It receives the unique doc ids of the dataset, as they are in the dataset. It returns a `Rover::DataFrame` with a column named `dataset_builder.doc_id_field` and one column per feature:
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
module Search
|
|
9
|
+
module Ltr
|
|
10
|
+
class DatasetEnricher < ::Ltr::DatasetAggregation::DatasetEnricher
|
|
11
|
+
def fetch_features(unique_doc_ids)
|
|
12
|
+
Rover::DataFrame.new(load_features_for(unique_doc_ids))
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Then name the class in config. The pipeline resolves it at run time:
|
|
20
|
+
|
|
21
|
+
```yaml
|
|
22
|
+
dataset_enricher:
|
|
23
|
+
class: "MyApp::Ltr::DatasetEnricher"
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Rules the pipeline applies
|
|
27
|
+
|
|
28
|
+
- The id column is `dataset_builder.doc_id_field`. The dataset must have it, or the enricher raises `ArgumentError`. Your frame must have a column with the same name.
|
|
29
|
+
- Doc ids are strings. Your frame may hold `Integer` or `String` ids, and the enricher turns both into strings before the join, so `12` joins as `"12"`. A `nil` id is skipped. Any other id type raises `ArgumentError` that names the column and the type, and says to cast the ids to `Integer` or `String`. A `Float` raises too, because Rover turns an integer column with a `nil` into `Float`, and `12` would become `"12.0"`.
|
|
30
|
+
- A doc id that appears in more than one row of your frame keeps its first row. The enricher logs a warning with the duplicate count and a few example ids. Without this the join would repeat dataset rows.
|
|
31
|
+
- A row with no doc id (`nil` or `NaN`) is left out of the ids your subclass gets. The row stays in the dataset with `NaN` in the new columns, and its id stays empty.
|
|
32
|
+
- Every column in your frame must be new to the dataset, apart from the join column (`dataset_builder.doc_id_field`). If one is not, the enricher raises `ArgumentError` naming the columns, before it changes the dataset.
|
|
33
|
+
- A column of numbers becomes floats. A missing value (`nil`) is always `NaN`, in float and object columns alike. `NaN` means the value is missing. It is not a zero.
|
|
34
|
+
- A blank string and the text `NaN` count as missing. In a column of numbers they become `NaN`, so `[1.5, "NaN"]` and `[1.5, ""]` give `[1.5, NaN]` with no warning.
|
|
35
|
+
- A column is text when at least one value that is not `nil`, a `Float` `NaN`, blank or the text `NaN` is a `String`. A text column is one-hot encoded. See [Text columns](#text-columns). A column of only blank and `NaN` strings becomes blank strings. It has no flags, and the pipeline drops it.
|
|
36
|
+
- A column that mixes strings with numbers, such as `["acme", 1.5]`, is text. Each value that is not missing goes through `to_s`, so the flags are `<column>_acme` and `<column>_1.5`. An `Integer` `2` gives `"2"` and a `Float` `1.0` gives `"1.0"`.
|
|
37
|
+
- The subclass gets only the doc ids. The pipeline passes its own config to the enricher, as `Ltr::DatasetAggregation::DatasetEnricher.call(dataset, config:)`. The enricher reads `doc_id_field` from that config. A subclass that overrides `initialize` must accept `config:`.
|
|
38
|
+
- Doc ids are strings from both aggregation engines. Your subclass gets them as strings, so a lookup keyed by `Integer` ids needs a cast inside `fetch_features`. The frame you return does not need one.
|
|
39
|
+
- When your frame has no rows, the enricher returns the dataset unchanged and logs at `info`. An empty frame can be intended, so it does not warn or raise. The same happens when the dataset has no doc ids at all.
|
|
40
|
+
- When your frame has rows and none of their ids is in the dataset, the enricher raises `Ltr::InvalidDatasetError`. This usually means the host has no rows for the dataset ids.
|
|
41
|
+
- When some ids match, the enricher logs how many of the dataset ids matched.
|
|
42
|
+
- The join is a left join on `dataset_builder.doc_id_field`. Rows with no match get `NaN` in the new float columns, and 0 in every flag of a text column.
|
|
43
|
+
|
|
44
|
+
## Text columns
|
|
45
|
+
|
|
46
|
+
The pipeline one-hot encodes each text column after the join. It replaces the column with one `<column>_<value>` column of 1 and 0 per distinct value. `brand` with the values `acme` and `zeta` becomes `brand_acme` and `brand_zeta`. A string column of numbers is encoded too, so `["1.5", "2"]` gives `size_1.5` and `size_2`.
|
|
47
|
+
|
|
48
|
+
- A row with no match, a row with no doc id, and a `nil`, blank or `NaN` value get 0 in every flag. There is no `<column>_NaN` flag.
|
|
49
|
+
- Only the columns your enricher added are encoded. The dataset columns, such as `split`, stay as they are.
|
|
50
|
+
- The flag names are saved with the one-hot column names in the `.serving.json` file. Serving gives a flag that the request and the feature store leave out the value 0.
|
|
51
|
+
- A value that training never saw has no flag. All the known flags are 0 for it.
|
|
52
|
+
- The pipeline raises `ArgumentError` when a flag has the name of a column in the dataset, or when two columns give the same flag name.
|
|
53
|
+
- The pipeline logs at `info` how many flags each text column becomes. It logs a warning when a column has 10 or more distinct values, and raises `ArgumentError` when it has 100 or more. A blank or `NaN` value is not counted. The error names the column and the count. Drop the column or bucket its values into fewer categories. Both numbers are `WARN_DISTINCT_VALUES` and `MAX_DISTINCT_VALUES` on `Ltr::Features::EnrichedColumnEncoder`.
|
|
54
|
+
- `ltr:train` and `ltr:optimize` raise `ArgumentError` naming a feature whose name has `[`, `]` or `<`, because XGBoost rejects it. A text value with one of these characters gives such a flag. Aggregate does not check.
|
|
55
|
+
- `feature_transformations` do not apply to these flags.
|
|
56
|
+
- The flag names depend on the data. List the flags, such as `brand_acme`, in `feature_store.features`, not the source column `brand`. Listing `brand` fails at deploy, because the CSV has no `brand` column. If a value disappears from the data, its flag disappears on the next `ltr:aggregate`, and a deploy that lists it fails.
|
|
57
|
+
|
|
58
|
+
## Train on the new columns
|
|
59
|
+
|
|
60
|
+
Joining a column does not train on it. Add its name (for a text column, the `<column>_<value>` flag names) to [`search_time_features`](config.md#search_time_features) or [`feature_store.features`](config.md#feature_store). The model uses only the features that those lists name. After `ltr:optimize` has written `optimized_features`, the model uses that list instead. Re-run `ltr:optimize` to pick up the new column.
|
|
61
|
+
|
|
62
|
+
See [Config](config.md#dataset_enricher) for the key. `DatasetEnricher#fetch_features` is part of the [public API](public-api.md).
|
data/docs/errors.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Errors
|
|
2
|
+
|
|
3
|
+
This page explains the gem's error classes and how it handles errors from other libraries.
|
|
4
|
+
|
|
5
|
+
## The gem's errors
|
|
6
|
+
|
|
7
|
+
`Ltr::Error` inherits from `StandardError`. The five classes below inherit from `Ltr::Error`, so a host app can rescue them all with `rescue Ltr::Error`.
|
|
8
|
+
|
|
9
|
+
The gem also raises `Ltr::Error` when `tar` exits unsuccessfully while packaging a model. Check that `tar` can write the archive. See [Model files](model-files.md#model-file).
|
|
10
|
+
|
|
11
|
+
| Class | When it is raised and what to do |
|
|
12
|
+
|---|---|
|
|
13
|
+
| `Ltr::ConfigurationError` | A config is invalid or a required setting, serving file or model metadata is missing. Check the config and the affected feature's instructions. See [Config](config.md) and [Model files](model-files.md#dataset-serving-file). |
|
|
14
|
+
| `Ltr::DeployError` | A SageMaker endpoint fails to reach the expected state or serves an older config. Check the endpoint in SageMaker and correct the cause before deploying again. See [Run on AWS](run-on-aws.md#train-and-deploy). |
|
|
15
|
+
| `Ltr::InvalidDatasetError` | A dataset or a User Behavior Insights (UBI) query record is missing or malformed. Correct the data or rebuild the dataset. See [Modelling dataset CSV](dataset-csv.md) and [UBI documents](ubi-documents.md). |
|
|
16
|
+
| `Ltr::MissingDependencyError` | A feature needs an optional gem that is missing or outside its supported versions. Add a supported version to the host app's Gemfile. See [Installation](../README.md#installation). |
|
|
17
|
+
| `Ltr::SqliteError` | A SQLite aggregation statement fails. Check its `statement` and `error_code` and the aggregation log. See [Aggregation engines](aggregation-engines.md#when-a-sqlite-run-fails). |
|
|
18
|
+
|
|
19
|
+
## Errors from other libraries
|
|
20
|
+
|
|
21
|
+
The table shows the errors the gem handles and what happens next.
|
|
22
|
+
|
|
23
|
+
| Source | Handling |
|
|
24
|
+
|---|---|
|
|
25
|
+
| UBI loaders | The loaders retry Faraday connection failures and timeouts. They also retry OpenSearch HTTP 5xx, 408 and 429 errors. After the retries fail, the last error reaches the host. Other OpenSearch errors reach the host without a retry. |
|
|
26
|
+
| Dataset on Amazon S3 | If the compressed file is missing, the gem tries the uncompressed file. A missing uncompressed file or another S3 error reaches the host. |
|
|
27
|
+
| Dataset serving file on S3 | A missing file becomes `Ltr::ConfigurationError`. Other S3 errors reach the host. |
|
|
28
|
+
| AWS Systems Manager Parameter Store (SSM) | If optimization cannot find its SSM hyperparameters, it uses the config values. Missing SSM parameters in training or deploy reach the host. |
|
|
29
|
+
| SageMaker | If SageMaker reports that the named endpoint already exists, the gem updates it. Other SageMaker service errors reach the host. |
|
|
30
|
+
| SQLite | An aggregation statement failure becomes `Ltr::SqliteError`. Other SQLite errors can reach the host. |
|
|
31
|
+
| Feature store deployment | The gem reports errors to the configured error reporter and raises them again. See [Host integration](host-integration.md). |
|
|
32
|
+
|
|
33
|
+
Other Ruby errors such as `ArgumentError` and `KeyError` can come from argument and config checks. Each feature's page describes its own checks.
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# Feature selection
|
|
2
|
+
|
|
3
|
+
`ltr:optimize` starts by choosing the features the model trains on. This page explains where the candidate features come from, how one candidate set is scored, how the strategies `greedy_backward`, `importance_ranked` and `rfe` (recursive feature elimination) choose which sets to try, and how many trainings each strategy costs. The hyperparameter search then runs on the chosen features. [Optimization](optimization.md) explains that search and the rest of `ltr:optimize`.
|
|
4
|
+
|
|
5
|
+
## Choose a strategy
|
|
6
|
+
|
|
7
|
+
Set `optimization.feature_selection.strategy`. When the key is missing, the gem uses `greedy_backward`. [Config](config.md#optimization) lists the other keys and the error that an unknown name raises.
|
|
8
|
+
|
|
9
|
+
| Strategy | Trainings | At the shipped config | Ranking refreshed |
|
|
10
|
+
|---|---|---|---|
|
|
11
|
+
| `greedy_backward` | at most `1 + (min_features + 1) + … + n` | at most 456 | not used |
|
|
12
|
+
| `rfe` | `1 + n - min_features` | 27 | every step |
|
|
13
|
+
| `importance_ranked` | `1 + n - min_features` | 27 | once |
|
|
14
|
+
|
|
15
|
+
Here `n` is the number of candidate features. The shipped config, `lib/ltr/configuration/example_config.yml`, has 30 candidates and `min_features: 4`.
|
|
16
|
+
|
|
17
|
+
Use `greedy_backward` when you can afford its trainings, because it trains every possible removal instead of choosing from an importance ranking. Otherwise use `rfe`. It costs the same as `importance_ranked` and refreshes the ranking after every drop. The [example below](#ranking-strategies) shows why the refresh matters.
|
|
18
|
+
|
|
19
|
+
## Candidate features
|
|
20
|
+
|
|
21
|
+
The candidates are `optimization.search_time_features`, the derived features that `feature_engineering` adds for them, and `optimization.feature_store_features`. These lists are separate from the top-level `search_time_features` and `feature_store.features`, which hold the features the model uses. In the shipped config, 8 search-time features, 16 derived features and 6 feature-store features make 30 candidates.
|
|
22
|
+
|
|
23
|
+
A candidate with no column in the dataset is left out, and the log lists it. `ltr:optimize` raises `ArgumentError` when the configured candidates don't outnumber `min_features`.
|
|
24
|
+
|
|
25
|
+
At the end, `ltr:optimize` writes the chosen features to the config file. [Optimization](optimization.md#what-gets-written-back) lists the keys it rewrites.
|
|
26
|
+
|
|
27
|
+
## How a set is scored
|
|
28
|
+
|
|
29
|
+
Each candidate set costs one training, called a trial. [Optimization](optimization.md#what-a-trial-is) explains which split a trial trains on, which split scores it, and which hyperparameters feature selection uses.
|
|
30
|
+
|
|
31
|
+
The strategies compare the penalized score, `raw_score - k * complexity_penalty`. Here `raw_score` is the metric and `k` is the number of features in the set. A set with `m` more features has the higher penalized score only when it raises the metric by more than `m * complexity_penalty`. For example, with the shipped `complexity_penalty: 0.0001` and the made-up scores in the chart below, 8 features at `ndcg@12` 0.71270 score 0.71190. 7 features at 0.71240 score 0.71170, so the 8-feature set wins. Dropping the feature lost 0.0003 of metric and saved only 0.0001 of penalty. 9 features at 0.71275 score 0.71185, so a ninth feature that adds only 0.00005 of metric loses.
|
|
32
|
+
|
|
33
|
+
Pick the value so that the penalty for one feature is smaller than the metric gain one useful feature can bring. A penalty larger than that gain drops useful features until the set reaches `min_features`. An older example file set `0.01`. On the toy data the metric moved by about 0.0024 across a 24-to-4 feature sweep, while the penalty moved by 0.20 (20 dropped features at 0.01). So the search always ended at `min_features`.
|
|
34
|
+
|
|
35
|
+
The chart applies the same penalty to made-up scores for 4 to 12 features. The raw metric peaks at 11 features, but the penalized score peaks at 8.
|
|
36
|
+
|
|
37
|
+
```mermaid
|
|
38
|
+
xychart-beta
|
|
39
|
+
title "Raw ndcg@12 (bars) and penalized score (line)"
|
|
40
|
+
x-axis "Features in the set" [4, 5, 6, 7, 8, 9, 10, 11, 12]
|
|
41
|
+
y-axis "Score" 0.709 --> 0.713
|
|
42
|
+
bar [0.71000, 0.71120, 0.71200, 0.71240, 0.71270, 0.71275, 0.71280, 0.71285, 0.71270]
|
|
43
|
+
line [0.70960, 0.71070, 0.71140, 0.71170, 0.71190, 0.71185, 0.71180, 0.71175, 0.71150]
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Greedy backward elimination
|
|
47
|
+
|
|
48
|
+
`greedy_backward` runs in rounds. Each round removes each feature of the current set in turn and trains every result. A round over `k` features costs `k` trainings. The strategy keeps the best removal only when its penalized score is higher than the current set's, so a tie keeps the larger set. It stops when no removal beats the current set or the set reaches `min_features`.
|
|
49
|
+
|
|
50
|
+
The diagram shows one round on a made-up 4-feature set with `min_features: 3`.
|
|
51
|
+
|
|
52
|
+
```mermaid
|
|
53
|
+
flowchart TB
|
|
54
|
+
C["Current set: relevancy, price, view_count, bm25_name<br>penalized 0.600"] --> M{{"More features than min_features?"}}
|
|
55
|
+
M -->|"no"| S["Stop and keep the current set"]
|
|
56
|
+
M -->|"yes"| R1["Without relevancy<br>penalized 0.540"]
|
|
57
|
+
M -->|"yes"| R2["Without price<br>penalized 0.585"]
|
|
58
|
+
M -->|"yes"| R3["Without view_count<br>penalized 0.598"]
|
|
59
|
+
M -->|"yes"| R4["Without bm25_name<br>penalized 0.607"]
|
|
60
|
+
R1 --> B{{"Best removal higher than<br>the current set's score?"}}
|
|
61
|
+
R2 --> B
|
|
62
|
+
R3 --> B
|
|
63
|
+
R4 --> B
|
|
64
|
+
B -->|"no"| S
|
|
65
|
+
B -->|"yes: 0.607 > 0.600"| N["Current set: relevancy, price, view_count"]
|
|
66
|
+
N --> M
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Because every removal is trained, each decision comes from measured scores. A feature that helps only together with another feature stays when removing it lowers the metric by at least `complexity_penalty`. The two ranking strategies decide from importance instead, so they can drop such a feature.
|
|
70
|
+
|
|
71
|
+
## Ranking strategies
|
|
72
|
+
|
|
73
|
+
`importance_ranked` and `rfe` drop one feature per step, from all candidates down to `min_features`, and train each set. They rank features by XGBoost's `total_gain`, which adds up the gain of every split on a feature. A feature the model never splits on gets 0 and ranks last. Features with equal importance keep their candidate order, so the later one drops first.
|
|
74
|
+
|
|
75
|
+
Neither strategy stops at the first fall in the score, because the metric can fall and then rise again as the set shrinks. Both train every size down to `min_features` and keep the set with the best penalized score. A tie goes to the smaller set.
|
|
76
|
+
|
|
77
|
+
The strategies differ in the ranking that picks the next feature to drop:
|
|
78
|
+
|
|
79
|
+
- `importance_ranked` ranks once, on the model trained with all candidates. Each step drops the remaining feature that is lowest in that first ranking.
|
|
80
|
+
- `rfe` ranks again on each new model and drops that model's lowest feature.
|
|
81
|
+
|
|
82
|
+
The first ranking is misleading when features are correlated. Correlated features share the gain between them, so each one ranks lower than it would alone. Derived features make this common, because `bm25_name`, `bm25_name_rank` and `bm25_name_relative_score` all come from one score.
|
|
83
|
+
|
|
84
|
+
The table shows made-up `total_gain` values for five candidates with `min_features: 3`. `bm25_name` and `bm25_name_simple` are near duplicates.
|
|
85
|
+
|
|
86
|
+
| Feature | `total_gain`, 5-feature model | `total_gain`, 4-feature model |
|
|
87
|
+
|---|---|---|
|
|
88
|
+
| `relevancy` | 50 | 50 |
|
|
89
|
+
| `price` | 30 | 30 |
|
|
90
|
+
| `view_count` | 25 | 25 |
|
|
91
|
+
| `bm25_name` | 20 | 38 |
|
|
92
|
+
| `bm25_name_simple` | 18 | dropped |
|
|
93
|
+
|
|
94
|
+
```mermaid
|
|
95
|
+
flowchart TB
|
|
96
|
+
subgraph IR["importance_ranked"]
|
|
97
|
+
direction TB
|
|
98
|
+
I5["All 5 features"] -->|"drop bm25_name_simple, 18"| I4["relevancy, price, view_count, bm25_name"]
|
|
99
|
+
I4 -->|"drop bm25_name, 20 in the first ranking"| I3["relevancy, price, view_count"]
|
|
100
|
+
end
|
|
101
|
+
subgraph RF["rfe"]
|
|
102
|
+
direction TB
|
|
103
|
+
R5["All 5 features"] -->|"drop bm25_name_simple, 18"| R4["relevancy, price, view_count, bm25_name"]
|
|
104
|
+
R4 -->|"rank again, drop view_count, 25"| R3["relevancy, bm25_name, price"]
|
|
105
|
+
end
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Both strategies drop `bm25_name_simple` first, because it ranks last on the 5-feature model. Without it, `bm25_name` gets the gain the two features shared and rises from 20 to 38. `importance_ranked` still uses the first ranking, so its 3-feature set is `relevancy`, `price` and `view_count`. `rfe` ranks the 4-feature model, so its 3-feature set is `relevancy`, `bm25_name` and `price`. The `importance_ranked` set has no feature that scores the product name.
|
data/docs/features.md
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# Features
|
|
2
|
+
|
|
3
|
+
The model scores each candidate document from a list of numbers that describe it. Each of those numbers is a feature. This page explains the two kinds of feature the gem supports. For each kind, it shows where the training data gets the value, where a live search gets it, and what the host app has to send. It also explains how training picks the features the model reads. The page assumes you have read [Learning to rank](learning-to-rank.md).
|
|
4
|
+
|
|
5
|
+
## Glossary
|
|
6
|
+
|
|
7
|
+
| Term | Meaning |
|
|
8
|
+
|---|---|
|
|
9
|
+
| Candidate | One document that OpenSearch returned for a search. The model gives each candidate a `score`. |
|
|
10
|
+
| Feature | A named number that describes one candidate, such as `bm25_name` or `purchase_count`. For each candidate, the model reads one value for each feature it uses. |
|
|
11
|
+
| Feature list | The names of the features the model reads, in order. Training picks the list and saves it in the model file. |
|
|
12
|
+
| Feature store | A table of feature-store values that deploy ships with the model when `feature_store.include_in_deployment` is `true`. Inference looks up a value in it by feature name and doc id, only when the request fields have no value for that feature. |
|
|
13
|
+
| Host app | The app that runs the search in OpenSearch, logs it to UBI and calls the gem to rerank the results. |
|
|
14
|
+
| Local reranker | `Ltr::Inference::LocalReranker`, the inference backend that scores candidates inside the host app's own process. It loads the model file from `deploy.local_path` by default. |
|
|
15
|
+
| Modelling CSV | The gzipped CSV that `ltr:aggregate` writes to `training.modelling_dataset_path` with `.gz` added. It has one row for each document in each query group, and a column for each feature. |
|
|
16
|
+
| Request fields | The `fields` list of `{ "name": ..., "value": ... }` pairs that the host app sends with each candidate when it asks the model to rerank. Inference uses a value from them before it looks in the feature store. |
|
|
17
|
+
| SageMaker endpoint | The AWS SageMaker endpoint that the SageMaker deploy creates, named `<model.name>-endpoint`. `Ltr::Inference::SagemakerClient` sends it the payload and gets the scores back. |
|
|
18
|
+
| UBI | User Behavior Insights, the query and event logs that the host app writes to OpenSearch. The shipped index names are `ubi_queries` and `ubi_events`. |
|
|
19
|
+
|
|
20
|
+
## Two kinds of feature
|
|
21
|
+
|
|
22
|
+
A search-time feature describes how well a document matches one query, so its value changes from query to query. A feature-store feature describes the document itself, such as how often users bought it, so it has the same value for every query.
|
|
23
|
+
|
|
24
|
+
| | Search-time feature | Feature-store feature |
|
|
25
|
+
|---|---|---|
|
|
26
|
+
| Describes | How well the document matches the query | The document, for every query |
|
|
27
|
+
| Examples | `bm25_name`, `relevancy`, `bm25_name_rank` | `view_count`, `purchase_count`, `purchase_conversion` |
|
|
28
|
+
| Training value comes from | The scores the host app logged in UBI | UBI events in the train split, or a dataset enricher |
|
|
29
|
+
| Live value comes from | The request fields | The request fields, else the feature store |
|
|
30
|
+
| Config key | `search_time_features` | `feature_store.features` |
|
|
31
|
+
|
|
32
|
+
## Search-time features
|
|
33
|
+
|
|
34
|
+
The search engine computes a search-time feature while it runs the search, such as the BM25 score of the product name. The host app uses each score twice, as the diagram shows.
|
|
35
|
+
|
|
36
|
+
```mermaid
|
|
37
|
+
---
|
|
38
|
+
config:
|
|
39
|
+
flowchart:
|
|
40
|
+
wrappingWidth: 480
|
|
41
|
+
---
|
|
42
|
+
flowchart LR
|
|
43
|
+
S["Host app runs a search,<br>OpenSearch scores each candidate"] -->|"logs the scores"| Q["UBI query record<br>query_attributes.scores"]
|
|
44
|
+
Q -->|"ltr:aggregate"| CSV[("Modelling CSV<br>one column per score")]
|
|
45
|
+
CSV -->|"ltr:train"| M["Model"]
|
|
46
|
+
S -->|"puts the same scores in"| R["Request fields for each candidate<br>in the host app's rerank request"]
|
|
47
|
+
R -->|"sent to the model"| M
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
For training, the host logs the scores on the UBI query record, under `query_attributes.scores`, keyed by doc id. The dataset pipeline copies each score into a CSV column of the same name, except a score whose name the gem reserves (see [Reserved score names](ubi-documents.md#reserved-score-names)). When the same query and document appear in several sessions, the row keeps the scores from the newest session that examined the document.
|
|
51
|
+
|
|
52
|
+
At a live search, the host app sends the model the same scores that OpenSearch produced. It puts them in the request fields of each candidate. Two rules keep the scores the same as in training:
|
|
53
|
+
|
|
54
|
+
- Use the same name that the score has in UBI.
|
|
55
|
+
- Send the value exactly as the host logged it. Do not transform it. The model applies the [feature transforms](#feature-transforms) itself.
|
|
56
|
+
|
|
57
|
+
Each score must come from the same scoring in both places. If it comes from a different scoring, the model sees different numbers at inference from the ones it trained on.
|
|
58
|
+
|
|
59
|
+
List the scores the model uses in `search_time_features`:
|
|
60
|
+
|
|
61
|
+
```yaml
|
|
62
|
+
search_time_features:
|
|
63
|
+
- relevancy
|
|
64
|
+
- bm25_name
|
|
65
|
+
- bm25_description
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The modelling CSV also has three columns that the gem computes itself: `original_position`, `query_length_tokens` and `bm25_fields_matched`. [Modelling dataset CSV](dataset-csv.md#other-columns-the-pipeline-writes) defines them. The model uses them only if you list them in `search_time_features`. Neither inference backend computes them, so the host must send them in the request fields like any other search-time feature. A UBI score cannot use these names, so the dataset always holds the gem's value for them.
|
|
69
|
+
|
|
70
|
+
## Rank and relative score
|
|
71
|
+
|
|
72
|
+
A raw BM25 score depends on the query, so a score of 9 can be high for one query and low for another. `feature_engineering` adds two search-time features that compare a document's score with the scores of the other candidates for the same query:
|
|
73
|
+
|
|
74
|
+
```yaml
|
|
75
|
+
feature_engineering:
|
|
76
|
+
- rank
|
|
77
|
+
- relative_score
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
- `rank` is the document's position when the candidates are sorted by score, with 1 for the highest. Equal scores share the smaller rank, so the ranks run 1, 2, 2, 4. A score of zero or below gets `-1`. A missing score gets `NaN`, and it does not change the other candidates' ranks. A score is missing when the value is `nil` or `NaN`, or when the candidate has no such field.
|
|
81
|
+
- `relative_score` is the score divided by the highest score for the query, rounded to 3 decimal places. Training and the local reranker compute it in Ruby. The SageMaker endpoint computes it in Python. A ratio that is exactly halfway between two 3-place values in decimal, such as `1 / 16` (`0.0625`) or `3 / 400` (`0.0075`), rounds up in Ruby and can round down in Python. On those ratios the endpoint can differ by `0.001`. If the highest score is zero or below, every document with a score gets `0.0`. The highest score is taken over the present scores only. A missing score gets `NaN`.
|
|
82
|
+
|
|
83
|
+
The table applies both methods to made-up `bm25_name` scores for the query magnesium.
|
|
84
|
+
|
|
85
|
+
| Product | `bm25_name` | `bm25_name_rank` | `bm25_name_relative_score` |
|
|
86
|
+
|---|---|---|---|
|
|
87
|
+
| Magnesium glycinate | 12.4 | 1 | 1.0 |
|
|
88
|
+
| Magnesium citrate | 9.3 | 2 | 0.75 |
|
|
89
|
+
| Magnesium oxide | 9.3 | 2 | 0.75 |
|
|
90
|
+
| Zinc | 0.0 | -1 | 0.0 |
|
|
91
|
+
|
|
92
|
+
The gem builds both for `relevancy` and for every search-time feature whose name starts with `bm25_`, except `bm25_fields_matched`. Each new feature is named `<feature>_<method>`, such as `bm25_name_rank`. You don't need to list these names yourself, because the gem adds them to the feature list, as [Which features the model reads](#which-features-the-model-reads) explains.
|
|
93
|
+
|
|
94
|
+
The gem computes `_rank` and `_relative_score` over one query group. In the modelling CSV, a query group is the rows that share a `qid`, which are the candidate documents for one query. At inference, it is the candidates in one request. Both values depend on the other candidates in the group, so a document's value changes when its group changes. The SageMaker endpoint and the local reranker compute each `_rank` and `_relative_score` feature in the feature list from the base scores in the request fields. So the host sends only the base scores.
|
|
95
|
+
|
|
96
|
+
For `bm25_name_rank`, the base score is `bm25_name`. Send the base score in the request fields for every `_rank` and `_relative_score` feature, even when the base score is not in the feature list. If a candidate has no base score, or sends `null`, its `_rank` and `_relative_score` are `NaN`. This matches the base score, which is `NaN` in training when it is missing. XGBoost treats `NaN` as a missing value. A real score of `0` is not missing. It gets rank `-1` and relative score `0.0`. If no candidate sends the base score, every candidate gets `NaN` for both. In older versions a missing base score counted as `0.0`, so a model trained then should be retrained. Log about as many candidates in UBI for a query as you send for reranking. If the two numbers differ a lot, the same document can get a different rank and relative score at inference from the ones it had in training.
|
|
97
|
+
|
|
98
|
+
## Feature-store features
|
|
99
|
+
|
|
100
|
+
A feature-store feature describes a document for every query, such as how often users bought it. The gem computes most of them from UBI events. The diagram shows how `ltr:aggregate` turns the events into columns of the modelling CSV, and how deploy turns those columns into the feature store.
|
|
101
|
+
|
|
102
|
+
```mermaid
|
|
103
|
+
---
|
|
104
|
+
config:
|
|
105
|
+
flowchart:
|
|
106
|
+
wrappingWidth: 480
|
|
107
|
+
---
|
|
108
|
+
flowchart TB
|
|
109
|
+
E["UBI events<br>such as views and purchases"] --> C["1. Count each action for each query group and document,<br>such as view_count and purchase_count"]
|
|
110
|
+
C --> T["2. For each document, add up its counts from the train rows only,<br>and write that total to every row of the document"]
|
|
111
|
+
T --> R["3. Add the conversion ratios,<br>such as purchase_conversion =<br>purchase_count / view_count"]
|
|
112
|
+
R --> X["4. Apply feature_transformations"]
|
|
113
|
+
X --> CSV[("Modelling CSV")]
|
|
114
|
+
H["Dataset enricher<br>columns from the host app"] --> CSV
|
|
115
|
+
CSV -->|"deploy builds the store"| FS[("Feature store<br>built only when include_in_deployment is true<br>feature name, doc id, value")]
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
The steps in the diagram work like this:
|
|
119
|
+
|
|
120
|
+
1. `ltr:aggregate` counts each action, such as a view or a purchase, for each query group and document. These are the `<action>_count` columns.
|
|
121
|
+
2. For each document, it adds up each count over the document's rows in the train split. It writes the totals to every row of the document, in all three splits. The val and test actions are left out of the totals, so no val or test action reaches a feature.
|
|
122
|
+
3. It adds each ratio in `dataset_builder.conversion_features`, using the train totals. The shipped config defines `cart_conversion` and `purchase_conversion`. A ratio is written only when the document's denominator total is above 0.
|
|
123
|
+
4. It applies `feature_transformations`, as [Feature transforms](#feature-transforms) explains.
|
|
124
|
+
|
|
125
|
+
The table shows made-up counts for one product that appears in three query groups. Two of the groups are in the train split, and one is in the test split.
|
|
126
|
+
|
|
127
|
+
| `qid` | `split` | `view_count` before step 2 | `purchase_count` before step 2 | `view_count` after | `purchase_count` after | `purchase_conversion` |
|
|
128
|
+
|---|---|---|---|---|---|---|
|
|
129
|
+
| 1 | train | 4 | 1 | 6 | 1 | 0.167 |
|
|
130
|
+
| 3 | train | 2 | 0 | 6 | 1 | 0.167 |
|
|
131
|
+
| 6 | test | 3 | 2 | 6 | 1 | 0.167 |
|
|
132
|
+
|
|
133
|
+
The 3 views and 2 purchases in the test row do not count. Every row gets the same totals, 6 views and 1 purchase, so `purchase_conversion` is 1 / 6. A document with no rows in the train split has no totals, so it gets `nil` for each `_count` column and each ratio. The feature store is the exception, as [How the model gets feature-store values](#how-the-model-gets-feature-store-values) explains.
|
|
134
|
+
|
|
135
|
+
A [dataset enricher](dataset-enrichers.md) can add more columns, such as product data from the host app. It joins them by doc id after the steps above. An enricher column can be a feature-store feature too. `ltr:aggregate` one-hot encodes the text columns of an enricher after the join, as [One-hot columns](#one-hot-columns) explains. To use a text column as a feature-store feature, list its `<column>_<value>` flags in `feature_store.features`.
|
|
136
|
+
|
|
137
|
+
List the columns the model uses in `feature_store.features`:
|
|
138
|
+
|
|
139
|
+
```yaml
|
|
140
|
+
feature_store:
|
|
141
|
+
include_in_deployment: true
|
|
142
|
+
features:
|
|
143
|
+
- purchase_count
|
|
144
|
+
- view_count
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## How the model gets feature-store values
|
|
148
|
+
|
|
149
|
+
With `feature_store.include_in_deployment: true`, deploy builds the feature store from the modelling CSV. For each document, it copies the value of each feature in `feature_store.features`. When `ssm.enabled` is `true`, it reads the feature names from SSM instead. The store leaves out `nil`, empty and `NaN` values. A document with no train rows has `nil` in the CSV, so deploy takes its value from `fallback_feature_totals` in the serving file. Each fallback total adds up the document's counts over its val and test rows, and has the same transforms applied. Every `*_count` feature gets a fallback. A conversion ratio gets one only when its denominator total is above 0. A document with no rows in any split has no value in the store.
|
|
150
|
+
|
|
151
|
+
The table shows the `view_count` and `purchase_conversion` values for four documents, with no transforms. Document A is the product from the table above. The numbers come from running `BehaviouralFeatureBuilder` and `FeatureStoreDeployer` on these rows.
|
|
152
|
+
|
|
153
|
+
| Document | Rows in the CSV | `view_count` in the CSV | `view_count` in the store | `purchase_conversion` in the store | Why |
|
|
154
|
+
|---|---|---|---|---|---|
|
|
155
|
+
| A | 2 train rows, 1 test row | 6 | 6 | 0.167 | It has train rows, so the store copies the CSV value. |
|
|
156
|
+
| B | 1 val row with 1 view and 1 purchase, 1 test row with 2 views | `nil` | 3 | 0.333 | It has no train rows, so the store uses the fallback totals from val and test. |
|
|
157
|
+
| C | 1 test row with 0 views | `nil` | 0 | no value | Its fallback `view_count` is 0, so the ratio has no fallback. |
|
|
158
|
+
| D | none | none | no value | no value | It has no rows, so it has no fallback totals. |
|
|
159
|
+
|
|
160
|
+
Training never saw documents like B and C, because they have no train rows. Their fallback values come from val and test queries only. By default those splits hold 30% of the queries and train holds 70%, so the values are on the small side of the train scale. No offline metric can check them, because the val and test rows carry the labels. The SageMaker deploy puts the store in the model package as `code/feature_store.json`. The local deploy, which `deploy.local: true` turns on, stores it in the model file as the XGBoost attribute `feature_store`. With any other value of `include_in_deployment`, neither deploy ships a store. [Model and feature store files](model-files.md#feature-store-json) describes the store.
|
|
161
|
+
|
|
162
|
+
For each candidate and each feature in the feature list, the SageMaker endpoint and the local reranker pick the value in this order:
|
|
163
|
+
|
|
164
|
+
1. The value in the request fields, after the saved transform steps. A `null` value counts as no value.
|
|
165
|
+
2. Otherwise the value in the feature store for that doc id, if the store has the feature.
|
|
166
|
+
3. Otherwise `0` through the saved steps for a [one-hot column](#one-hot-columns), and `NaN` for any other feature. XGBoost treats `NaN` as a missing value.
|
|
167
|
+
|
|
168
|
+
So when the model has a feature store, the host does not need to send feature-store features. If it sends one, the request value is used. When the model has no store, the host must send every feature-store feature in the request fields. Send it raw in both cases, because the model transforms request values.
|
|
169
|
+
|
|
170
|
+
## Which features the model reads
|
|
171
|
+
|
|
172
|
+
Training picks the feature list and saves it in the model file. At inference, the SageMaker endpoint and the local reranker read the list from the model file. So a config change after training does not change the list until you train and deploy again.
|
|
173
|
+
|
|
174
|
+
Training picks the list in this order:
|
|
175
|
+
|
|
176
|
+
1. When `ssm.enabled` is `true`, it reads the list from the SSM `all_features` parameter, and it ignores the lists in the YAML.
|
|
177
|
+
2. Otherwise, when `optimized_features` is set and not empty, it uses that list as it is.
|
|
178
|
+
3. Otherwise, it joins `search_time_features`, the derived names from `feature_engineering` and `feature_store.features`, in that order, with duplicates removed.
|
|
179
|
+
|
|
180
|
+
Training then drops any name that is not a column of the modelling CSV, and logs a warning.
|
|
181
|
+
|
|
182
|
+
`optimized_features` is the full list of features that `ltr:optimize` kept. `ltr:optimize` writes it to the config file, so you don't set it by hand. The same run rewrites `search_time_features` with the kept search-time and derived features, and `feature_store.features` with the kept feature-store features. When SSM is on, it also saves the list to SSM as `all_features`. [Optimization](optimization.md#what-gets-written-back) lists every key it rewrites.
|
|
183
|
+
|
|
184
|
+
Once `optimized_features` is set, training uses it and not the other two lists. So an edit to `search_time_features` or `feature_store.features` does not reach training until `ltr:optimize` runs again. When SSM is off, the config loader logs a warning when `optimized_features` no longer matches those two lists. See [`optimized_features`](config.md#optimized_features) and [`ssm`](config.md#ssm).
|
|
185
|
+
|
|
186
|
+
## Feature transforms
|
|
187
|
+
|
|
188
|
+
`feature_transformations` changes the values of the columns it names, with `log1p`, `sqrt` or `z_score`. `ltr:aggregate` applies the transforms last, after it builds the `_rank` and `_relative_score` columns and the feature-store totals. It transforms only the features in the config's feature list, which is step 2 or step 3 in [Which features the model reads](#which-features-the-model-reads), even when SSM is on. It skips any other feature that `feature_transformations` names, and logs a warning. See [`feature_transformations`](config.md#feature_transformations).
|
|
189
|
+
|
|
190
|
+
Both inference backends repeat the transforms. `ltr:aggregate` saves the steps it applied in `<modelling_dataset_path without .csv>.serving.json`. A `z_score` step keeps the mean and the standard deviation of its column. Deploy copies the steps into the model file, as the XGBoost attribute `feature_transforms`. At inference, the backend first builds the `_rank` and `_relative_score` features from the raw request values. It then applies the steps to every value in the request fields, including values for feature-store features. So send raw values for every feature.
|
|
191
|
+
|
|
192
|
+
A value read from the feature store is never transformed at inference. The store is built from the transformed modelling CSV, so its values are already on the training scale.
|
|
193
|
+
|
|
194
|
+
Deploy raises `Ltr::ConfigurationError` when the `.serving.json` file is missing. Run `ltr:aggregate` again to write it. A model file without the `feature_transforms` attribute scores the request values as they are. [Dataset serving file](model-files.md#dataset-serving-file) describes the file.
|
|
195
|
+
|
|
196
|
+
## One-hot columns
|
|
197
|
+
|
|
198
|
+
`ltr:aggregate` one-hot encodes each text column. It replaces the column with one `<column>_<value>` column for each value, which holds 1 for that value and 0 for any other. This includes the text columns from a `dataset_enricher`, which are encoded after the join. A request usually sends only the flag that is on, such as `query_type_brand` with value `1`.
|
|
199
|
+
|
|
200
|
+
In training, every other flag was `0`. So when the request fields and the feature store both leave out a one-hot column, the model uses `0`, not a missing value. A request value of `null` counts as left out. If `feature_transformations` lists the column, the `0` goes through the saved steps once. For example, a `z_score` step with a mean and standard deviation of `0.5` turns the `0` into `-1`, as in training.
|
|
201
|
+
|
|
202
|
+
`ltr:aggregate` saves the one-hot column names in the same `.serving.json` file, with `[]` when there are none. Deploy copies them into the model file, as the XGBoost attribute `one_hot_columns`. A model without that attribute leaves every missing feature as a missing value. Run `ltr:aggregate`, `ltr:train` and deploy again to get the `0` default.
|
data/docs/glossary.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Glossary
|
|
2
|
+
|
|
3
|
+
This is the master list of the terms the docs use, and the glossary on each page repeats its wording.
|
|
4
|
+
|
|
5
|
+
| Term | Meaning |
|
|
6
|
+
|---|---|
|
|
7
|
+
| BM25 | A text match score that OpenSearch computes for one field of a document, such as `bm25_name` for the product name. The host app logs it and sends it as a search-time feature. |
|
|
8
|
+
| Candidate | One document that OpenSearch returned for a search. The model gives each candidate a `score`. |
|
|
9
|
+
| Cascade | The rule that decides which documents a user examined in a session. Every document at or above the deepest position with a cascade action is examined. The documents below it are dropped unless `dataset_builder.cascade_cutoff` is `false`. |
|
|
10
|
+
| Cascade action | A configured action other than `impression`. The loaders read only the events of cascade actions, and the cascade cutoff uses only them. |
|
|
11
|
+
| Config loader | An `Ltr::ConfigLoader`, the object that holds the pipeline config. It reads the base YAML file, merges an optional override file on top, runs ERB and checks the values. |
|
|
12
|
+
| Configured action | An action that a `dataset_builder.conversion_rate_targets` entry names as a `numerator` or a `denominator`. The `_count` suffix is left off the name, so `view_count` gives the action `view`. `impression` is a configured action when a rate target names `impression_count`. |
|
|
13
|
+
| Conversion feature | A ratio of two summed `_count` columns, such as `cart_conversion`. `dataset_builder.conversion_features` lists them. It is a feature-store feature, not part of the label. |
|
|
14
|
+
| Conversion-rate target | One entry in `dataset_builder.conversion_rate_targets`. It defines a rate, `numerator / denominator`, with a `weight` and a smoothing strength `nu`. |
|
|
15
|
+
| Data split | One of `train`, `val` and `test`. Every row for a `user_query` goes into the same split. |
|
|
16
|
+
| DCG, IDCG | Discounted Cumulative Gain adds up each document's gain times `1 / log2(rank + 1)`. IDCG is the DCG of the best possible (or Ideal) order for the query. |
|
|
17
|
+
| Deploy | The last step of `ltr:train`, which saves the trained model so it can rerank searches. `deploy.enabled` sends it to a SageMaker endpoint when the metric passes `deploy.minimum_metric_value`. `deploy.local` saves it to `deploy.local_path` when the metric passes the same minimum. |
|
|
18
|
+
| Derived search-time feature | A `_rank` or `_relative_score` column that compares a document's score with the other candidates for the same query. `feature_engineering` names the methods, `rank` and `relative_score`. The gem recomputes the columns at inference. |
|
|
19
|
+
| Feature | A named number that describes one candidate, such as `bm25_name` or `purchase_count`. For each candidate, the model reads one value for each feature it uses. |
|
|
20
|
+
| Feature list | The names of the features the model reads, in order. Training picks the list and saves it in the model file. |
|
|
21
|
+
| Feature store | A table of feature-store values that deploy ships with the model when `feature_store.include_in_deployment` is `true`. Inference looks up a value in it by feature name and doc id, only when the request fields have no value for that feature. |
|
|
22
|
+
| Feature transform | A `log1p`, `sqrt` or `z_score` step that `feature_transformations` applies to a feature column. Inference repeats the same steps on every value in the request fields. |
|
|
23
|
+
| Feature-store feature | A value that describes the document for every query, such as `purchase_count`. `feature_store.features` lists them. Inference takes the value from the request fields, or from the feature store when the request has none. |
|
|
24
|
+
| Gain | The amount a document adds to DCG before the rank discount. With `ndcg_exp_gain: false`, as in the shipped config, the gain is the label. Otherwise it is `2^label - 1`. |
|
|
25
|
+
| Hit ids | The list of doc ids that one search showed, in the order the page showed them. The loader reads it from the field that `dataset_builder.hit_ids_field` names, which defaults to `query_response_hit_ids`. A doc's position is its place in that list, counted from 1. |
|
|
26
|
+
| Host app | The app that runs the search in OpenSearch, logs it to UBI and calls the gem to rerank the results. |
|
|
27
|
+
| Hyperparameter | A training setting that the model does not learn from the data, such as `max_depth` or `learning_rate`. The config keeps them under `model.hyperparameters`. `ltr:optimize` searches for better values. |
|
|
28
|
+
| Impression | One session in which the cascade marks a document as examined. A document gets at most one impression per session. |
|
|
29
|
+
| `label` | The target value for training the model. |
|
|
30
|
+
| Label transformer | The class in `label_transformer.class` that turns `raw_label` into `label`. |
|
|
31
|
+
| LambdaMART | The pairwise ranking method behind the XGBoost `rank:ndcg` objective. |
|
|
32
|
+
| Local reranker | `Ltr::Inference::LocalReranker`, the inference backend that scores candidates inside the host app's own process. It loads the model file from `deploy.local_path` by default. |
|
|
33
|
+
| Model file | The file that holds the trained model. It also holds the feature list, the feature transform steps and the one-hot column names. XGBoost picks the file format from the extension, so a `.ubj` path gives UBJSON and a `.json` path gives JSON. A local model file can also hold the feature store, in the XGBoost attribute `feature_store`. |
|
|
34
|
+
| Model package | The `model.tar.gz` file that the SageMaker deploy uploads to S3. It holds the model file as `xgboost-model.ubj` and the Python scoring code under `code/`. |
|
|
35
|
+
| Modelling CSV | The gzipped CSV that `ltr:aggregate` writes to `training.modelling_dataset_path` with `.gz` added. It has one row for each document in each query group, and a column for each feature. |
|
|
36
|
+
| NDCG | Normalized DCG, which is DCG divided by IDCG. It runs from 0 to 1. |
|
|
37
|
+
| Negative | A document with 0 impressions in every session of its query group. It is kept only when `dataset_builder.cascade_cutoff` is `false`. Its `raw_label` and `label` are 0. |
|
|
38
|
+
| One-hot column | A `<column>_<value>` column that `ltr:aggregate` makes from a text column, such as `query_type_brand`. It holds 1 for that value and 0 for any other. |
|
|
39
|
+
| OpenSearch | The search engine that runs the search and returns the candidates. It also holds the UBI indices that the dataset pipeline reads. |
|
|
40
|
+
| Payload | The data the host app passes to an inference backend to rerank one search. It holds one item for each candidate, as an array for the local reranker or under `items` for the SageMaker endpoint. |
|
|
41
|
+
| Pipeline | One of the three entry points: dataset, optimize and modelling. None of them calls another. |
|
|
42
|
+
| `qid` | The id of one query group. The gem numbers the kept groups from 1 with no gaps, after `min_documents_per_query` drops the small ones. |
|
|
43
|
+
| Query group | All rows that share a `qid`. A group holds the candidate documents for one `user_query` and one value of each `dataset_builder.additional_qid_fields` field. XGBoost builds pairs only inside a group. |
|
|
44
|
+
| `raw_label` | The sum of `weight × smoothed rate` over the conversion-rate targets. It is the label before any transformer. |
|
|
45
|
+
| Relevance grade | The `label` at or above which a document counts as relevant for `map`, `mrr`, `precision` and `recall`. It comes from `evaluation.min_relevance_grade`, or from `evaluation.min_relevance_percentile`. `ndcg` does not use it. |
|
|
46
|
+
| Request fields | The `fields` list of `{ "name": ..., "value": ... }` pairs that the host app sends with each candidate when it asks the model to rerank. Inference uses a value from them before it looks in the feature store. |
|
|
47
|
+
| Rerank | To put the candidates from OpenSearch in a new order. They are sorted by the `score` the model gives each one, highest first. |
|
|
48
|
+
| S3 | Amazon S3, the AWS file storage service. It can hold the modelling CSV, the serving file and the model package. |
|
|
49
|
+
| SageMaker endpoint | The AWS SageMaker endpoint that the SageMaker deploy creates, named `<model.name>-endpoint`. `Ltr::Inference::SagemakerClient` sends it the payload and gets the scores back. |
|
|
50
|
+
| Search-time feature | A score the search engine computes for each query and document, such as `bm25_name`. The host logs it in `query_attributes.scores` for training and sends it in the request fields at query time. `search_time_features` lists them. |
|
|
51
|
+
| Serving file | The `<modelling_dataset_path without .csv>.serving.json` file that `ltr:aggregate` writes next to the modelling CSV. It holds the feature transform steps and the one-hot column names. Deploy copies both into the model file. |
|
|
52
|
+
| Session | One search by one user, which is one record in the queries index. The docs also call it a query record. |
|
|
53
|
+
| Shipped | The value in `lib/ltr/configuration/example_config.yml`. It can differ from the value the code uses when the key is missing. |
|
|
54
|
+
| SSM | AWS Systems Manager Parameter Store. When `ssm.enabled` is `true`, the optimize pipeline writes its chosen features and hyperparameters there, and the modelling pipeline reads them. |
|
|
55
|
+
| UBI | User Behavior Insights, the query and event logs that the host app writes to OpenSearch. The shipped index names are `ubi_queries` and `ubi_events`. |
|
|
56
|
+
| XGBoost | The gradient-boosted tree library that trains the model and scores the candidates. The gem uses its `rank:ndcg` objective. |
|