解决llama_index中使用Ollama出现timed out 问题

现象:

bash 复制代码
  File "~/anaconda3/envs/leo_py38/lib/python3.8/site-packages/httpx/_transports/default.py", line 86, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ReadTimeout: timed out

代码:

python 复制代码
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, Settings
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
from llama_index.llms.ollama import Ollama

###定义使用的llm,embedding 模型
llm = Ollama(model="yi:34b")
embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-large-zh-v1.5")
Settings.llm = llm
Settings.embed_model = embed_model

## 加载文档
documents = SimpleDirectoryReader("../../data").load_data()
print("documents: ", len(documents))

## 构建index
index = VectorStoreIndex.from_documents(documents, show_progress=True)

## 构建query engine
query_engine = index.as_query_engine()
query = "身长九尺,髯长二尺的人是谁?"

## query
response = query_engine.query(query)
print(f"query:{query}")
print(f"查询结果:{response}")

解决办法是增加timeout时长

python 复制代码
llm = Ollama(model="yi:34b", request_timeout=500)
相关推荐
不会敲代码134 分钟前
从零搭建 RAG 电子书智能问答系统:天龙八部 × Milvus × LangChain
langchain·node.js·llm
爱听歌的周童鞋2 小时前
Learn-Claude-Code | 笔记 | Collaboration | s11 Autonomous Agents
笔记·llm·agent·claude code·collaboration·autonomous
爱听歌的周童鞋4 小时前
Learn-Claude-Code | 笔记 | Collaboration | s12 Worktree + Task Isolation
llm·agent·worktree·claude code·collaboration·task isolation
Irissgwe6 小时前
LangChain之核心组件(文档加载器Document loaders)
人工智能·ai·langchain·llm·rag·langgraph·文档加载器
程序员三明治8 小时前
【AI】Prompt 工程入门:从五要素框架到 RAG 生产级 Prompt 模板与 Java 实战
java·人工智能·后端·大模型·llm·prompt·agent
GoCoding9 小时前
Rex-Omni 开始
llm
树獭非懒10 小时前
Harness Engineering:驾驭大模型的工程新范式
人工智能·程序员·llm
冬奇Lab19 小时前
RAG 系列(八):RAG 评估体系——用数据说话
人工智能·llm
Irissgwe1 天前
LangChain之核心组件(输出解析器)
ai·langchain·llm·ai编程·输出解析器