Skip to content
Snippets Groups Projects
Unverified Commit 83f2848d authored by Thuc Pham's avatar Thuc Pham Committed by GitHub
Browse files

feat: add test split nodes with UUID (#1315)

parent 313071e9
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ import { ...@@ -2,6 +2,7 @@ import {
SentenceSplitter, SentenceSplitter,
splitBySentenceTokenizer, splitBySentenceTokenizer,
} from "@llamaindex/core/node-parser"; } from "@llamaindex/core/node-parser";
import { Document } from "@llamaindex/core/schema";
import { describe, expect, test } from "vitest"; import { describe, expect, test } from "vitest";
describe("sentence splitter", () => { describe("sentence splitter", () => {
...@@ -115,4 +116,26 @@ describe("sentence splitter", () => { ...@@ -115,4 +116,26 @@ describe("sentence splitter", () => {
const split = splitBySentenceTokenizer(); const split = splitBySentenceTokenizer();
expect(split(text)).toEqual([text]); expect(split(text)).toEqual([text]);
}); });
test("split nodes with UUID IDs and correct relationships", () => {
const UUID_REGEX =
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
const sentenceSplitter = new SentenceSplitter();
const docId = "test-doc-id";
const doc = new Document({
id_: docId,
text: "This is a test sentence. This is another test sentence.",
});
const nodes = sentenceSplitter.getNodesFromDocuments([doc]);
nodes.forEach((node) => {
// test node id should match uuid regex
expect(node.id_).toMatch(UUID_REGEX);
// test source reference to the doc ID
const source = node.relationships?.SOURCE;
expect(source).toBeDefined();
expect(source).toHaveProperty("nodeId");
expect((source as { nodeId: string }).nodeId).toEqual(docId);
});
});
}); });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment