-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquery.mjs
27 lines (26 loc) · 889 Bytes
/
query.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
import { count, search, searchVector } from "@orama/orama";
import { Command } from "commander";
import db from "./db.mjs";
import getEmbedding from "./embedding.mjs";
const program = new Command();
program.option("-q, --query <query>");
program.parse();
const options = program.opts();
const { query } = options;
const dbCount = await count(db);
console.log(`db has ${dbCount} entries`);
const queryEmbedding = await getEmbedding(query);
const results = await searchVector(db, {
vector: queryEmbedding,
property: "embedding",
similarity: 0.8,
limit: 10,
});
console.log(`${results.hits.length} results for "${query}"`);
results.hits.forEach((hit) => {
console.log(`score: ${hit.score}, from ${hit.document?.parent}`);
console.log("=============================");
console.log(hit.document?.content);
console.log("=============================\n\n");
});
process.exit(0);