Builder
`Forgetless` is a chainable builder. Inputs stay buffered until `run()` executes preview filtering, chunking, scoring, and final budget selection.
Builder shape
1use forgetless::{Config, Forgetless, WithPriority};23let result = Forgetless::new()4 .config(5 Config::default()6 .context_limit(64_000)7 .chunk_size(256),8 )9 .add_pinned("You are writing release notes.")10 .add(WithPriority::high(conversation))11 .add_file("design-review.pdf")12 .query("What changed in the API surface?")13 .run()14 .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. |