Repository navigation
Expand file tree
/
Copy pathbackends.test.ts
More file actions
122 lines (115 loc) · 3.21 KB
/
Copy pathbackends.test.ts
File metadata and controls
122 lines (115 loc) · 3.21 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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import { describe, expect, it } from "vitest";
import { createLocalSearchBackend, createVectorizeSearchBackend } from "../src/backends";
describe("createLocalSearchBackend", () => {
it("내장 갤러리에서 공개 가능한 위치 후보만 반환한다", async () => {
const backend = createLocalSearchBackend([
{
id: "starfield",
label: "별마당도서관 북측",
floor: "B1",
zone: "ZONE-01",
x: 20,
y: 35,
imagePath: "/gallery/starfield.jpg",
vector: [1, 0, 0],
},
]);
const [result] = await backend.search([1, 0, 0], 1);
expect(result).toMatchObject({
id: "starfield",
label: "별마당도서관 북측",
rank: 1,
score: 1,
});
expect(result).not.toHaveProperty("vector");
});
});
describe("createVectorizeSearchBackend", () => {
it("Vectorize matches metadata를 위치 후보 응답으로 변환한다", async () => {
const backend = createVectorizeSearchBackend({
async query(vector, options) {
expect(vector).toEqual([1, 0, 0]);
expect(options).toMatchObject({ topK: 2, returnMetadata: "all" });
return {
matches: [
{
id: "coex-sample-01",
score: 0.98,
metadata: {
label: "별마당도서관 북측",
floor: "B1",
zone: "ZONE-01",
x: 20,
y: 35,
imagePath: "/gallery/coex-sample-01.jpg",
},
},
],
};
},
});
await expect(backend.search([1, 0, 0], 2)).resolves.toEqual([
{
id: "coex-sample-01",
label: "별마당도서관 북측",
floor: "B1",
zone: "ZONE-01",
x: 20,
y: 35,
imagePath: "/gallery/coex-sample-01.jpg",
score: 0.98,
rank: 1,
},
]);
});
it("D1 metadata store가 있으면 Vectorize 결과를 위치 메타데이터로 보강한다", async () => {
const backend = createVectorizeSearchBackend(
{
async query() {
return {
matches: [
{
id: "coex-keyframe-001",
score: 0.91,
metadata: {
label: "coex-keyframe-001",
},
},
],
};
},
},
{
async getByIds(ids) {
expect(ids).toEqual(["coex-keyframe-001"]);
return new Map([
[
"coex-keyframe-001",
{
label: "별마당도서관 북측",
floor: "B1",
zone: "STARFIELD",
x: 20,
y: 35,
imagePath: "/keyframes/coex/B1/starfield/coex-keyframe-001.jpg",
},
],
]);
},
},
);
await expect(backend.search([1, 0, 0], 1)).resolves.toEqual([
{
id: "coex-keyframe-001",
label: "별마당도서관 북측",
floor: "B1",
zone: "STARFIELD",
x: 20,
y: 35,
imagePath: "/keyframes/coex/B1/starfield/coex-keyframe-001.jpg",
score: 0.91,
rank: 1,
},
]);
});
});