Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

optimizer_rag-0.1.2.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

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

optimizer_rag-0.1.2-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

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

Hashes for optimizer_rag-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c60ef162fc7abc6ef382c110f95de859a747476c37e331083e7fff8757699349
MD5 aacb48a3f47e46a3f3d8fe36549ea546
BLAKE2b-256 590d6f19915139822c6cd1f447eff6e16e30a890ba1403fe739df5b69428c36a

See more details on using hashes here.

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

Hashes for optimizer_rag-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fc149344044f71941e4d6c01847f1b8e711f4ee8b69270f93949afd78e39db95
MD5 376f97b8eb43b88dc25609b28032e011
BLAKE2b-256 4b5b1f426edf056d688daf7adcdf7de1432046cca942971ef8826850489fd48e

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