- 任务要求:基于 LlamaIndex 构建自己的 RAG 知识库,寻找一个问题 A 在使用 LlamaIndex 之前InternLM2-Chat-1.8B模型不会回答,借助 LlamaIndex 后 InternLM2-Chat-1.8B 模型具备回答 A 的能力,截图保存。
-
构建RAG之前的回答效果
-
获取知识库
- 新建
llamaindex_RAG.py
贴入以下代码 -
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, Settings from llama_index.embeddings.huggingface import HuggingFaceEmbedding from llama_index.llms.huggingface import HuggingFaceLLM #初始化一个HuggingFaceEmbedding对象,用于将文本转换为向量表示 embed_model = HuggingFaceEmbedding( #指定了一个预训练的sentence-transformer模型的路径 model_name="/root/model/sentence-transformer" ) #将创建的嵌入模型赋值给全局设置的embe
书生大模型实战营第四期——LlamaIndex
于 2024-10-05 18:28:56 首次发布