学习RAG踩坑解决记录

学习 https://zhuanlan.zhihu.com/p/675509396 和 https://zhuanlan.zhihu.com/p/668082024 文章了解RAG,使用langchain实现一种简单的RAG问答应用示例。

  1. 问题一:import langchain 报错
pydantic.errors.PydanticUserError: If you use `@root_validator` with pre=False (the default) you MUST specify `skip_on_failure=True`. Note that `@root_validator` is deprecated and should be replaced with `@model_validator`.
 
For further information visit https://errors.pydantic.dev/2.4/u/root-validator-pre-skip

解决:https://blog.csdn.net/liaoningxinmin/article/details/134590965
python3.8.1版本 langchain 0.0.27

pydantic库的版本降低到1.10.13

  1. from langchain.document_loaders import TextLoader时在lanchain中找不到这个模块
    解决:
    langchain版本太低,直接pip install --upgrade langchain也无法提升;
    原来是python版本太低,将python版本提升为3.8.1,之后再更新langchain自动升级解决

  2. documents = text_splitter.split_documents(documents)拆分文档的时候发现没有拆分,还是原来的长度
    解决:
    可能是langchain版本更新了,函数用法改变,修改为https://blog.csdn.net/qq_44894943/article/details/137018519
    https://blog.csdn.net/weixin_44238683/article/details/137914108
    (CharacterTextSplitter基于字符(默认’\n\n’)进行分割)

# 文档分割
from langchain.text_splitter import CharacterTextSplitter
# # 创建拆分器
text_splitter = CharacterTextSplitter(
    separator="\n",  # 指定TextSplitterTextSplitter分隔符
    chunk_size=128,  # 指定每个块的大小(以字符为单位)。在这个例子中,每个块的大小是200个字符。
    chunk_overlap=0,  # 指定块之间的重叠部分的大小(以字符为单位)。在这个例子中,块之间的重叠部分大小是200个字符。
    length_function=len,
    is_separator_regex=False,  # 表示是否识别separator为正则规则
    add_start_index=True,  # 截断索引
)
# 拆分文档
documents = text_splitter.create_documents([document[0].page_content],metadatas=[document[0].metadata])
documents
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值