mbd-studio-sdk 3.2.0 → 3.3.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/README.md ADDED
@@ -0,0 +1,113 @@
1
+ # mbd-studio-sdk
2
+
3
+ SDK for MBD Studio backend services — search, features, scoring, and ranking.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install mbd-studio-sdk
9
+ ```
10
+
11
+ ## Setup
12
+
13
+ ```javascript
14
+ import { StudioConfig, StudioV1 } from 'mbd-studio-sdk';
15
+
16
+ const config = new StudioConfig({ apiKey: 'YOUR_API_KEY' });
17
+ const mbd = new StudioV1({ config });
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ### 1. Set the target user for personalization
23
+ ```javascript
24
+ const polymarketWallet = '0x123...';
25
+ mbd.forUser("polymarket-wallets", polymarketWallet);
26
+ ```
27
+
28
+ ### 2. Generate candidates
29
+
30
+ Search your mbd indices using inclide/exclude filters and boosting options.
31
+
32
+ ```javascript
33
+ const candidates = await mbd.search()
34
+ .index("polymarket-items")
35
+ .includeVectors(true)
36
+ .include()
37
+ .numeric("volume_1wk", ">=", 10000)
38
+ .exclude()
39
+ .term("closed", true)
40
+ .term("price_under05_or_over95", true)
41
+ .boost()
42
+ .groupBoost("polymarket-wallets", "ai_labels_med", polymarketWallet, "label", 1, 5, 10)
43
+ .groupBoost("polymarket-wallets", "tags", polymarketWallet, "tag", 1, 5, 10)
44
+ .execute();
45
+ ```
46
+
47
+ ### 2. Add candidates to current context
48
+
49
+ Attach the search results to the SDK so later steps can use them.
50
+
51
+ ```javascript
52
+ mbd.addCandidates(candidates);
53
+ ```
54
+
55
+ ### 3. Enrich your data
56
+
57
+ Fetch features (signals, metadata) for each candidate.
58
+
59
+ ```javascript
60
+ const features = await mbd.features("v1")
61
+ .execute();
62
+ mbd.addFeatures(features);
63
+ ```
64
+
65
+ ### 4. Run predictive and reranking AI models
66
+
67
+ Score candidates with ML models for relevance or reranking.
68
+
69
+ ```javascript
70
+ const scores = await mbd.scoring()
71
+ .model("/scoring/ranking_model/polymarket-rerank-v1")
72
+ .execute();
73
+ mbd.addScores(scores, "rerank_polymkt1");
74
+ ```
75
+
76
+ ### 5. Combine all the data into final recommendations
77
+
78
+ Merge signals and produce the final ranked list with diversity and limits.
79
+
80
+ ```javascript
81
+ const ranking = await mbd.ranking()
82
+ .sortingMethod('mix')
83
+ .mix("topic_score", 'desc', 40)
84
+ .mix("user_affinity_score", 'desc', 40)
85
+ .mix("rerank_polymkt1", 'desc', 20)
86
+ .diversity('semantic')
87
+ .lambda(0.5)
88
+ .horizon(20)
89
+ .limitByField()
90
+ .every(10)
91
+ .limit("cluster_1", 1)
92
+ .execute();
93
+ mbd.addRanking(ranking);
94
+ ```
95
+
96
+ ## API
97
+
98
+ | Method | Description |
99
+ |--------|-------------|
100
+ | `forUser(index, userId)` | Set user context for personalization |
101
+ | `search()` | Build and run a search query |
102
+ | `addCandidates(array)` | Add search hits to the current context |
103
+ | `features(version)` | Fetch features for candidates |
104
+ | `addFeatures(result)` | Attach features to candidates |
105
+ | `scoring()` | Run scoring/reranking models |
106
+ | `addScores(result, key)` | Attach model scores to candidates |
107
+ | `ranking()` | Produce final ranked recommendations |
108
+ | `addRanking(result)` | Attach ranking scores to candidates |
109
+
110
+ ## Useful links
111
+
112
+ - **Demo repo:** [https://github.com/ZKAI-Network/mbd_studio_demo](https://github.com/ZKAI-Network/mbd_studio_demo)
113
+ - **Studio webapp:** [https://api.mbd.xyz/v3/studio/frontend/](https://api.mbd.xyz/v3/studio/frontend/)
package/StudioConfig.js CHANGED
@@ -1,3 +1,6 @@
1
+ const defaultBaseUrl = 'https://api.mbd.studio/v3/studio';
2
+
3
+
1
4
  export class StudioConfig {
2
5
  constructor(options) {
3
6
  if (!options || typeof options !== 'object') {
@@ -15,10 +18,7 @@ export class StudioConfig {
15
18
  this.featuresService = url;
16
19
  this.scoringService = url;
17
20
  this.rankingService = url;
18
- } else {
19
- if (!servicesUrl || typeof servicesUrl !== 'object') {
20
- throw new Error('StudioConfig: when commonUrl is not provided, servicesUrl must be an object with searchService, storiesService, featuresService, scoringService, rankingService');
21
- }
21
+ } else if (servicesUrl && typeof servicesUrl === 'object') {
22
22
  const { searchService, storiesService, featuresService, scoringService, rankingService } = servicesUrl;
23
23
  const services = { searchService, storiesService, featuresService, scoringService, rankingService };
24
24
  const missing = Object.entries(services)
@@ -32,6 +32,12 @@ export class StudioConfig {
32
32
  this.featuresService = featuresService.trim().replace(/\/$/, '');
33
33
  this.scoringService = scoringService.trim().replace(/\/$/, '');
34
34
  this.rankingService = rankingService.trim().replace(/\/$/, '');
35
+ } else {
36
+ this.searchService = defaultBaseUrl;
37
+ this.storiesService = defaultBaseUrl;
38
+ this.featuresService = defaultBaseUrl;
39
+ this.scoringService = defaultBaseUrl;
40
+ this.rankingService = defaultBaseUrl;
35
41
  }
36
42
  this.apiKey = apiKey.trim();
37
43
  this.log = typeof log === 'function' ? log : console.log.bind(console);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mbd-studio-sdk",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "description": "SDK for MBD Studio backend services",
5
5
  "type": "module",
6
6
  "main": "index.js",