Skip to content

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

Open
majiayu000 wants to merge 3 commits into
StarTrail-org:mainfrom
majiayu000:feat/global-index-registry
Open

feat: implement global index registry for O(1) index discovery#199
majiayu000 wants to merge 3 commits into
StarTrail-org:mainfrom
majiayu000:feat/global-index-registry

Conversation

@majiayu000
Copy link
Copy Markdown
Contributor

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 StarTrail-org#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 <1835304752@qq.com>
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 <noreply@anthropic.com>
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 StarTrail-org#198

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@majiayu000
Copy link
Copy Markdown
Contributor 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.

ngmks added a commit to ngmks/LEANN that referenced this pull request Feb 3, 2026
…org#195, StarTrail-org#196, StarTrail-org#199

- Fix unused variable `zmq_port` in warmup() method (F841)
- Remove unused imports in test_cli_list_performance.py (F401)
- Sort imports in test files (I001)
- Fix test_warmup.py: correct attribute name `_warmup_enabled` → `_warmup`
- Add skipif for DiskANN test when backend is not installed
- Apply ruff format to all modified files

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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