Skip to main content

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

Metadata

Release files for optimizer-rag 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for optimizer-rag 0.1.2
File Size Uploaded
optimizer_rag-0.1.2.tar.gz 3.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for optimizer-rag 0.1.2
File Interpreter ABI Platform
optimizer_rag-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 9.0 kB

Release files / optimizer_rag-0.1.2.tar.gz

Download URL optimizer_rag-0.1.2.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c60ef162fc7abc6ef382c110f95de859a747476c37e331083e7fff8757699349
BLAKE2b-256 checksum
How to use checksums
590d6f19915139822c6cd1f447eff6e16e30a890ba1403fe739df5b69428c36a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.10

Release files / optimizer_rag-0.1.2-py3-none-any.whl

Download URL optimizer_rag-0.1.2-py3-none-any.whl
Size 5.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fc149344044f71941e4d6c01847f1b8e711f4ee8b69270f93949afd78e39db95
BLAKE2b-256 checksum
How to use checksums
4b5b1f426edf056d688daf7adcdf7de1432046cca942971ef8826850489fd48e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.10

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page