使用LlamaIndex对接Azure OpenAI时遇未知文档类型错误求助
解决方案:LlamaIndex Document类型不匹配错误
错误原因
llama_index 0.10.x版本进行了架构重构,旧代码被迁移至legacy模块,新代码统一放在core模块中。你混用了legacy模块的SimpleDirectoryReader(生成旧版llama_index.legacy.schema.Document)和默认的新版VectorStoreIndex(仅识别新版llama_index.core.schema.Document),导致类型不兼容报错。
两种解决办法
办法一:统一使用legacy模块组件
将VectorStoreIndex的导入改为legacy版本,确保所有组件来自同一模块:
# 替换原VectorStoreIndex的导入 from llama_index.legacy import VectorStoreIndex
后续执行index = VectorStoreIndex.from_documents(documents)即可正常运行。
办法二:迁移至新版本组件(推荐)
放弃legacy模块,全部使用新版core组件,适配未来版本迭代:
# 替换SimpleDirectoryReader的导入为新版 from llama_index.core.readers.file import SimpleDirectoryReader # 确保VectorStoreIndex使用新版(0.10.x中默认导入即为新版,也可明确指定) from llama_index.core import VectorStoreIndex
重新读取文档并构建索引,即可避免类型不匹配问题。
内容的提问来源于stack exchange,提问作者Keithx
相关产品推荐
相关产品推荐

