Model-aware text chunking and answer re-ranking for LLM pipelines. Automatically adapts chunk size to tokenizer and context window, then consolidates and ranks answers across chunks.
Project description
ChunkRank: Model-Aware Chunking + Answer Ranking
Used internally for long-document QA and evaluation pipelines handling 1,000+ PDFs.
ChunkRank is a lightweight Python library that automatically chunks
text based on an LLM’s tokenizer and context window, then consolidates
and ranks answers across chunks. In short ChunkRank is a model-aware text
chunking and answer re-ranking library for LLM pipelines.
🔗 PyPI : https://pypi.org/project/chunkrank/
Why ChunkRank?
When working with LLMs, long documents must be split into chunks, but:
- Every model has different tokenizers and context limits
- Chunk sizes are usually hard-coded and error-prone
- Answer quality drops when responses come from multiple chunks
- Existing RAG frameworks are heavy when you only need chunking + ranking
ChunkRank solves this gap.
What It Does
✅Model-aware chunking
- Pass a model name (
gpt-4o-mini,claude-3.5-sonnet,Llama-3.1-8Betc.) - ChunkRank automatically:
- Selects the correct tokenizer
- Applies the correct context window
- Reserves token space for prompts and responses
No manual token math. No trial-and-error.
✅Answer consolidation & ranking
- Query runs across multiple chunks
- Multiple candidate answers are produced
- ChunkRank re-ranks them to return the best answer Works standalone — no full RAG stack required.
Installation
pip install chunkrank
or for development:
poetry install
Quick Example
import chunkrank
text = open("document.txt").read()
question = "What is the main topic of this document?"
chunks = chunkrank.split(text, model="gpt-4o-mini")
answers = chunkrank.answer(question, chunks)
best = chunkrank.rank(answers)
print(best)
Core API
import chunkrank
# 1. Split text into model-aware chunks
chunks = chunkrank.split(text, model="gpt-4o-mini")
# 2. Answer the question across all chunks
# Default: local extractive (no API key required)
answers = chunkrank.answer(question, chunks)
# With OpenAI:
answers = chunkrank.answer(question, chunks, provider="openai", api_key="sk-...")
# With Anthropic:
answers = chunkrank.answer(question, chunks, provider="anthropic", api_key="sk-ant-...")
# 3. Rank and return the best answer
best_answer = chunkrank.rank(answers)
Pipeline API
from chunkrank import ChunkRankPipeline
# Local (no LLM)
pipe = ChunkRankPipeline(model="gpt-4o-mini")
# With OpenAI
pipe = ChunkRankPipeline(model="gpt-4o-mini", provider="openai", api_key="sk-...")
# With Anthropic
pipe = ChunkRankPipeline(model="gpt-4o-mini", provider="anthropic", api_key="sk-ant-...")
answer = pipe.process(question="What is the main topic?", text=text)
Supported Capabilities
- Automatic model → tokenizer → context resolution
- Token, sentence, and paragraph chunking strategies
- Cross-encoder based answer re-ranking
- Works with OpenAI, Anthropic, HF, Llama-based models
- Drop-in utility for QA, summarization, extraction
How It Fits
| Tool | What it does |
|---|---|
| LangChain / LlamaIndex | Full RAG pipelines |
| Haystack | End-to-end retrieval frameworks |
| ChunkRank | Focused, model-aware chunking + answer ranking |
ChunkRank complements RAG frameworks — it doesn’t replace them.
Roadmap
- Build the model registry (model → context window + tokenizer).
- Implement chunking strategies (tokens, sentences, paragraphs).
- Integrate a re-ranking engine (start with Hugging Face cross-encoder).
- Package and release to PyPI with a simple API.
Community
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file chunkrank-1.0.0.tar.gz.
File metadata
- Download URL: chunkrank-1.0.0.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.14.2 Darwin/24.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1e2435a9f7e6e840844c4deec5965337a73b96de75610125238c8c6daa49055
|
|
| MD5 |
a7d8097a206bdcda9d0e826f7ea9a715
|
|
| BLAKE2b-256 |
35393b6c37795c55e381b006c5929c0f2570894d34f5496cf130aeac7d2fecbe
|
File details
Details for the file chunkrank-1.0.0-py3-none-any.whl.
File metadata
- Download URL: chunkrank-1.0.0-py3-none-any.whl
- Upload date:
- Size: 15.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.14.2 Darwin/24.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b188ab25e153120bf299defd84caf6935650e114155a189c1dc7135616813da9
|
|
| MD5 |
627f91d6f2e070c6f27ab1369c44cc71
|
|
| BLAKE2b-256 |
62cc31da37887990df7e62461f704de263cad52d69e1f0ece843ae4770a67f40
|