Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for Node and Relationship Properties in LLMGraphTransformer for LLMs without native function calling #42

Conversation

dhiaaeddine16
Copy link

@dhiaaeddine16 dhiaaeddine16 commented Feb 4, 2025

This pull request addresses #40 by introducing support for the node_properties and relationship_properties parameters in the LLMGraphTransformer for LLMs without native function calling. Previously, the LLMGraphTransformer restricted the use of these parameters when working with LLMs lacking native function calling capabilities or when ignore_tool_usage was set to True. This limitation compelled users to choose between utilizing lightweight or open-source LLMs without structured property enforcement and opting for more costly or proprietary models that support function calling. The current update removes this restriction, enabling the use of node_properties and relationship_properties across a broader range of LLMs, thereby enhancing flexibility and functionality.

@dhiaaeddine16
Copy link
Author

Hi @ccurme, @efriis, @Levara, @tomasonjo could someone please review this PR? 🙏
Let me know if any adjustments are needed!

@dhiaaeddine16
Copy link
Author

dhiaaeddine16 commented Feb 9, 2025

Hi @kartikpersistent, @kaustubh-darekar

Following our discussion in Issue #1002, I’ve implemented support for node_properties and relationship_properties in the LLMGraphTransformer for LLMs without native function calling or when ignore_tool_usage was set to True.

@tomasonjo
Copy link
Contributor

Which models have you tested this with? Looks a bit complicated for the LLM

@dhiaaeddine16
Copy link
Author

I have tested it with Llama-3.3-70B-Instruct-Turbo.

@tomasonjo
Copy link
Contributor

Can you try with some 7b models?

@dhiaaeddine16
Copy link
Author

dhiaaeddine16 commented Feb 9, 2025

with this conf:

text = """
Marie Curie, born in 1867, was a Polish and naturalised-French physicist and chemist who conducted pioneering research on radioactivity.
She was the first woman to win a Nobel Prize, the first person to win a Nobel Prize twice, and the only person to win a Nobel Prize in two scientific fields.
Her husband, Pierre Curie, was a co-winner of her first Nobel Prize, making them the first-ever married couple to win the Nobel Prize and launching the Curie family legacy of five Nobel Prizes.
She was, in 1906, the first woman to become a professor at the University of Paris.
"""
model_name = "mistralai/Mistral-7B-Instruct-v0.2"
llowed_nodes = ["Award", "Person", "Country", "Organization"]
allowed_relationships = [
    ("Person", "SPOUSE", "Person"),
    ("Person", "NATIONALITY", "Country"),
    ("Person", "WORKED_AT", "Organization"),
    ("Person", "LOCATED_IN", "Country"),
    ("Person", "AWARDED", "Award"),
]
node_properties=["born_year"]
relationship_properties=["role"]
additional_instructions = """- Your goal is to identify and categorize entities while ensuring that specific data types such as dates, numbers, revenues, and other non-entity information are not extracted as separate entity. Instead, treat these as properties associated with the relevant entities."""
ignore_tool_usage = True
strict_mode = True
GraphDocument(nodes=[Node(id='Marie Curie', type='Person', properties={'born_year': '1867'}), Node(id='Poland', type='Country', properties={}), Node(id='France', type='Country', properties={}), Node(id='University of Paris', type='Organization', properties={}), Node(id='Nobel Prize', type='Award', properties={}), Node(id='Pierre Curie', type='Person', properties={})], relationships=[Relationship(source=Node(id='Marie Curie', type='Person', properties={}), target=Node(id='Poland', type='Country', properties={}), type='NATIONALITY', properties={}), Relationship(source=Node(id='Marie Curie', type='Person', properties={}), target=Node(id='France', type='Country', properties={}), type='NATIONALITY', properties={}), Relationship(source=Node(id='Marie Curie', type='Person', properties={}), target=Node(id='University of Paris', type='Organization', properties={}), type='WORKED_AT', properties={'role': 'professor'}), Relationship(source=Node(id='Marie Curie', type='Person', properties={}), target=Node(id='Nobel Prize', type='Award', properties={}), type='AWARDED', properties={}), Relationship(source=Node(id='Marie Curie', type='Person', properties={}), target=Node(id='Nobel Prize', type='Award', properties={}), type='AWARDED', properties={'role': 'co-winner'}), Relationship(source=Node(id='Pierre Curie', type='Person', properties={}), target=Node(id='Marie Curie', type='Person', properties={}), type='SPOUSE', properties={}), Relationship(source=Node(id='Marie Curie', type='Person', properties={}), target=Node(id='Nobel Prize', type='Award', properties={}), type='AWARDED', properties={'role': 'co-winner'})], source=Document(metadata={}, page_content='\nMarie Curie, born in 1867, was a Polish and naturalised-French physicist and chemist who conducted pioneering research on radioactivity.\nShe was the first woman to win a Nobel Prize, the first person to win a Nobel Prize twice, and the only person to win a Nobel Prize in two scientific fields.\nHer husband, Pierre Curie, was a co-winner of her first Nobel Prize, making them the first-ever married couple to win the Nobel Prize and launching the Curie family legacy of five Nobel Prizes.\nShe was, in 1906, the first woman to become a professor at the University of Paris.\n'))

Screenshot 2025-02-09 113851

@dhiaaeddine16
Copy link
Author

If issues occur with small models, we can separate the two prompts—the new one and the old one—and create two modes: advanced and simple.

@tomasonjo
Copy link
Contributor

tomasonjo commented Feb 9, 2025 via email

@dhiaaeddine16
Copy link
Author

Hi @tomasonjo, thanks for your valuable input. Based on your suggestion, I've updated the implementation so that the prompt is modified only when node_properties or relationship_properties are explicitly provided. This ensures that if these parameters aren’t defined, the prompt remains unchanged, thereby avoiding any breaking changes for users who rely on the default behavior.

I'll proceed with testing the updated code with both the enhanced configuration and the default setup. Please let me know if you have any further suggestions or concerns.

@dhiaaeddine16
Copy link
Author

Hi @ccurme, @efriis, @Levara, @tomasonjo could someone please review this PR?

@tomasonjo
Copy link
Contributor

tomasonjo commented Feb 16, 2025 via email

@dhiaaeddine16 dhiaaeddine16 force-pushed the Support-node_properties/relationship_properties-in-LLMGraphTransformer-for-LLMs-without-native-function-calling branch from db4b777 to 930f13f Compare February 16, 2025 15:11
@dhiaaeddine16 dhiaaeddine16 force-pushed the Support-node_properties/relationship_properties-in-LLMGraphTransformer-for-LLMs-without-native-function-calling branch from 930f13f to b3172d8 Compare February 16, 2025 15:12
@dhiaaeddine16 dhiaaeddine16 deleted the Support-node_properties/relationship_properties-in-LLMGraphTransformer-for-LLMs-without-native-function-calling branch March 2, 2025 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants