diff --git a/packages/core/tests/node-parser/text-splitter.test.ts b/packages/core/tests/node-parser/text-splitter.test.ts index 1ccf9a93ab8772cef1d1550c467254f2291e90ad..53189649206d885b9bd156c246bfc530dd335cfc 100644 --- a/packages/core/tests/node-parser/text-splitter.test.ts +++ b/packages/core/tests/node-parser/text-splitter.test.ts @@ -2,6 +2,7 @@ import { SentenceSplitter, splitBySentenceTokenizer, } from "@llamaindex/core/node-parser"; +import { Document } from "@llamaindex/core/schema"; import { describe, expect, test } from "vitest"; describe("sentence splitter", () => { @@ -115,4 +116,26 @@ describe("sentence splitter", () => { const split = splitBySentenceTokenizer(); 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); + }); + }); });