-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdb.mjs
36 lines (32 loc) · 842 Bytes
/
db.mjs
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
30
31
32
33
34
35
36
import { count, create } from "@orama/orama";
import {
restoreFromFile,
persistToFile,
// @ts-ignore
} from "@orama/plugin-data-persistence/server";
let db;
try {
db = await restoreFromFile("binary", "./.dbfile.msp");
console.log("db restored from file");
} catch {
console.log("no db file found, creating new db");
/* note: changing the embedding function means you have
to change the vector size in the db declaration in db.mjs as well
openai size: 1536
HF size: 384
*/
db = await create({
schema: {
parent: "string",
tags: "string[]",
embedding: "vector[384]",
content: "string",
},
id: "oramadb",
});
await persistToFile(db, "binary", "./.dbfile.msp");
} finally {
const dbCount = await count(db);
console.log(`db has ${dbCount} entries`);
}
export default db;