A document compression and optimization library using Groq LLMs and LangChain
Project description
Document Optimizer for LLMs
A lightweight Python library and Streamlit web application to compress large documents into the most relevant chunks for downstream use in LLM-based workflows.
It leverages semantic chunking, scoring, and selection to reduce token count while preserving essential content, making it ideal for Retrieval-Augmented Generation (RAG), summarization, and QA pipelines.
Features
Token-based document chunk compression
Semantic scoring and chunk selection with Maximal Marginal Relevance (MMR) or similar methods
Integration with LangChain and Groq LLMs
Modular Python package (optimizer) with reusable backend logic
Streamlit frontend for easy document upload and summarization
Supports sentence-transformers for embeddings and tiktoken for token counting
Folder Structure
. ├── app.py (Streamlit frontend application) ├── requirements.txt ├── sample_files/ │ └── sample_doc.txt (Sample input document for testing) └── optimizer/ (Python module) ├── init.py ├── compressor.py (compress_chunk function) ├── retriever_wrapper.py ├── scorer.py ├── selector.py └── token_utils.py
Getting Started
Clone the Repository
git clone https://github.com/yourname/document-optimizer.git cd document-optimizer
Install Requirements
pip install -r requirements.txt
Run the Streamlit App
streamlit run app.py
Usage
As a Python Library
Import the main compression function and run on your document text:
from optimizer.compressor import compress_chunks
chunks = compress_chunks(  doc_text="...your document text...",  top_k=5,  chunk_size=300,  stride=150, )
Development
Install Your Package Locally (Editable Mode)
From the root directory:
pip install -e .
This allows you to edit the code in optimizer/ and see changes immediately without reinstalling.
Import Shortcut
optimizer/init.py enables importing key functions directly:
from optimizer import compress_chunks
Technology Stack
Python Streamlit LangChain Sentence-Transformers Scikit-Learn Tiktoken Groq LLMs (optional)
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 optimizer_rag-0.1.0.tar.gz.
File metadata
- Download URL: optimizer_rag-0.1.0.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77e521afd390c6c90d664f054c733e87b1445d05ce6a8d22d6ab3750293bc8e0
|
|
| MD5 |
c18a5e81254bbf8035a4435fdefc4bf5
|
|
| BLAKE2b-256 |
2f883ed18435265881872a4acf1c6684f01cd93adf48a628b8339c2c22620b7c
|
File details
Details for the file optimizer_rag-0.1.0-py3-none-any.whl.
File metadata
- Download URL: optimizer_rag-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc906cbfd3c8ea360c7180382c3e1853339dd3dcf1a7559c17876ffbf8039706
|
|
| MD5 |
5f56da04909e261ba337f416f61f2098
|
|
| BLAKE2b-256 |
cfcf082a0257d4ac9a2885c752c598ee38280111c92b32b71c7a9deee817f370
|