llama-index packs raptor integration
Project description
Raptor Retriever LlamaPack
This LlamaPack shows how to use an implementation of RAPTOR with llama-index, leveraging the RAPTOR pack.
RAPTOR works by recursively clustering and summarizing clusters in layers for retrieval.
There two retrieval modes:
- tree_traversal -- traversing the tree of clusters, performing top-k at each level in the tree.
- collapsed -- treat the entire tree as a giant pile of nodes, perform simple top-k.
See the paper for full algorithm details.
CLI Usage
You can download llamapacks directly using llamaindex-cli
, which comes installed with the llama-index
python package:
llamaindex-cli download-llamapack RaptorPack --download-dir ./raptor_pack
You can then inspect/modify the files at ./raptor_pack
and use them as a template for your own project.
Code Usage
You can alternaitvely install the package:
pip install llama-index-packs-raptor
Then, you can import and initialize the pack! This will perform clustering and summarization over your data.
from llama_index.packs.raptor import RaptorPack
pack = RaptorPack(documents, llm=llm, embed_model=embed_model)
The run()
function is a light wrapper around retriever.retrieve()
.
nodes = pack.run(
"query",
mode="collapsed", # or tree_traversal
)
You can also use modules individually.
# get the retriever
retriever = pack.retriever
Persistence
The RaptorPack
comes with the RaptorRetriever
, which offers ways of saving/reloading!
If you are using a remote vector-db, just pass it in
# Pack usage
pack = RaptorPack(..., vector_store=vector_store)
# RaptorRetriever usage
retriever = RaptorRetriever(..., vector_store=vector_store)
Then, to re-connect, just pass in the vector store again and an empty list of documents
# Pack usage
pack = RaptorPack([], ..., vector_store=vector_store)
# RaptorRetriever usage
retriever = RaptorRetriever([], ..., vector_store=vector_store)
Check out the notebook here for complete details!.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for llama_index_packs_raptor-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5c326a92ae8f7f84adbaf9a8ec9e05289ae29f466858779ee6a680ff11a5ac1 |
|
MD5 | 210e8d789b433cc91e79dadb8fe1cf66 |
|
BLAKE2b-256 | 46b915a357113db8ecf0ca7d512df8855e8b04538760293e97b5f46c01cec903 |
Hashes for llama_index_packs_raptor-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac118e92b8a1dad7d15e2892ce4a5daa4a854a4218f19f4e0412a3917096db67 |
|
MD5 | 8a4535d7e767ee09de4f64fe8fcce037 |
|
BLAKE2b-256 | 8b54c5d0ae2f16a9f99a69fd827730701ab0f7e97a6dc3a0b8c632897a097446 |