Skip to main content

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

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page