llama-index packs dense_x_retrieval integration
Project description
Dense-X-Retrieval Pack
This LlamaPack creates a query engine that uses a RecursiveRetriever
in llama-index to fetch nodes based on propoistions extracted from each node.
This follows the idea from the paper Dense X Retrieval: What Retrieval Granularity Should We Use?.
From the paper, a proposition is described as:
Propositions are defined as atomic expressions within text, each encapsulating a distinct factoid and presented in a concise, self-contained natural language format.
We use the provided OpenAI prompt from their paper to generate propositions, which are then embedded and used to retrieve their parent node chunks.
NOTE: While the paper uses a fine-tuned model to extract propositions, it is unreleased at the time of writing. Currently, this pack uses the LLM to extract propositions, which can be expensive for large amounts of data.
CLI Usage
You can download llamapacks directly using llamaindex-cli
, which comes installed with the llama-index
python package:
llamaindex-cli download-llamapack DenseXRetrievalPack --download-dir ./dense_pack
You can then inspect the files at ./dense_pack
and use them as a template for your own project!
Code Usage
You can download the pack to a the ./dense_pack
directory:
from llama_index.core import SimpleDirectoryReader
from llama_index.core.llama_pack import download_llama_pack
# download and install dependencies
DenseXRetrievalPack = download_llama_pack(
"DenseXRetrievalPack", "./dense_pack"
)
documents = SimpleDirectoryReader("./data").load_data()
# uses the LLM to extract propositions from every document/node!
dense_pack = DenseXRetrievalPack(documents)
# for streaming
dense_pack = DenseXRetrievalPack(documents, streaming=True)
The run()
function is a light wrapper around query_engine.query()
.
response = dense_pack.run("What can you tell me about LLMs?")
print(response)
for streaming:
The run()
function is a light wrapper around query_engine.query()
.
stream_response = dense_pack.run("What can you tell me about LLMs?")
stream_response.print_response_stream()
See the notebook on llama-hub for a full example.
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_dense_x_retrieval-0.4.0.tar.gz
.
File metadata
- Download URL: llama_index_packs_dense_x_retrieval-0.4.0.tar.gz
- Upload date:
- Size: 5.0 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 | 3211d29c7989a53c87ea04ddd0031347e9aac6d0e079ea02ffc553d6f4d778a3 |
|
MD5 | 68fcd4699b87c0e68022771c209025d1 |
|
BLAKE2b-256 | b41f569616eb99b960a56581099b9e235b2bd433a2e63397713a9cf8f55a749b |
File details
Details for the file llama_index_packs_dense_x_retrieval-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: llama_index_packs_dense_x_retrieval-0.4.0-py3-none-any.whl
- Upload date:
- Size: 5.3 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 | cab908d7d2102ba1c8257c470321e3d711811d4c83da5dec770ce2ce4870bc6f |
|
MD5 | f56188fac133013e004536508a5d2e6c |
|
BLAKE2b-256 | 7ca6bce6305fc7ada26f27c79cbee603742c94262f01cd25d1d3b3c9fa4ca2c2 |