# Getting Started

> Install, compress, and focus the context on the question your agent is answering.

Install LLMSlim and compress long prompts with the Python API.

Category: Getting Started · Updated: September 2026 · 5 min read

## Install

Install the Python package with pip. Optional extras enable exact token counts.

```bash
pip install llmslim
# Optional exact token counter
pip install 'llmslim[fast-tokens]'
```

## Compress text

The GENERAL role preserves the legacy compress(text) behavior.

```python
from llmslim import compress

result = compress(long_context, target_ratio=0.5)
print(result.compressed_text)
print(result.token_counter_used)
```

## Compress around a question

Pass the question your agent is answering and LLMSlim 0.8 ranks chat rounds, documents, paragraphs or log lines against it, keeps the best ones whole and in their original order, and fits them into the budget. Logs, tracebacks and code keep their line structure.

```python
from llmslim import compress

result = compress(chat_history, target_ratio=0.25, query="Where should the replacement card be shipped?")
print(result.selection)  # "focus"
print(result.compressed_text)
```

## Sharper retrieval with the reranker

Relevance is lexical by default: no model, deterministic, tens of milliseconds on a 3k-token context. For retrieval and long chat memory, where the answer often shares few words with the question, add the optional 22M-parameter reranker. It also accepts any callable scorer(query, texts), such as a hosted reranking API.

```python
# pip install "llmslim[semantic]"
from llmslim import compress_documents

results = compress_documents(documents, query=question, target_ratio=0.25, relevance="semantic")
context = "\n\n".join(r.compressed_text for r in results)
```

> **Measured on public benchmarks:** With the reranker, LLMSlim kept long-chat accuracy within noise of the whole history at 1/62 of the cost at Haiku 5.5 list prices. See the results page for every benchmark.

## FAQ

### Does LLMSlim require an LLM provider?

No. Extractive compression runs locally. Rewrite and hybrid strategies require a caller-supplied provider.

## Related

- [Provenance and ContextRole](https://www.llmslim.app/docs/context-role.md)
- [Pipelines](https://www.llmslim.app/docs/pipelines.md)

Canonical page: https://www.llmslim.app/docs/getting-started
