summaryrefslogtreecommitdiff
path: root/chromium/components/history_clusters/core/on_device_clustering_features.cc
blob: 4090f3d45cff5c486e2786e3aa0f733360c64d79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/history_clusters/core/on_device_clustering_features.h"

#include <algorithm>
#include "base/command_line.h"
#include "base/metrics/field_trial_params.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "build/build_config.h"

namespace history_clusters {
namespace features {

const base::Feature kOnDeviceClustering{"HistoryClustersOnDeviceClustering",
                                        base::FEATURE_ENABLED_BY_DEFAULT};

const base::Feature kUseEngagementScoreCache{"JourneysUseEngagementScoreCache",
                                             base::FEATURE_ENABLED_BY_DEFAULT};

const base::Feature kSplitClusteringTasksToSmallerBatches{
    "JourneysSplitClusteringTasksToSmallerBatches",
    base::FEATURE_ENABLED_BY_DEFAULT};

base::TimeDelta ClusterNavigationTimeCutoff() {
  return base::Minutes(GetFieldTrialParamByFeatureAsInt(
      kOnDeviceClustering, "navigation_time_cutoff_minutes", 60));
}

bool ContentClusteringEnabled() {
  return GetFieldTrialParamByFeatureAsBool(kOnDeviceClustering,
                                           "content_clustering_enabled", true);
}

float ContentClusteringEntitySimilarityWeight() {
  return GetFieldTrialParamByFeatureAsDouble(
      kOnDeviceClustering, "content_clustering_entity_similarity_weight", 1.0);
}

float ContentClusteringCategorySimilarityWeight() {
  return GetFieldTrialParamByFeatureAsDouble(
      kOnDeviceClustering, "content_clustering_category_similarity_weight",
      1.0);
}

float ContentClusteringSimilarityThreshold() {
  float threshold = GetFieldTrialParamByFeatureAsDouble(
      kOnDeviceClustering, "content_clustering_similarity_threshold", 0.2);
  // Ensure that the value is [0.0 and 1.0].
  return std::max(0.0f, std::min(1.0f, threshold));
}

float ContentVisibilityThreshold() {
  float threshold = GetFieldTrialParamByFeatureAsDouble(
      kOnDeviceClustering, "content_visibility_threshold", 0.7);
  // Ensure that the value is [0.0 and 1.0].
  return std::max(0.0f, std::min(1.0f, threshold));
}

int64_t GetMinPageTopicsModelVersionToUseContentVisibilityFrom() {
  std::string value_as_string = GetFieldTrialParamValueByFeature(
      kOnDeviceClustering, "min_page_topics_model_version_for_visibility");
  int64_t value_as_int = 0;
  if (!base::StringToInt64(value_as_string, &value_as_int)) {
    value_as_int = INT64_MAX;
  }
  return value_as_int;
}

bool ShouldHideSingleVisitClustersOnProminentUISurfaces() {
  return GetFieldTrialParamByFeatureAsBool(
      kOnDeviceClustering,
      "hide_single_visit_clusters_on_prominent_ui_surfaces", true);
}

bool ShouldDedupeSimilarVisits() {
  return GetFieldTrialParamByFeatureAsBool(kOnDeviceClustering,
                                           "dedupe_similar_visits", true);
}

bool ShouldFilterNoisyClusters() {
  return GetFieldTrialParamByFeatureAsBool(kOnDeviceClustering,
                                           "filter_noisy_clusters", true);
}

float NoisyClusterVisitEngagementThreshold() {
  float threshold = GetFieldTrialParamByFeatureAsDouble(
      kOnDeviceClustering, "noisy_cluster_visit_engagement_threshold", 15.0);
  return threshold;
}

size_t NumberInterestingVisitsFilterThreshold() {
  int threshold = GetFieldTrialParamByFeatureAsInt(
      kOnDeviceClustering, "num_interesting_visits_filter_threshold", 1);
  return threshold;
}

float VisitDurationRankingWeight() {
  float weight = GetFieldTrialParamByFeatureAsDouble(
      kOnDeviceClustering, "visit_duration_ranking_weight", 1.0);
  return std::max(0.f, weight);
}

float ForegroundDurationRankingWeight() {
  float weight = GetFieldTrialParamByFeatureAsDouble(
      kOnDeviceClustering, "foreground_duration_ranking_weight", 1.5);
  return std::max(0.f, weight);
}

float BookmarkRankingWeight() {
  float weight = GetFieldTrialParamByFeatureAsDouble(
      kOnDeviceClustering, "bookmark_ranking_weight", 1.0);
  return std::max(0.f, weight);
}

float SearchResultsPageRankingWeight() {
  float weight = GetFieldTrialParamByFeatureAsDouble(
      kOnDeviceClustering, "search_results_page_ranking_weight", 2.0);
  return std::max(0.f, weight);
}

float HasPageTitleRankingWeight() {
  float weight = GetFieldTrialParamByFeatureAsDouble(
      kOnDeviceClustering, "has_page_title_ranking_weight", 2.0);
  return std::max(0.f, weight);
}

bool ContentClusterOnIntersectionSimilarity() {
  return GetFieldTrialParamByFeatureAsBool(
      kOnDeviceClustering, "use_content_clustering_intersection_similarity",
      true);
}

int ClusterIntersectionThreshold() {
  return GetFieldTrialParamByFeatureAsInt(
      kOnDeviceClustering, "content_clustering_intersection_threshold", 2);
}

bool ShouldIncludeCategoriesInKeywords() {
  return GetFieldTrialParamByFeatureAsBool(
      kOnDeviceClustering, "include_categories_in_keywords", true);
}

bool ShouldExcludeKeywordsFromNoisyVisits() {
  return GetFieldTrialParamByFeatureAsBool(
      kOnDeviceClustering, "exclude_keywords_from_noisy_visits", false);
}

size_t GetClusteringTasksBatchSize() {
  return GetFieldTrialParamByFeatureAsInt(
      features::kSplitClusteringTasksToSmallerBatches,
      "clustering_task_batch_size", 250);
}

bool ShouldSplitClustersAtSearchVisits() {
  return GetFieldTrialParamByFeatureAsBool(
      kOnDeviceClustering, "split_clusters_at_search_visits", true);
}

}  // namespace features
}  // namespace history_clusters