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

llama_index_packs_dense_x_retrieval-0.6.1.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file llama_index_packs_dense_x_retrieval-0.6.1.tar.gz.

File metadata

  • Download URL: llama_index_packs_dense_x_retrieval-0.6.1.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_packs_dense_x_retrieval-0.6.1.tar.gz
Algorithm Hash digest
SHA256 3c99ccfd89c089b7cbc8e67b48550aa5999d80899d7f09e8200a84099e89cf46
MD5 655ec81f40b62bcbf97893ce4f0c5979
BLAKE2b-256 96ed2b067af6bdf9b1a03937ad6597ba1975878a9e619f44f5c6766ca10b4f06

See more details on using hashes here.

File details

Details for the file llama_index_packs_dense_x_retrieval-0.6.1-py3-none-any.whl.

File metadata

  • Download URL: llama_index_packs_dense_x_retrieval-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_packs_dense_x_retrieval-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 40d727c86adf3abaf702e9996adc59ab6e78f8243ffb4f24afe1f6f08b0f91f7
MD5 18c7ed625cfd31f92707a58bd6185765
BLAKE2b-256 0a60481378d67e608133ac53c57fdd37fdf7d4ddcbf9f78d0f8b4e32d4d18e86

See more details on using hashes here.

Supported by

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