A document compression and optimization library using Groq LLMs and LangChain
Project description
Optimizer
Optimizer is a Python library for compressing large documents using LLMs like Groq. It provides functionality for summarizing document chunks based on a query, selecting the most relevant summaries, and managing token budgets effectively — ideal for RAG (Retrieval Augmented Generation) applications.
Features
- Summarize document chunks using Groq models
- Select relevant summaries based on token limits
- Easily integrate with any RAG pipeline
Installation
pip install optimizer-groq
Requirements
Make sure the following packages are installed (handled automatically if installing via pip):
langchain>=0.1.16
groq
tiktoken
numpy
scikit-learn
sentence-transformers
python-dotenv
Usage
from optimizer.compressor import compress_chunk
chunks = ["Paragraph 1...", "Paragraph 2...", "Paragraph 3..."]
query = "What are the benefits of renewable energy?"
token_budget = 512
selected = compress_chunk(chunks, query, token_budget)
print(selected)
You can also customize the model by injecting the model into the library functions like this.
from openai import OpenAI
from optimizer.compressor import compress_chunk
client = OpenAI(api_key="your-openai-api-key")
chunks = ["Text A...", "Text B..."]
query = "Summarize risks."
token_budget = 400
summaries = compress_chunk(chunks, query, token_budget, client=client, model="gpt-4")
Environment Setup
Set your Groq API key in a .env file:
GROQ_API_KEY=your_groq_api_key_here
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.2.tar.gz.
File metadata
- Download URL: optimizer_rag-0.1.2.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c60ef162fc7abc6ef382c110f95de859a747476c37e331083e7fff8757699349
|
|
| MD5 |
aacb48a3f47e46a3f3d8fe36549ea546
|
|
| BLAKE2b-256 |
590d6f19915139822c6cd1f447eff6e16e30a890ba1403fe739df5b69428c36a
|
File details
Details for the file optimizer_rag-0.1.2-py3-none-any.whl.
File metadata
- Download URL: optimizer_rag-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.1 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 |
fc149344044f71941e4d6c01847f1b8e711f4ee8b69270f93949afd78e39db95
|
|
| MD5 |
376f97b8eb43b88dc25609b28032e011
|
|
| BLAKE2b-256 |
4b5b1f426edf056d688daf7adcdf7de1432046cca942971ef8826850489fd48e
|