forked from run-llama/LlamaIndexTS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVectorStore.test.ts
48 lines (45 loc) · 1.77 KB
/
VectorStore.test.ts
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
import { Document, MetadataMode } from "@llamaindex/core/schema";
import {
metadataDictToNode,
nodeToMetadata,
} from "llamaindex/vector-store/utils";
import { beforeEach, describe, expect, test } from "vitest";
describe("Testing VectorStore utils", () => {
let node: Document;
beforeEach(() => {
node = new Document({
text: "text",
metadata: { meta1: "Some metadata" },
});
});
test("nodeToMetadata should not modify a node's metadata", () => {
nodeToMetadata(node, true);
expect(node.metadata).toEqual({ meta1: "Some metadata" });
});
test("metadataDictToNode should reconstructs node and remove text (except embedding)", () => {
const metadata = nodeToMetadata(node, true);
const newNode = metadataDictToNode(metadata);
expect(newNode.metadata).toEqual({ meta1: "Some metadata" });
expect(() => newNode.getEmbedding()).toThrow();
expect(newNode.getContent(MetadataMode.NONE)).toEqual("");
});
test("metadataDictToNode should reconstructs node (except embedding)", () => {
const metadata = nodeToMetadata(node, false);
const newNode = metadataDictToNode(metadata);
expect(newNode.metadata).toEqual({ meta1: "Some metadata" });
expect(newNode.getContent(MetadataMode.NONE)).toEqual("text");
expect(() => newNode.getEmbedding()).toThrow();
});
test("metadataDictToNode should not allow deep metadata if flatMetadata is true", () => {
node.metadata = { meta: { meta: "meta" } };
expect(() => nodeToMetadata(node, false, "text", true)).toThrow();
});
test("metadataDictToNode should throw an error when node content not found in metadata", () => {
const faultyMetadata = {
_node_type: "IndexNode",
};
expect(() => {
metadataDictToNode(faultyMetadata);
}).toThrow();
});
});