Skip to content
Snippets Groups Projects
Unverified Commit b68d8697 authored by Marcus Schiesser's avatar Marcus Schiesser Committed by GitHub
Browse files

fix: add missing metadata after node parsing (#317)

parent 7704df50
No related branches found
No related tags found
No related merge requests found
......@@ -53,6 +53,10 @@ export function getNodesFromDocument(
const node = new TextNode({
text: textSplit,
metadata: includeMetadata ? _.cloneDeep(document.metadata) : {},
excludedEmbedMetadataKeys: _.cloneDeep(
document.excludedEmbedMetadataKeys,
),
excludedLlmMetadataKeys: _.cloneDeep(document.excludedLlmMetadataKeys),
});
node.relationships[NodeRelationship.SOURCE] = document.asRelatedNodeInfo();
nodes.push(node);
......
import { Document } from "../../Node";
import { SimpleNodeParser } from "../../nodeParsers";
describe("SimpleNodeParser", () => {
let simpleNodeParser: SimpleNodeParser;
beforeEach(() => {
simpleNodeParser = new SimpleNodeParser({
chunkSize: 1024,
chunkOverlap: 20,
});
});
test("getNodesFromDocuments should return child nodes with equal but not the same metadata", () => {
const doc = new Document({
text: "Hello. Cat Mouse. Dog.",
metadata: { animals: true },
excludedLlmMetadataKeys: ["animals"],
excludedEmbedMetadataKeys: ["animals"],
});
const result = simpleNodeParser.getNodesFromDocuments([doc]);
expect(result.length).toEqual(1);
const node = result[0];
// check not the same object
expect(node.metadata).not.toBe(doc.metadata);
expect(node.excludedLlmMetadataKeys).not.toBe(doc.excludedLlmMetadataKeys);
expect(node.excludedEmbedMetadataKeys).not.toBe(
doc.excludedEmbedMetadataKeys,
);
// but the same content
expect(node.metadata).toEqual(doc.metadata);
expect(node.excludedLlmMetadataKeys).toEqual(doc.excludedLlmMetadataKeys);
expect(node.excludedEmbedMetadataKeys).toEqual(
doc.excludedEmbedMetadataKeys,
);
// check relationship
expect(node.sourceNode?.nodeId).toBe(doc.id_);
});
});
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