-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanifest.ts
More file actions
68 lines (60 loc) · 1.32 KB
/
Copy pathmanifest.ts
File metadata and controls
68 lines (60 loc) · 1.32 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
export type ManifestModel = {
id: string;
dimensions: number;
};
export type ManifestItem = {
id: string;
label: string;
imagePath: string;
vector: number[];
floor?: string;
zone?: string;
x?: number;
y?: number;
};
export type EmbeddingManifest = {
model: ManifestModel;
items: ManifestItem[];
};
export type VectorizeRecord = {
id: string;
values: number[];
metadata: {
label: string;
imagePath: string;
floor?: string;
zone?: string;
x?: number;
y?: number;
};
};
export function validateManifest(manifest: EmbeddingManifest): string[] {
const errors: string[] = [];
const seen = new Set<string>();
for (const item of manifest.items) {
if (seen.has(item.id)) {
errors.push(`${item.id}: duplicate id`);
}
seen.add(item.id);
if (item.vector.length !== manifest.model.dimensions) {
errors.push(
`${item.id}: vector dimension ${item.vector.length} does not match model dimension ${manifest.model.dimensions}`,
);
}
}
return errors;
}
export function toVectorizeRecord(item: ManifestItem): VectorizeRecord {
return {
id: item.id,
values: item.vector,
metadata: {
label: item.label,
floor: item.floor,
zone: item.zone,
x: item.x,
y: item.y,
imagePath: item.imagePath,
},
};
}