Skip to content

Conversation

@robfrank
Copy link
Collaborator

This pull request addresses critical issues with the persistence and discovery of HNSW graph files in the LSMVectorIndex implementation, ensuring that graph data is properly flushed to disk and can be reliably recovered after database restarts. It also adds comprehensive tests to verify these behaviors and improve the robustness of the vector index subsystem.

Persistence and resource management improvements:

  • Ensured the HNSW graph file (graphFile) is properly closed and flushed to disk when the LSMVectorIndex is closed, preventing data loss and resource leaks. Error handling was added to log any exceptions during the close operation.

Logging and debugging enhancements:

  • Added detailed debug-level logging to the graph file discovery process in discoverAndLoadGraphFile(), making it easier to trace file lookup issues and understand index initialization behavior. [1] [2]

Testing and verification:

  • Introduced new tests in LSMVectorIndexTest.java to verify:
    • That the graph file is properly closed and flushed to disk, addressing the bug where graphFile.close() was not previously called.
    • That graph files can be discovered and loaded after a database reload, ensuring index recovery works as expected.
    • (Disabled) That graph persistence is maintained across multiple close/reopen cycles, confirming consistent query results if the graph is properly persisted.
    • Added a helper method for recursive directory cleanup to support test isolation.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @robfrank, 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 resolves critical issues related to the persistence and discovery of HNSW graph files within the LSMVectorIndex implementation. By ensuring that graph data is correctly flushed to disk upon database closure and can be reliably reloaded, it significantly enhances the robustness and data integrity of the vector indexing subsystem. The changes also include improved logging for easier debugging of graph file discovery and comprehensive new tests to validate these fixes.

Highlights

  • Persistence Fix: The HNSW graph file (graphFile) is now properly closed and flushed to disk when LSMVectorIndex is closed, preventing data loss and ensuring data integrity.
  • Discovery Enhancement: Detailed debug logging has been added to the discoverAndLoadGraphFile() method, along with a null check for ComponentFile, improving traceability and robustness of graph file discovery.
  • Comprehensive Testing: New tests have been introduced in LSMVectorIndexTest.java to specifically verify the proper flushing of graph files on close and their successful discovery and loading after database restarts.
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.

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 addresses a critical issue by ensuring the JVector HNSW graph file is properly closed and flushed to disk, preventing data loss on database shutdown. The changes also improve the discovery of graph files and add comprehensive tests to verify the fixes. The implementation is solid, and the tests are thorough. I've provided a couple of suggestions to enhance logging and modernize a test utility method for better maintainability.

Comment on lines 2107 to 2117
private void deleteDirectory(java.io.File directory) {
if (directory.exists()) {
final java.io.File[] files = directory.listFiles();
if (files != null) {
for (final java.io.File file : files) {
if (file.isDirectory()) {
deleteDirectory(file);
} else {
file.delete();
}
}
}
directory.delete();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This helper method for recursively deleting a directory can be simplified and made more robust by using the modern java.nio.file.Files.walk API. This approach avoids manual recursion and is generally preferred for traversing file trees.

  private void deleteDirectory(java.io.File directory) {
    if (directory.exists()) {
      try (java.util.stream.Stream<java.nio.file.Path> walk = java.nio.file.Files.walk(directory.toPath())) {
        walk.sorted(java.util.Comparator.reverseOrder())
            .map(java.nio.file.Path::toFile)
            .forEach(java.io.File::delete);
      } catch (java.io.IOException e) {
        System.err.println("Error deleting directory " + directory.getAbsolutePath() + ": " + e.getMessage());
      }
    }
  }

@mergify
Copy link
Contributor

mergify bot commented Dec 12, 2025

🧪 CI Insights

Here's what we observed from your CI run for ff6ea24.

🟢 All jobs passed!

But CI Insights is watching 👀

@codacy-production
Copy link

codacy-production bot commented Dec 12, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for 8f9ac7f1 62.50%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (8f9ac7f) Report Missing Report Missing Report Missing
Head commit (ff6ea24) 75785 48287 63.72%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#2916) 8 5 62.50%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Footnotes

  1. Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

robfrank added a commit that referenced this pull request Dec 12, 2025
Improvements to code quality and maintainability:

* Enhanced exception logging: Include full stack trace when closing graph file
  for better debugging. Changed from logging only the error message to passing
  the exception object to LogManager for complete context.

* Refactored deleteDirectory() helper: Replaced manual recursive directory
  traversal with modern java.nio.file.Files.walk() API. This approach is more
  robust, efficient, and follows Java best practices for file tree operations.
  - Uses try-with-resources for proper resource management
  - Sorts in reverse order to delete files before directories
  - Provides better exception handling with IOException

All existing tests continue to pass (22/22).

Addresses review comments from PR #2916:
- #2916 (comment)
- #2916 (comment)
Improvements to code quality and maintainability:

* Enhanced exception logging: Include full stack trace when closing graph file
  for better debugging. Changed from logging only the error message to passing
  the exception object to LogManager for complete context.

* Refactored deleteDirectory() helper: Replaced manual recursive directory
  traversal with modern java.nio.file.Files.walk() API. This approach is more
  robust, efficient, and follows Java best practices for file tree operations.
  - Uses try-with-resources for proper resource management
  - Sorts in reverse order to delete files before directories
  - Provides better exception handling with IOException

All existing tests continue to pass (22/22).

Addresses review comments from PR #2916:
- #2916 (comment)
- #2916 (comment)
@robfrank robfrank force-pushed the fix/2915-vector-index-hnsw-persistence branch from ec05c5b to ff6ea24 Compare December 14, 2025 17:32
@robfrank robfrank requested a review from lvca December 15, 2025 12:42
@lvca lvca merged commit 432707d into main Dec 15, 2025
34 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants