Skip to content

feat: implement GPU-backed FAISS support and dynamic tokenization scaling#209

Open
wgergely wants to merge 21 commits into
StarTrail-org:mainfrom
wgergely:feature/gpu-backend-enhancements
Open

feat: implement GPU-backed FAISS support and dynamic tokenization scaling#209
wgergely wants to merge 21 commits into
StarTrail-org:mainfrom
wgergely:feature/gpu-backend-enhancements

Conversation

@wgergely
Copy link
Copy Markdown

@wgergely wgergely commented Jan 7, 2026

PR Update Draft - Leann GPU Backend & Metadata Enrichment

This update builds upon the initial FAISS GPU support by adding robust metadata extraction and stabilizing the environment for production use.

What's New?

1. Metadata-Rich Indexing (Context Headers)

We’ve added a CodeAnalyzer that uses tree-sitter to extract global context from files. Every code chunk now includes a "Context Header" prepended to its text:

  • Module Skeletons: High-level outlines of classes and functions (signatures + docstrings).
  • Logical Imports: Project-relative import tracking ("5 paths") to help LLMs understand dependencies.
  • Entry point detection: Identifying main modules automatically.

2. FAISS Stability (ZMQ Fixes)

To prevent ZMQ deadlocks observed in high-concurrency scenarios, we've implemented an in-process embedding strategy for the FAISS backend. Search operations now compute query embeddings within the same process by default.

3. MCP Protocol v2025 Upgrade

Standardized the codebase to support the latest MCP protocol version (2025-11-25).

4. Better Environment Control

Standardized LEANN_HOME and LEANN_DOCS handling across CLI and Server modules. The system now strictly respects these environment variables if provided.


⚠️ Breaking Changes & Notes

  • Model Loading: Default embedding model loading now includes trust_remote_code=True to support nomic-embed-text-v1.5 out of the box.
  • New Dependencies: Added tree-sitter (0.23+) and gitignore-parser to core requirements.
  • Python parallelization: Parallel tokenization now uses ProcessPoolExecutor for true CPU parallelism.

Verification

Full test suite passed, including new integration tests for the FAISS ZMQ server and metadata analyzer.

…ding computation

- Force use_server=False to prevent ZMQ connection issues
- Add explicit logger for better debugging
- Improve code structure and comments
Implements a standalone embedding server for the FAISS backend to prevent ZMQ deadlocks that occur when mixing direct embedding computation (build) and server-based computation (search).

- Adds faiss_embedding_server.py: Specialized server reusing leann-core logic.

- Updates __init__.py: Exports and registers the new server module.
Adds:

- gitignore-parser: For robust .gitignore handling in the CLI.

- einops: Required for nomic-embed-text-v1.5 custom implementation.
- api.py: Explicitly separate server-mode (search) vs direct-mode (build) to ensure stability.

- embedding_compute.py: Add parallel tokenization, adaptive batch sizing, and support for nomic-embed-text-v1.5.

- tests: Add token truncation tests.
- Add gitignore-parser integration for correct file exclusion.

- Add suppress_cpp_output context manager to silence noisy FAISS/HNSW backend logs.

- Add code-optimized SentenceSplitter configuration.
- metadata_filter.py: Implements comprehensive filtering (comparison, membership, string, boolean) for search results.

- tests: Add test suite for metadata filtering logic.
@wgergely
Copy link
Copy Markdown
Author

wgergely commented Jan 8, 2026

Successfully updated the PR with the latest stabilization fixes, metadata enrichment, and MCP protocol v2025 updates.

…ontext

- CodeAnalyzer: Added robust import resolution for JS/TS and Python relative paths
- CodeAnalyzer: Improved AST parsing resilience with tree-sitter bindings
- Chunking: Integrated context headers for better semantic search retrieval
- API: Standardization of search interfaces and error handling
- Chat: Improved RAG context injection flow
- Embedding Server: Robust startup/shutdown and process management
- CLI: Consistency updates for downstream consumers
WHAT:
- Add compute_embeddings_voyage() for Voyage AI API with 32K context
- Add resolve_voyage_api_key() to settings.py for API key resolution
- Update EMBEDDING_MODEL_LIMITS with voyage-code-3 (32000 tokens)
- Add 'voyage' and 'gemini' to CLI --embedding-mode choices
- Fix AST chunking import: chunking_utils is in parent package

WHY:
- Voyage Code 3 provides 77% CoIR score for code retrieval
- 32K context window enables Late Chunking strategy
- AST chunking was failing due to wrong relative import path
  (from .chunking_utils should be from ..chunking_utils)

IMPACT:
- Users can now use: --embedding-mode voyage --embedding-model voyage-code-3
- AST-aware chunking now works correctly in analysis module
- Fallback chunking is no longer needed when AST is available
@andylizf
Copy link
Copy Markdown
Collaborator

Thanks for the substantial work here.

At the moment this PR is too broad to safely merge as-is:

  • It is currently conflicting with main.
  • No CI checks are reported on this branch.
  • Scope is much larger than the title suggests (FAISS/GPU + tokenization + MCP/version updates + metadata filtering + CLI/chat behavior + submodule/vendor changes).

To make this mergeable, please split into smaller PRs with clear boundaries, for example:

  1. FAISS backend support only (minimal API surface + tests)
  2. Tokenization/embedding performance changes only
  3. astchunk submodule/vendoring decision only
  4. MCP/CLI/chat/metadata-filtering changes separately

Also please rebase onto current main and ensure CI is green for each split PR.

Happy to review quickly once split.

@andylizf
Copy link
Copy Markdown
Collaborator

Hi @wgergely, just checking in on this PR. Do you still plan to continue working on it?

Since it currently has conflicts and would need to be resolved before review, I’m wondering whether we should keep it open or close it for now.

Happy to revisit and review quickly if you decide to pick it back up.

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.

2 participants