mbd-studio-sdk 4.3.0 → 4.5.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.
package/V1/Studio.js CHANGED
@@ -120,20 +120,16 @@ export class Studio {
120
120
  origin: this._origin,
121
121
  });
122
122
  }
123
- /** Maps ranked item IDs to scores (1.0 for rank 0, decreasing by rank). Merges into hit._scores[scoringKey]. */
123
+ /** Maps scoring result [{id, score}, ...] into hit._scores[scoringKey]. */
124
124
  addScores(scoringResult, scoringKey) {
125
- const rankedItemIds = scoringResult;
126
- if (!this._candidates || !rankedItemIds || !Array.isArray(rankedItemIds)) return;
127
- const rankToScore = {};
128
- rankedItemIds.forEach((itemId, index) => {
129
- rankToScore[itemId] = 1.0 - (index / rankedItemIds.length);
130
- });
125
+ if (!this._candidates || !scoringResult || !Array.isArray(scoringResult)) return;
126
+ const scoreByItemId = {};
127
+ scoringResult.forEach(({ id, score }) => { scoreByItemId[String(id)] = score; });
131
128
  for (const hit of this._candidates) {
132
- const hitId = hit._id;
133
- const hitScore = rankToScore[hitId];
134
- if (hitScore) {
129
+ const hitScore = scoreByItemId[String(hit._id)];
130
+ if (hitScore != null) {
135
131
  if (!hit._scores) hit._scores = {};
136
- hit._scores[scoringKey] = rankToScore[hitId];
132
+ hit._scores[scoringKey] = hitScore;
137
133
  }
138
134
  }
139
135
  }
package/index.d.ts CHANGED
@@ -208,7 +208,7 @@ export class Studio {
208
208
  features(version?: string): Features;
209
209
  addFeatures(featuresResult: FeaturesResult): void;
210
210
  scoring(): Scoring;
211
- addScores(scoringResult: string[], scoringKey: string): void;
211
+ addScores(scoringResult: Array<{ id: string; score: number }>, scoringKey: string): void;
212
212
  ranking(): Ranking;
213
213
  addRanking(rankingResult: { items?: RankingItem[] }): void;
214
214
  log(string: string): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mbd-studio-sdk",
3
- "version": "4.3.0",
3
+ "version": "4.5.0",
4
4
  "description": "SDK for Embed Recommendation Engine APIs",
5
5
  "keywords": [
6
6
  "web3",