@ai4data/search 0.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/README.md +88 -0
- package/dist/index.d.mts +693 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/dist/rank-worker.mjs +2910 -0
- package/dist/rank-worker.mjs.map +1 -0
- package/dist/worker.mjs +1866 -0
- package/dist/worker.mjs.map +1 -0
- package/package.json +59 -0
package/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# @ai4data/search
|
|
2
|
+
|
|
3
|
+
Framework-agnostic semantic search client for the **AI for Data – Data for AI** program. Combines HNSW approximate nearest-neighbour search, BM25 lexical search, and hybrid ranking — all running in a Web Worker. Published under the [@ai4data](https://www.npmjs.com/org/ai4data) npm organization.
|
|
4
|
+
|
|
5
|
+
**Browser only:** requires a browser environment (Web Workers, `fetch`, Cache API).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @ai4data/search
|
|
11
|
+
# or
|
|
12
|
+
yarn add @ai4data/search
|
|
13
|
+
# or
|
|
14
|
+
pnpm add @ai4data/search
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { SearchClient } from '@ai4data/search'
|
|
21
|
+
|
|
22
|
+
const client = new SearchClient('https://example.com/data/your-collection/manifest.json')
|
|
23
|
+
|
|
24
|
+
client.on('index_ready', () => {
|
|
25
|
+
client.search('climate finance', { topK: 10, mode: 'hybrid' })
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
client.on('results', ({ data, stats }) => {
|
|
29
|
+
console.log(data) // SearchResult[]
|
|
30
|
+
console.log(stats) // SearchStats | null
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
// Clean up when done
|
|
34
|
+
client.destroy()
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Custom worker path
|
|
38
|
+
|
|
39
|
+
If your bundler does not resolve the default worker URL, pass a factory:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
new SearchClient(manifestUrl, {
|
|
43
|
+
workerFactory: () => new Worker(
|
|
44
|
+
new URL('@ai4data/search/worker', import.meta.url),
|
|
45
|
+
{ type: 'module' }
|
|
46
|
+
)
|
|
47
|
+
})
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Rerank worker (optional)
|
|
51
|
+
|
|
52
|
+
For cross-encoder reranking of results, use the separate rank worker:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
const rankWorker = new Worker(
|
|
56
|
+
new URL('@ai4data/search/rank-worker', import.meta.url),
|
|
57
|
+
{ type: 'module' }
|
|
58
|
+
)
|
|
59
|
+
// Send { query, documents, top_k } and receive scored results
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Vue and React adapters are planned (future: `@ai4data/search/vue`, `@ai4data/search/react`).
|
|
63
|
+
|
|
64
|
+
## Development
|
|
65
|
+
|
|
66
|
+
From the repo root (with workspaces):
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
npm install
|
|
70
|
+
npm run build --workspace=@ai4data/search
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Or from this directory:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
cd packages/ai4data/search
|
|
77
|
+
npm install
|
|
78
|
+
npm run build
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Documentation
|
|
82
|
+
|
|
83
|
+
- [Main project docs](https://worldbank.github.io/ai4data)
|
|
84
|
+
- [Repo structure](../../../docs/repo-structure.md)
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
|
|
88
|
+
MIT License with World Bank IGO Rider. See [LICENSE](../../../LICENSE) in the repo root.
|