Repository navigation
使用Python构建RAG系统 --chromadb 部分出现kernel crashed #5
Description
Activity
import chromadb
chromadb_client = chromadb.EphemeralClient() chromadb_collection = chromadb_client.get_or_create_collection(name="default")
def save_embeddings(chunks: List[str], embeddings: List[List[float]]) -> None: for i, (chunk, embedding) in enumerate(zip(chunks, embeddings)): chromadb_collection.add( documents=[chunk], embeddings=[embedding], ids=[str(i)] )
save_embeddings(chunks, embeddings)
运行这部分代码时出现报错: The Kernel crashed while executing code in the current cell or a previous cell.
Please review the code in the cell(s) to identify a possible cause of the failure.
Click here for more info.
View Jupyter log for further details.
我也出现了这个问题,请问解决了吗?
看起来这是典型 No.6 向量库/依赖崩溃,常见于 chromadb + jupyter/多进程 + 大批量
add_documents时:内核直接炸掉,没有 Python trace,只在 jupyter log 里提示 kernel crash。三步把问题缩小(先过一条即可)
- 最小复现:把
embedding换成固定小批量(如 8 条),collection.add用ids + documents + metadatas明确字段,确认是否仍 crash。 - 拆分阶段:先只做
embed → np.array,不入库;再单独collection.add。能区分是 embed 侧还是 DB 侧炸。 - 隔离环境:在独立脚本里跑同样代码,不用 notebook。chromadb 在 notebook 下多进程/并发时更容易崩。
如果需要,我有一份 向量库排错清单(No.6):批量阈值、序列化尺寸、进程模式、FAISS/SQLite 切换、以及崩溃旁路策略。你回我一下,我把清单发你,按表走基本都能复现并定位。
- 最小复现:把
现在照着作者的代码敲的话会出现接口不兼容的问题,因为chromadb所依赖的库版本更新了,导致接口出现错误,目前只能换模型了。
C:\HypsFiles\Work\Language\Python\python.exe "C:\HypsFiles\Work\Words\PythonWords\RAG Hands-on Practice\AskingBefore.py" Traceback (most recent call last): File "C:\HypsFiles\Work\Words\PythonWords\RAG Hands-on Practice\AskingBefore.py", line 3, in <module> import chromadb #引入向量数据库 ^^^^^^^^^^^^^^^ File "C:\HypsFiles\Work\Language\Python\Lib\site-packages\chromadb\__init__.py", line 2, in <module> import chromadb.config File "C:\HypsFiles\Work\Language\Python\Lib\site-packages\chromadb\config.py", line 1, in <module> from pydantic import BaseSettings File "C:\HypsFiles\Work\Language\Python\Lib\site-packages\pydantic\__init__.py", line 437, in __getattr__ return _getattr_migration(attr_name) File "C:\HypsFiles\Work\Language\Python\Lib\site-packages\pydantic\_migration.py", line 304, in wrapper raise PydanticImportError( ...<3 lines>... ) pydantic.errors.PydanticImportError: BaseSettings has been moved to the pydantic-settings package. See https://docs.pydantic.dev/2.12/migration/#basesettings-has-moved-to-pydantic-settings for more details. For further information visit https://errors.pydantic.dev/2.12/u/import-error
import chromadb
chromadb_client = chromadb.EphemeralClient()
chromadb_collection = chromadb_client.get_or_create_collection(name="default")
def save_embeddings(chunks: List[str], embeddings: List[List[float]]) -> None:
for i, (chunk, embedding) in enumerate(zip(chunks, embeddings)):
chromadb_collection.add(
documents=[chunk],
embeddings=[embedding],
ids=[str(i)]
)
save_embeddings(chunks, embeddings)
运行这部分代码时出现报错:
The Kernel crashed while executing code in the current cell or a previous cell.
Please review the code in the cell(s) to identify a possible cause of the failure.
Click here for more info.
View Jupyter log for further details.