-
Notifications
You must be signed in to change notification settings - Fork 64
perf: move pre-tokenize from partition to build_kg to reduce memory #156
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
Conversation
Summary of ChangesHello @ChenZiHong-Gavin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refactors the knowledge graph construction and partitioning pipeline by moving the pre-tokenization step. Previously, a bulk tokenization pass occurred during partitioning, which could be memory-intensive. Now, token lengths are calculated and stored incrementally as nodes and edges are built, aiming to reduce overall memory footprint and improve performance by integrating this step earlier and more efficiently into the graph building process. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request refactors the pre-tokenization logic, moving it from the partitioning phase into the knowledge graph building phase. This is a sensible optimization for performance and memory usage, as it avoids loading the entire graph into memory just for tokenization. The implementation is mostly sound, but I've identified a high-severity data correctness issue, along with a couple of medium-severity suggestions to improve code quality and maintainability.
I am having trouble creating individual review comments. Click here to see my feedback.
graphgen/models/kg_builder/light_rag_kg_builder.py (169-178)
When an edge's source or target node doesn't exist, a new node is created. Currently, this new node is assigned the description of the edge. This is incorrect as a node's description should be about the entity itself, not the relationship it's involved in. This can lead to incorrect data in the knowledge graph.
A better approach is to create these implicitly-defined nodes with an empty description.
kg_instance.upsert_node(
insert_id,
node_data={
"entity_type": "UNKNOWN",
"entity_name": insert_id,
"description": "",
"source_id": source_id,
"length": 0,
},
)
graphgen/operators/partition/partition_service.py (98-131)
The _pre_tokenize method has been commented out. Instead of commenting out dead code, it's better to remove it completely to improve code clarity and maintainability.
This pull request refactors the knowledge graph construction and partitioning pipeline by moving the pre-tokenization step. Previously, a bulk tokenization pass occurred during partitioning, which could be memory-intensive. Now, token lengths are calculated and stored incrementally as nodes and edges are built, aiming to reduce overall memory footprint and improve performance by integrating this step earlier and more efficiently into the graph building process.