llama-index packs sentence_window_retriever integration
Project description
Sentence Window Retriever
This LlamaPack provides an example of our sentence window retriever.
This specific template shows the e2e process of building this. It loads a document, chunks it up, adds surrounding context as metadata to each chunk, and during retrieval inserts the context back into each chunk for response synthesis.
Check out the notebook here.
CLI Usage
You can download llamapacks directly using llamaindex-cli
, which comes installed with the llama-index
python package:
llamaindex-cli download-llamapack SentenceWindowRetrieverPack --download-dir ./sentence_window_retriever_pack
You can then inspect the files at ./sentence_window_retriever_pack
and use them as a template for your own project.
Code Usage
You can download the pack to a the ./sentence_window_retriever_pack
directory:
from llama_index.core.llama_pack import download_llama_pack
# download and install dependencies
SentenceWindowRetrieverPack = download_llama_pack(
"SentenceWindowRetrieverPack", "./sentence_window_retriever_pack"
)
From here, you can use the pack, or inspect and modify the pack in ./sentence_window_retriever_pack
.
Then, you can set up the pack like so:
# create the pack
# get documents from any data loader
sentence_window_retriever_pack = SentenceWindowRetrieverPack(
documents,
)
The run()
function is a light wrapper around query_engine.query()
.
response = sentence_window_retriever_pack.run(
"Tell me a bout a Music celebritiy."
)
You can also use modules individually.
# get the sentence vector index
index = sentence_window_retriever_pack.sentence_index
# get the node parser
node_parser = sentence_window_retriever_pack.node_parser
# get the metadata replacement postprocessor
postprocessor = sentence_window_retriever_pack.postprocessor
# get the query engine
query_engine = sentence_window_retriever_pack.query_engine
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
Hashes for llama_index_packs_sentence_window_retriever-0.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c70e782a4ad2ae35c2f3112821d21a5470ed471660933f71fbb04d73550d8135 |
|
MD5 | ed12f3c8e5b84a7e9be51162b70751ed |
|
BLAKE2b-256 | 7c8d7fdaf7aa099dd48900a5e90033f3431425f31d62617710fd04a9c65fff82 |
Hashes for llama_index_packs_sentence_window_retriever-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21d69f72d2afad3ddb4b5257078549d2ea2c0dae5a2a8d104b991617f6b457e9 |
|
MD5 | 72ab834db7e37f052a47bccac339cc66 |
|
BLAKE2b-256 | be7343b584108ec51cc5fefdd77d672daa23a15683e055c7a802055a9fb92774 |