Skip to main content

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-8B etc.)
  • 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

  1. Build the model registry (model → context window + tokenizer).
  2. Implement chunking strategies (tokens, sentences, paragraphs).
  3. Integrate a re-ranking engine (start with Hugging Face cross-encoder).
  4. Package and release to PyPI with a simple API.

Community


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

chunkrank-1.0.0.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

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

chunkrank-1.0.0-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

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

Hashes for chunkrank-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a1e2435a9f7e6e840844c4deec5965337a73b96de75610125238c8c6daa49055
MD5 a7d8097a206bdcda9d0e826f7ea9a715
BLAKE2b-256 35393b6c37795c55e381b006c5929c0f2570894d34f5496cf130aeac7d2fecbe

See more details on using hashes here.

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

Hashes for chunkrank-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b188ab25e153120bf299defd84caf6935650e114155a189c1dc7135616813da9
MD5 627f91d6f2e070c6f27ab1369c44cc71
BLAKE2b-256 62cc31da37887990df7e62461f704de263cad52d69e1f0ece843ae4770a67f40

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