系统学习 AI 学习路径:从 GPU 运行时到推理、微调与 RAG 评估

llamaindex

LlamaIndex 数据索引与 RAG

补充说明

LlamaIndex 面向 RAG 和数据索引,提供文档加载、分块、索引、检索、查询引擎和 Agent。适合把私有数据接入大模型。

核心概念:Document、Node、Index、Retriever、QueryEngine、VectorStoreIndex。

常用示例

安装:

pip install llama-index llama-index-vector-stores-qdrant

构建索引:

from llama_index.core import SimpleDirectoryReader, VectorStoreIndex

documents = SimpleDirectoryReader("./docs").load_data()
index = VectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine()
print(query_engine.query("如何排查磁盘满?"))

持久化:

index.storage_context.persist(persist_dir="./storage")

加载已有索引:

from llama_index.core import StorageContext, load_index_from_storage
storage_context = StorageContext.from_defaults(persist_dir="./storage")
index = load_index_from_storage(storage_context)

易错点与排错

相关命令

参考链接

读完自测

合上页面,先回答,再展开对照。

  1. 重启后索引被重建,通常漏了哪一步?
  2. 查询结果与问题无关,先检查什么?
  3. similarity_top_k 太小会怎样?
答案
  1. 索引持久化后没有加载 storage。
  2. embedding 模型与构建索引时是否一致。
  3. 答案缺少上下文。
微信小程序码:扫码打开命令速查小程序

小程序版

微信扫码,随时查命令