在Google Colab部署personal-assistant项目遇多类报错求助
一、retrievalQA.py模型加载失败(AssertionError)
错误信息
Loading the Manticore-13B.ggmlv2.q5_1.bin model...
llama.cpp: loading model from models/manticore-13b/Manticore-13B.ggmlv2.q5_1.bin
error loading model: unknown (magic, version) combination: 4f44213c, 50595443; is this really a GGML file?
llama_init_from_file: failed to load model
Traceback (most recent call last):
File "/content/personal-assistant/retrievalQA.py", line 61, in
main()
File "/content/personal-assistant/retrievalQA.py", line 40, in main
llm = load_local_model(model_path, provider='llamacpp')
File "/content/personal-assistant/retrievalQA.py", line 28, in load_local_model
llm = LlamaLLM(model_path, n_gpu_layers=n_gpu_layers,
File "/content/personal-assistant/pa/llm/llamacpp.py", line 20, in init
self.model = Llama(model_path=model_path,
File "/usr/local/lib/python3.10/dist-packages/llama_cpp/llama.py", line 162, in init
assert self.ctx is not None
AssertionError
解决步骤
- 核心原因是llama-cpp-python新版本已切换到GGUF格式,不再支持旧GGMLv2/v3格式
- 下载Manticore-13B模型的GGUF格式版本
- 升级llama-cpp-python到最新稳定版:
pip install --upgrade llama-cpp-python - 修改代码中模型路径为GGUF文件的路径,确保加载逻辑匹配新格式
二、旧版llama-cpp-python的参数错误(TypeError)
错误信息
TypeError: Llama.init() got an unexpected keyword argument 'n_gpu_layers'
解决步骤
n_gpu_layers是llama-cpp-python较新版本新增参数,旧版本(如0.1.25)不支持
- 优先选择升级llama-cpp-python到支持该参数的版本(参考上面的升级命令),保留GPU加速能力
- 若必须用旧版本,删除代码中
n_gpu_layers参数(但Colab CPU运行13B模型会极慢)
三、inject.py的Embedding编码错误(IndexError)
错误信息
load INSTRUCTOR_Transformer
max_seq_length 512
Traceback (most recent call last):
File "/content/personal-assistant/inject.py", line 66, in
main()
File "/content/personal-assistant/inject.py", line 59, in main
db = Chroma.from_documents(texts, instructor_embeddings,
File "/usr/local/lib/python3.10/dist-packages/langchain/vectorstores/chroma.py", line 435, in from_documents
return cls.from_texts(
File "/usr/local/lib/python3.10/dist-packages/langchain/vectorstores/chroma.py", line 403, in from_texts
chroma_collection.add_texts(texts=texts, metadatas=metadatas, ids=ids)
File "/usr/local/lib/python3.10/dist-packages/langchain/vectorstores/chroma.py", line 148, in add_texts
embeddings = self._embedding_function.embed_documents(list(texts))
File "/usr/local/lib/python3.10/dist-packages/langchain/embeddings/huggingface.py", line 158, in embed_documents
embeddings = self.client.encode(instruction_pairs, **self.encode_kwargs)
File "/usr/local/lib/python3.10/dist-packages/InstructorEmbedding/instructor.py", line 524, in encode
if isinstance(sentences[0],list):
IndexError: list index out of range
解决步骤
- 核心原因是传入的texts列表为空,无有效文档可处理
- 检查inject.py中数据源的路径、读取逻辑,确保能加载到有效文本内容
- 在生成texts后添加空值判断,提前终止流程避免报错:
if not texts: raise ValueError("No documents found to process. Check your data source.") - 确保Langchain与InstructorEmbedding版本兼容,建议安装指定版本:
pip install langchain==0.0.300 InstructorEmbedding==1.0.1
内容的提问来源于stack exchange,提问作者eclipt

