Skip to content

Conversation

@ChenZiHong-Gavin
Copy link
Collaborator

@ChenZiHong-Gavin ChenZiHong-Gavin commented Jan 14, 2026

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.

@github-actions github-actions bot added the core label Jan 14, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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

  • Relocated Pre-tokenization Logic: The pre-tokenization logic has been relocated from the partition_service to the light_rag_kg_builder module, ensuring token lengths are calculated earlier in the graph construction process.
  • Integrated Token Length Calculation: Token length calculation is now performed directly when nodes and edges are created or updated, storing the length attribute within their data, rather than in a separate bulk pass.
  • Generalized Type Hints: Type hints for node_data and edge_data in base_storage, kuzu_storage, and networkx_storage have been generalized from dict[str, str] to dict[str, any] to support diverse data types, including the new integer length field.
  • Removed Redundant Method: The _pre_tokenize method has been removed from partition_service.py, streamlining the partitioning process by eliminating the need for a separate tokenization step there.
  • Ensured Integer Type for Length: An explicit integer cast was added for the length attribute in ece_partitioner.py to ensure correct token sum calculations, aligning with the new integer storage of token lengths.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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)

high

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)

medium

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.

@ChenZiHong-Gavin ChenZiHong-Gavin merged commit 3688560 into main Jan 14, 2026
6 checks passed
@ChenZiHong-Gavin ChenZiHong-Gavin deleted the perf/pre-tokenize-in-build-kg branch January 14, 2026 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants