Spaces:
Running
Running
File size: 1,911 Bytes
abf1288 | 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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | // @vitest-environment node
/**
* Exercises the real bi-encoder end to end. Downloads ~460MB on first run, so
* it is excluded from the default suite:
*
* npx vitest run --config vitest.integration.config.ts biEncoder
*/
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import {
getBiEncoderStatus,
scorePassages,
startBiEncoderService,
stopBiEncoderService,
} from "./biEncoderService";
describe("biEncoderService", () => {
beforeAll(async () => {
await startBiEncoderService();
});
afterAll(async () => {
await stopBiEncoderService();
});
it("reports itself ready", async () => {
expect(await getBiEncoderStatus()).toBe(true);
});
it("scores a relevant passage above an unrelated one", async () => {
const [relevant, unrelated] = await scorePassages(
"how to bake sourdough bread at home",
[
"Mix the starter with flour and water, let the dough rise overnight, then bake it in a hot Dutch oven.",
"Antarctica has no permanent residents and its ice sheet holds most of the planet's fresh water.",
],
);
expect(relevant).toBeGreaterThan(unrelated);
expect(relevant).toBeGreaterThan(0.3);
});
it("matches across languages", async () => {
const [portuguese, unrelated] = await scorePassages(
"what is the capital of France",
[
"A capital da França é Paris, situada às margens do rio Sena.",
"Bubble sort repeatedly swaps adjacent elements until the list is ordered.",
],
);
expect(portuguese).toBeGreaterThan(unrelated);
});
it("returns one score per passage", async () => {
const scores = await scorePassages("query", ["one", "two", "three"]);
expect(scores).toHaveLength(3);
for (const score of scores) {
expect(score).toBeGreaterThanOrEqual(-1.001);
expect(score).toBeLessThanOrEqual(1.001);
}
});
});
|