Skip to content

Conversation

@majiayu000
Copy link

Summary

Implements a centralized index registry at ~/.leann/indexes.json that stores all LEANN index paths, enabling O(1) lookup instead of directory scanning.

Changes

  • Add register_index/unregister_index/list_registered_indexes functions in registry.py
  • Update leann build to register indexes in global registry
  • Update leann list to use registry when available (with scan fallback)
  • Update leann remove to unregister indexes from registry
  • Auto-cleanup stale registry entries on list
  • Add comprehensive tests for registry functionality

How it works

When registry is used, leann list output shows:

📊 Total: 3 indexes across 2 projects
⚡ Using global registry (O(1) lookup)

When falling back to scan (for legacy indexes):

📊 Total: 3 indexes across 2 projects
🔍 Using directory scan (run 'leann build' to enable fast registry)

Test plan

  • Unit tests for registry functions (register/unregister/list)
  • Test stale entry cleanup
  • Test list_indexes uses registry when available
  • All 14 tests pass

Closes #198

🤖 Generated with Claude Code

majiayu000 and others added 3 commits December 25, 2025 11:58
Fixes yichuan-w#122

The `leann list` command was scanning entire directory trees using
`rglob()`, causing extremely slow performance when run in large
directories like $HOME.

Changes:
- Add `_find_meta_files_limited()` method with max_depth parameter
- Skip common large directories (node_modules, .venv, .git, etc.)
- Apply limited search in `_discover_indexes_in_project()` and
  `_find_all_matching_indexes()`
- Add `_has_app_indexes_limited()` in registry.py for faster checks
- Add comprehensive tests for the new functionality

Signed-off-by: majiayu000 <[email protected]>
Address reviewer feedback by making the directory scan depth configurable
instead of hardcoding it to 3. Users with deeply nested project structures
can now increase the depth limit as needed.

- Add --max-depth argument to list command (default: 3)
- Update list_indexes() and _discover_indexes_in_project() to accept max_depth
- Add tests for the new CLI option and custom depth behavior

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Implements a centralized index registry at ~/.leann/indexes.json that
stores all LEANN index paths, enabling O(1) lookup instead of directory
scanning.

Changes:
- Add register_index/unregister_index/list_registered_indexes functions
- Update leann build to register indexes in global registry
- Update leann list to use registry when available (with scan fallback)
- Update leann remove to unregister indexes from registry
- Auto-cleanup stale registry entries on list
- Add comprehensive tests for registry functionality

When registry is used, `leann list` output shows:
  ⚡ Using global registry (O(1) lookup)

When falling back to scan:
  🔍 Using directory scan (run 'leann build' to enable fast registry)

Closes yichuan-w#198

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@majiayu000
Copy link
Author

Note: This PR builds on top of #196 (which adds --max-depth CLI option).

The relationship:

Recommended merge order:

  1. Merge fix: limit depth of index discovery to prevent slow scans #196 first
  2. Then merge this PR

This PR should be rebased onto #196 once it's merged.

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.

feat: implement global index registry for O(1) index discovery

1 participant