LlamaIndex中的可组合对象:构建顶级索引
在本文中,我们将展示如何将多个对象组合成一个顶级的索引。这种方法通过设置IndexNode对象来实现,每个对象的obj
字段可以指向以下内容:
- 查询引擎
- 检索器
- 查询管道
- 另一个节点!
object = IndexNode(index_id="my_object", obj=query_engine, text="some text about this object")
数据准备
首先,我们需要安装一些必要的库并下载示例数据:
%pip install llama-index-storage-docstore-mongodb
%pip install llama-index-vector-stores-qdrant
%pip install llama-index-storage-docstore-firestore
%pip install llama-index-retrievers-bm25
%pip install llama-index-storage-docstore-redis
%pip install llama-index-storage-docstore-dynamodb
%pip install llama-index-readers-file pymupdf
!wget --user-agent "Mozilla" "https://arxiv.org/pdf/2307.09288.pdf" -O "./llama2.pdf"
!wget --user-agent "Mozilla" "https://arxiv.org/pdf/1706.03762.pdf" -O "./attention.pdf"
检索器设置
设置OpenAI API密钥并加载文档:
import os
os.environ["OPENAI_API_KEY"] = "sk-..."
from llama_index.core.node_parser import TokenTextSplitter
from llama_index.readers.file import PyMuPDFReader
llama2_docs = PyMuPDFReader().load_data(file_path=