@van1s1mys/ai-router 1.0.1 → 1.2.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 +37 -3
- package/dist/index.cjs +71 -3
- package/dist/index.d.cts +70 -3
- package/dist/index.d.ts +70 -3
- package/dist/index.js +71 -3
- package/package.json +45 -45
package/README.md
CHANGED
|
@@ -32,6 +32,31 @@ const result = await router.search('how to reach support?');
|
|
|
32
32
|
router.destroy(); // cleanup when done
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
+
## Progressive model loading
|
|
36
|
+
|
|
37
|
+
Start with a fast model, upgrade to a better one in the background:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
const router = new SmartRouter({
|
|
41
|
+
routes,
|
|
42
|
+
model: ['Xenova/all-MiniLM-L6-v2', 'Xenova/multilingual-e5-small'],
|
|
43
|
+
onModelUpgrade: (modelId) => console.log(`Upgraded to ${modelId}`),
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
await router.ready; // first model ready — search works immediately
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Instance caching & preloading
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
// Pre-warm at page load
|
|
53
|
+
SmartRouter.preload({ routes, model: ['Xenova/all-MiniLM-L6-v2', 'Xenova/multilingual-e5-small'] });
|
|
54
|
+
|
|
55
|
+
// Later — returns cached instance, no re-download
|
|
56
|
+
const router = SmartRouter.create({ routes, model: ['Xenova/all-MiniLM-L6-v2', 'Xenova/multilingual-e5-small'] });
|
|
57
|
+
await router.ready; // instant if preload finished
|
|
58
|
+
```
|
|
59
|
+
|
|
35
60
|
## Multilingual support
|
|
36
61
|
|
|
37
62
|
The default model (`Xenova/all-MiniLM-L6-v2`) works best for English. For other languages, use the multilingual model:
|
|
@@ -50,12 +75,21 @@ const router = new SmartRouter({
|
|
|
50
75
|
| Option | Type | Default | Description |
|
|
51
76
|
|---|---|---|---|
|
|
52
77
|
| `routes` | `RouteConfig[]` | required | Routes to index |
|
|
53
|
-
| `model` | `string` | `"Xenova/all-MiniLM-L6-v2"` |
|
|
78
|
+
| `model` | `string \| string[]` | `"Xenova/all-MiniLM-L6-v2"` | Model ID or ordered array for progressive loading |
|
|
54
79
|
| `threshold` | `number` | `0.5` | Minimum similarity score (0-1) |
|
|
80
|
+
| `onModelUpgrade` | `(modelId: string) => void` | — | Called when the router switches to the next model |
|
|
81
|
+
|
|
82
|
+
### `SmartRouter.create(options): SmartRouter`
|
|
83
|
+
|
|
84
|
+
Returns a cached instance for the given model config. Safe to call on every component mount.
|
|
85
|
+
|
|
86
|
+
### `SmartRouter.preload(options): SmartRouter`
|
|
87
|
+
|
|
88
|
+
Same as `create()`, but intended to be called at page load to pre-warm the model.
|
|
55
89
|
|
|
56
90
|
### `router.ready: Promise<void>`
|
|
57
91
|
|
|
58
|
-
Resolves when the model is loaded and routes are indexed. Resolves immediately during SSR.
|
|
92
|
+
Resolves when the first model is loaded and routes are indexed. Resolves immediately during SSR.
|
|
59
93
|
|
|
60
94
|
### `router.search(query): Promise<SearchResult | null>`
|
|
61
95
|
|
|
@@ -63,7 +97,7 @@ Returns `{ path, score }` or `null` if no route meets the threshold. Returns `nu
|
|
|
63
97
|
|
|
64
98
|
### `router.destroy()`
|
|
65
99
|
|
|
66
|
-
Terminates the worker
|
|
100
|
+
Terminates the worker, cleans up resources, and removes from cache. Safe to call multiple times.
|
|
67
101
|
|
|
68
102
|
## SSR
|
|
69
103
|
|