How can I get nodes and relationships to have properties in LLMGraphTransformer #6036
Replies: 1 comment 2 replies
-
To get nodes and relationships to have properties in function createSchema(allowedNodes: string[], allowedRelationships: string[]) {
const dynamicGraphSchema = z.object({
nodes: z
.array(
z.object({
id: z.string(),
type: createOptionalEnumType({
enumValues: allowedNodes,
description: "The type or label of the node.",
}),
properties: z.record(z.string(), z.any()).optional(), // Add properties field
})
)
.describe("List of nodes"),
relationships: z
.array(
z.object({
sourceNodeId: z.string(),
sourceNodeType: createOptionalEnumType({
enumValues: allowedNodes,
description: "The source node of the relationship.",
}),
relationshipType: createOptionalEnumType({
enumValues: allowedRelationships,
description: "The type of the relationship.",
isRel: true,
}),
targetNodeId: z.string(),
targetNodeType: createOptionalEnumType({
enumValues: allowedNodes,
description: "The target node of the relationship.",
}),
properties: z.record(z.string(), z.any()).optional(), // Add properties field
})
)
.describe("List of relationships."),
});
return dynamicGraphSchema;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function mapToBaseNode(node: any): Node {
return new Node({
id: node.id,
type: node.type ? toTitleCase(node.type) : "",
properties: node.properties || {}, // Map properties
});
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function mapToBaseRelationship(relationship: any): Relationship {
return new Relationship({
source: new Node({
id: relationship.sourceNodeId,
type: relationship.sourceNodeType
? toTitleCase(relationship.sourceNodeType)
: "",
}),
target: new Node({
id: relationship.targetNodeId,
type: relationship.targetNodeType
? toTitleCase(relationship.targetNodeType)
: "",
}),
type: relationship.relationshipType.replace(" ", "_").toUpperCase(),
properties: relationship.properties || {}, // Map properties
});
} By adding the |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Checked other resources
Commit to Help
Example Code
Description
I am trying to generate a knowledge which is working well. However I see no doc or mention of how to add properties to nodes and relationships.
System Info
langchain: 0.2.9
Beta Was this translation helpful? Give feedback.
All reactions