llama-index-packs-dense-x-retrieval


Namellama-index-packs-dense-x-retrieval JSON
Version 0.3.0 PyPI version JSON
download
home_pageNone
Summaryllama-index packs dense_x_retrieval integration
upload_time2024-08-22 16:50:08
maintainerlogan-markewich
docs_urlNone
authorYour Name
requires_python<4.0,>=3.8.1
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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?](https://arxiv.org/abs/2312.06648).

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:

```bash
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:

```python
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()`.

```python
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()`.

```python
stream_response = dense_pack.run("What can you tell me about LLMs?")

stream_response.print_response_stream()
```

See the [notebook on llama-hub](https://github.com/run-llama/llama-hub/blob/main/llama_hub/llama_packs/dense_x_retrieval/dense_x_retrieval.ipynb) for a full example.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "llama-index-packs-dense-x-retrieval",
    "maintainer": "logan-markewich",
    "docs_url": null,
    "requires_python": "<4.0,>=3.8.1",
    "maintainer_email": null,
    "keywords": null,
    "author": "Your Name",
    "author_email": "you@example.com",
    "download_url": "https://files.pythonhosted.org/packages/9d/9d/2d40b41e3a15ee1832f417c99ee8bd119ab1ec68c363cc2fdfd384cad704/llama_index_packs_dense_x_retrieval-0.3.0.tar.gz",
    "platform": null,
    "description": "# Dense-X-Retrieval Pack\n\nThis LlamaPack creates a query engine that uses a `RecursiveRetriever` in llama-index to fetch nodes based on propoistions extracted from each node.\n\nThis follows the idea from the paper [Dense X Retrieval: What Retrieval Granularity Should We Use?](https://arxiv.org/abs/2312.06648).\n\nFrom the paper, a proposition is described as:\n\n```\nPropositions are defined as atomic expressions within text, each encapsulating a distinct factoid and presented in a concise, self-contained natural language format.\n```\n\nWe use the provided OpenAI prompt from their paper to generate propositions, which are then embedded and used to retrieve their parent node chunks.\n\n**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.\n\n## CLI Usage\n\nYou can download llamapacks directly using `llamaindex-cli`, which comes installed with the `llama-index` python package:\n\n```bash\nllamaindex-cli download-llamapack DenseXRetrievalPack --download-dir ./dense_pack\n```\n\nYou can then inspect the files at `./dense_pack` and use them as a template for your own project!\n\n## Code Usage\n\nYou can download the pack to a the `./dense_pack` directory:\n\n```python\nfrom llama_index.core import SimpleDirectoryReader\nfrom llama_index.core.llama_pack import download_llama_pack\n\n# download and install dependencies\nDenseXRetrievalPack = download_llama_pack(\n    \"DenseXRetrievalPack\", \"./dense_pack\"\n)\n\ndocuments = SimpleDirectoryReader(\"./data\").load_data()\n\n# uses the LLM to extract propositions from every document/node!\ndense_pack = DenseXRetrievalPack(documents)\n\n# for streaming\ndense_pack = DenseXRetrievalPack(documents, streaming=True)\n```\n\nThe `run()` function is a light wrapper around `query_engine.query()`.\n\n```python\nresponse = dense_pack.run(\"What can you tell me about LLMs?\")\n\nprint(response)\n```\n\nfor streaming:\n\nThe `run()` function is a light wrapper around `query_engine.query()`.\n\n```python\nstream_response = dense_pack.run(\"What can you tell me about LLMs?\")\n\nstream_response.print_response_stream()\n```\n\nSee the [notebook on llama-hub](https://github.com/run-llama/llama-hub/blob/main/llama_hub/llama_packs/dense_x_retrieval/dense_x_retrieval.ipynb) for a full example.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "llama-index packs dense_x_retrieval integration",
    "version": "0.3.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "13be9ce6e2052079d035733c42f91839efedb089890797e031a2a08392f965a8",
                "md5": "121f0e638e293a41f9f1776235d5f5f3",
                "sha256": "311fd8c0029b4695b14213c31ec8d3a5b2ec6510df242618067dce147cada749"
            },
            "downloads": -1,
            "filename": "llama_index_packs_dense_x_retrieval-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "121f0e638e293a41f9f1776235d5f5f3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8.1",
            "size": 5254,
            "upload_time": "2024-08-22T16:50:07",
            "upload_time_iso_8601": "2024-08-22T16:50:07.247330Z",
            "url": "https://files.pythonhosted.org/packages/13/be/9ce6e2052079d035733c42f91839efedb089890797e031a2a08392f965a8/llama_index_packs_dense_x_retrieval-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9d9d2d40b41e3a15ee1832f417c99ee8bd119ab1ec68c363cc2fdfd384cad704",
                "md5": "a64a8da316098abcb3b7dcafd9a3a9cb",
                "sha256": "3a06953cfd2a4c4603c1fddf2044372816c1c66827919ba0d0de17b71f3706e5"
            },
            "downloads": -1,
            "filename": "llama_index_packs_dense_x_retrieval-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a64a8da316098abcb3b7dcafd9a3a9cb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8.1",
            "size": 4979,
            "upload_time": "2024-08-22T16:50:08",
            "upload_time_iso_8601": "2024-08-22T16:50:08.700808Z",
            "url": "https://files.pythonhosted.org/packages/9d/9d/2d40b41e3a15ee1832f417c99ee8bd119ab1ec68c363cc2fdfd384cad704/llama_index_packs_dense_x_retrieval-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-22 16:50:08",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "llama-index-packs-dense-x-retrieval"
}
        
Elapsed time: 0.55412s