fix: lazy import faiss in embedding_storage.py#9350
Open
irmia2026 wants to merge 1 commit into
Open
Conversation
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Contributor
Author
|
Reopened as follow-up per discussion in #8323. Ready for review. 🙏 |
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The lazy
import faisspattern is now duplicated in__init__and implicitly relied on in the static methods; consider centralizing it in a small helper (e.g.,_get_faiss()that handles ImportError) to keep behavior and error messaging consistent. - If
_read_indexand_write_indexare intended to be usable without instantiatingEmbeddingStorage, you may want to add explicit ImportError handling in those methods similar to__init__so callers see a clear, localized error instead of a generic module import failure.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The lazy `import faiss` pattern is now duplicated in `__init__` and implicitly relied on in the static methods; consider centralizing it in a small helper (e.g., `_get_faiss()` that handles ImportError) to keep behavior and error messaging consistent.
- If `_read_index` and `_write_index` are intended to be usable without instantiating `EmbeddingStorage`, you may want to add explicit ImportError handling in those methods similar to `__init__` so callers see a clear, localized error instead of a generic module import failure.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
regression) PR AstrBotDevs#8323 inadvertently moved import faiss back to module top level, re-introducing the faiss-cpu 1.14.2 deadlock fixed by PR AstrBotDevs#8696. This commit moves the import back inside __init__() (as AstrBotDevs#8696 did), with local imports in _read_index/_write_index static methods. All ASCII temp-file bridge logic from AstrBotDevs#8323 is preserved.
irmia2026
force-pushed
the
fix/faiss-lazy-import-regression
branch
from
July 23, 2026 04:40
7717e7d to
06eb41e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
采用与 #8695 一致的懒加载方式处理
embedding_storage.py中的import faiss。Changes
将
import faiss从模块顶层移至__init__()和方法内部,避免 faiss-cpu 1.14.2 C 库在模块加载时触发 CPU 特性检测死锁。import faissTYPE_CHECKING守卫类型注解__init__()faiss.import faiss在 try/except 内_read_index()faiss.import faiss_write_index()faiss.import faissASCII 临时文件桥接逻辑(
_needs_bridge、_safe_temp_dir、_make_temp_file)保持不变。Related