Skip to main content
Back to integrations
Gemini
LLM ProviderPython integration

LLMSlim + Google Gemini

Compress retrieved Python context before a Gemini SDK request.

Use compress_documents() for retrieved text and preserve accurate provenance.

1. Package installation

Install LLMSlim and the official Google Gemini SDK using your package manager.

terminalbash
pip install llmslim

2. Architecture & execution flow

1

1. Retrieve or construct application context.

2

2. Label provenance accurately and compress with LLMSlim.

3

3. Send the resulting text to the provider SDK.

4

4. Apply application-level policy and output validation.

3. Production code pattern

gemini_app.pypython
from llmslim import compress_documents

compressed = compress_documents(documents, query=query, target_ratio=0.4)

4. Deployment best practices

Use LLMSlim in your Python application before constructing the provider request. Measure target workloads before choosing a compression ratio.

5. Key optimization tips

  • Use compress_documents() for retrieved documents; it defaults to RAG provenance.
  • Leave system messages unchanged by default in compress_chat_messages().
  • Do not treat compression as a complete prompt-injection defense.

6. Performance metrics

MetricUncompressedLLMSlimImpact
v0.4.0 release gateN/A489 tests passed90.93% coverage; 375 schemas across 18 catalogs

Frequently asked questions

Troubleshooting