@van1s1mys/ai-router 1.0.0 → 1.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.
package/dist/index.d.cts CHANGED
@@ -40,11 +40,29 @@ interface RouteOptions {
40
40
  /** Array of routes to index for semantic search. */
41
41
  routes: RouteConfig[];
42
42
  /**
43
- * HuggingFace model ID for generating embeddings.
43
+ * HuggingFace model ID (or an ordered array of IDs) for generating embeddings.
44
44
  * Must produce 384-dimensional vectors.
45
+ *
46
+ * When an array is provided, the first model is loaded and used immediately.
47
+ * Heavier models are downloaded in the background; once ready, the router
48
+ * hot-swaps to the next model and re-indexes all routes automatically.
49
+ *
45
50
  * @default "Xenova/all-MiniLM-L6-v2"
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * // Start fast with a light model, upgrade to a better one in the background
55
+ * model: ['Xenova/all-MiniLM-L6-v2', 'Xenova/multilingual-e5-small']
56
+ * ```
57
+ */
58
+ model?: string | string[];
59
+ /**
60
+ * Called each time the router upgrades to the next model in the chain.
61
+ * Only relevant when {@link model} is an array with more than one entry.
62
+ *
63
+ * @param modelId - The HuggingFace model ID that just became active.
46
64
  */
47
- model?: string;
65
+ onModelUpgrade?: (modelId: string) => void;
48
66
  /**
49
67
  * Minimum similarity score (0–1) for a result to be returned.
50
68
  * Results below this threshold are discarded.
@@ -83,10 +101,13 @@ interface SearchResult {
83
101
  * { path: '/pricing', title: 'Pricing', description: 'cost, plans, subscription' },
84
102
  * { path: '/contact', title: 'Contact', description: 'support, phone, address' },
85
103
  * ],
104
+ * // Start with a fast lightweight model, then upgrade to a better one in the background
105
+ * model: ['Xenova/all-MiniLM-L6-v2', 'Xenova/multilingual-e5-small'],
86
106
  * threshold: 0.5,
107
+ * onModelUpgrade: (modelId) => console.log(`Upgraded to ${modelId}`),
87
108
  * });
88
109
  *
89
- * // Wait for the model to load (~22 MB on first run, cached afterwards)
110
+ * // Wait for the first (lightest) model to load ready to search immediately
90
111
  * await router.ready;
91
112
  *
92
113
  * // Search by meaning — typos and synonyms work too
@@ -105,6 +126,7 @@ declare class SmartRouter {
105
126
  private pendingSearches;
106
127
  private destroyed;
107
128
  private readonly ssr;
129
+ private onModelUpgrade?;
108
130
  /**
109
131
  * Creates a new SmartRouter instance.
110
132
  *
package/dist/index.d.ts CHANGED
@@ -40,11 +40,29 @@ interface RouteOptions {
40
40
  /** Array of routes to index for semantic search. */
41
41
  routes: RouteConfig[];
42
42
  /**
43
- * HuggingFace model ID for generating embeddings.
43
+ * HuggingFace model ID (or an ordered array of IDs) for generating embeddings.
44
44
  * Must produce 384-dimensional vectors.
45
+ *
46
+ * When an array is provided, the first model is loaded and used immediately.
47
+ * Heavier models are downloaded in the background; once ready, the router
48
+ * hot-swaps to the next model and re-indexes all routes automatically.
49
+ *
45
50
  * @default "Xenova/all-MiniLM-L6-v2"
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * // Start fast with a light model, upgrade to a better one in the background
55
+ * model: ['Xenova/all-MiniLM-L6-v2', 'Xenova/multilingual-e5-small']
56
+ * ```
57
+ */
58
+ model?: string | string[];
59
+ /**
60
+ * Called each time the router upgrades to the next model in the chain.
61
+ * Only relevant when {@link model} is an array with more than one entry.
62
+ *
63
+ * @param modelId - The HuggingFace model ID that just became active.
46
64
  */
47
- model?: string;
65
+ onModelUpgrade?: (modelId: string) => void;
48
66
  /**
49
67
  * Minimum similarity score (0–1) for a result to be returned.
50
68
  * Results below this threshold are discarded.
@@ -83,10 +101,13 @@ interface SearchResult {
83
101
  * { path: '/pricing', title: 'Pricing', description: 'cost, plans, subscription' },
84
102
  * { path: '/contact', title: 'Contact', description: 'support, phone, address' },
85
103
  * ],
104
+ * // Start with a fast lightweight model, then upgrade to a better one in the background
105
+ * model: ['Xenova/all-MiniLM-L6-v2', 'Xenova/multilingual-e5-small'],
86
106
  * threshold: 0.5,
107
+ * onModelUpgrade: (modelId) => console.log(`Upgraded to ${modelId}`),
87
108
  * });
88
109
  *
89
- * // Wait for the model to load (~22 MB on first run, cached afterwards)
110
+ * // Wait for the first (lightest) model to load ready to search immediately
90
111
  * await router.ready;
91
112
  *
92
113
  * // Search by meaning — typos and synonyms work too
@@ -105,6 +126,7 @@ declare class SmartRouter {
105
126
  private pendingSearches;
106
127
  private destroyed;
107
128
  private readonly ssr;
129
+ private onModelUpgrade?;
108
130
  /**
109
131
  * Creates a new SmartRouter instance.
110
132
  *