llama-index packs self rag integration
Project description
Simple self-RAG short form pack
This LlamaPack implements (*in short form) the self-RAG paper by Akari et al..
This paper presents a novel framework called Self-Reflective Retrieval-Augmented Generation (SELF-RAG). Which aims to enhance the quality and factuality of large language models (LLMs) by combining retrieval and self-reflection mechanisms.
The implementation is adapted from the author implementation A full notebook guide can be found here.
CLI Usage
You can download llamapacks directly using llamaindex-cli
, which comes installed with the llama-index
python package:
llamaindex-cli download-llamapack SelfRAGPack --download-dir ./self_rag_pack
You can then inspect the files at ./self_rag_pack
and use them as a template for your own project!
Code Usage
We will show you how to import the agent from these files! The implementation uses llama-cpp, to download the relevant models (be sure to replace DIR_PATH)
pip3 install -q huggingface-hub
huggingface-cli download m4r1/selfrag_llama2_7b-GGUF selfrag_llama2_7b.q4_k_m.gguf --local-dir "<DIR_PATH>" --local-dir-use-symlinks False
from llama_index.core.llama_pack import download_llama_pack
# download and install dependencies
SelfRAGPack = download_llama_pack("SelfRAGPack", "./self_rag_pack")
From here, you can use the pack. You can import the relevant modules from the download folder (in the example below we assume it's a relative import or the directory has been added to your system path).
from self_rag_pack.base import SelfRAGQueryEngine
query_engine = SelfRAGQueryEngine(
model_path=model_path, retriever=retriever, verbose=True
)
response = query_engine.query(
"Who won best Director in the 1972 Academy Awards?"
)
You can also use/initialize the pack directly.
from llm_compiler_agent_pack.base import SelfRAGPack
agent_pack = SelfRAGPack(
model_path=model_path, retriever=retriever, verbose=True
)
The run()
function is a light wrapper around agent.chat()
.
response = pack.run("Who won best Director in the 1972 Academy Awards?")
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
File details
Details for the file llama_index_packs_self_rag-0.3.0.tar.gz
.
File metadata
- Download URL: llama_index_packs_self_rag-0.3.0.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.10 Darwin/22.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e83e4f49ae373a2f728650337ac4701ef83c4a00ba0b65a1a9648da97ffb31bb |
|
MD5 | 91b4a26b6ee840371f75c06a8090ef68 |
|
BLAKE2b-256 | 6016d97913dca8f54439d1b61a2cfccc41d262d65a947322c8f1b1eae84124e6 |
File details
Details for the file llama_index_packs_self_rag-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: llama_index_packs_self_rag-0.3.0-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.10 Darwin/22.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97d8c547c9e3ecc7ef89055a438579cd02e406bc1ffe2ec87e0c62f8fcc7549f |
|
MD5 | a747d84460be0e40bc3be268f083b81b |
|
BLAKE2b-256 | 316b6d535a5b1c33f8b13a420db8de6c003e6b0d77b0e4e4692d5373762664b1 |