-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascript.cjs
More file actions
29 lines (26 loc) · 1.04 KB
/
Copy pathjavascript.cjs
File metadata and controls
29 lines (26 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'use strict';
const { mkdtempSync, rmSync } = require('node:fs');
const { tmpdir } = require('node:os');
const { join } = require('node:path');
const { Store } = require('..');
// A store is a persistent directory. This temporary directory keeps the
// example self-cleaning; use an application path to reopen it later.
const directory = mkdtempSync(join(tmpdir(), 'zeppelin-node-js-'));
const store = new Store(join(directory, 'index'));
try {
// Applications provide vectors and stable bigint document IDs. The second
// argument fixes the vector dimension for this ingest batch.
store.ingest(
[
{ id: 1n, vector: new Float32Array([0.9, 0.1, 0.05, 0]) },
{ id: 2n, vector: new Float32Array([0.1, 0.9, 0.05, 0]) },
],
4,
);
// Query vectors must use the same dimension and embedding space.
console.log(store.search(new Float32Array([0.88, 0.12, 0.07, 0.02]), 1));
} finally {
// Close releases the native handle before the example removes its files.
store.close();
rmSync(directory, { force: true, recursive: true });
}