Builder
Forgetless is a chainable builder. Inputs stay buffered until run() executes preview filtering, chunking, scoring, and final budget selection.
Builder shape#
use forgetless::{Config, Forgetless, WithPriority};
let result = Forgetless::new()
.config(
Config::default()
.context_limit(64_000)
.chunk_size(256),
)
.add_pinned("You are writing release notes.")
.add(WithPriority::high(conversation))
.add_file("design-review.pdf")
.query("What changed in the API surface?")
.run()
.await?;Core methods#
| Method | Purpose | Notes from the crate |
|---|---|---|
| new() | Create an empty optimizer | Uses ForgetlessConfig::default() internally. |
| config(Config) | Merge runtime options | Non-default context_limit and chunk_size override the current config. |
| query(...) | Attach a relevance query | When more than five lazy files exist, preview filtering is attempted before full reads. |
| add(...) | Push eager string content | Accepts plain strings or WithPriority wrappers. |
| add_pinned(...) | Shortcut for critical text | Wraps the content with WithPriority::critical. |
| add_file(...) | Register one lazy file | The file path is stored and read later inside run(). |
| add_files(...) | Register many lazy files | Every item is converted through the private IntoLazyFile trait. |
| add_bytes(...) | Attach in-memory bytes | Text MIME types are decoded as UTF-8 when possible; non-text MIME types become placeholder records. |
| run() | Execute the pipeline | Returns an OptimizedContext. |
Execution flow#
| Step | What happens |
|---|---|
| 1. Model init | Vision and text models are only initialized when the current config enables them. |
| 2. Preview filter | If query exists and there are many files, only the most relevant lazy files are read. |
| 3. File load | Selected files are read in parallel with Rayon and converted into ContentInput items. |
| 4. Chunking | Each input gets a ChunkConfig derived from content type and current runtime options. |
| 5. Scoring | Priority, semantic similarity, position heuristics, and conversation-style recency contribute to each score. |
| 6. Selection | Top chunks are kept until the configured token budget is satisfied. |
Related#
Introduction
Learn how Forgetless, a Rust LLM context optimizer, ranks and compresses oversized prompts and files into budget-aware context for production workflows.
Getting Started
Install the Forgetless crate with Cargo, enable optional features, add content and files, and run your first LLM context optimization pass in Rust.
Inputs and Priorities
Control what the LLM context optimizer keeps using WithPriority, FileWithPriority, byte payloads, and lazy file inputs to rank and preserve critical content.