Skip to content
Projetos

Sobre

trim-1: a 1.2 MB model that keeps the lines of a context an AI agent needs

IA e aprendizado de máquina

Como estes números são medidos

Crescimento medido de estrelas

em 24 h
+2
em 7 dias
+6
em 15 dias
+7
em 1 mês
Coletando histórico

Variações líquidas em períodos sobrepostos, não totais diários. Medições ausentes ficam em branco. Estrelas indicam interesse, não qualidade.

README.md

Original

Caveman / trim-1. The word TRIM-1 in solid pixel letters with a double-line shadow. Why read many line when few do trick. Agent read whole log to find one error. trim-1 keep the lines the ask need and drop the rest. Every kept line exact, nothing rewritten. Say this to shell: trim --query "why fail" build.log. How big is rock: 1.2 MB model, 7 ms for 5k tokens on one core, 0 GPUs

trim-2

trim-2 is a small two-stage model that decides which lines of a context an AI agent needs for its current ask, and drops the rest.

Give it a context (a tool result, a file, a log, a long chat) and the current query. It returns the context's own lines, in their original order, with a short marker wherever lines were removed. It never rewrites or summarizes a line, so identifiers, paths and error text come through exactly as they were.

  • 3.57 MB. Two-stage contextual gradient-boosted trees (701 stage-1 trees over 134 lexical, sub-identifier, structural, and query features + 641 DAgger stage-2 trees adding 40 sequence, template, and 2-hop anchor-propagation features = 174 total features), paired with exact O(N) Viterbi DP token-knapsack line selection and payload-shape calibration (code, diff, log, grep, structured, prose). Not a neural network.
  • CPU only. About 13 ms for a 2k-token log and about 250 ms for a 50k-token log on one Apple M5 Max core (go test -bench Compress -cpu 1). No GPU, no network call.
  • Deterministic. No sampling and no randomness: the same context and query give the same output.
  • No dependencies. Pure Go, standard library only. The model is embedded.

trim-2 replaces trim-1 in this repository. The trim-1 model card, with its benchmark results and limits, stays on Hugging Face: caveman-so/trim-1. To keep trim-1, pin the last trim-1 commit in go.mod.

Install

Needs Go 1.23 or newer.

go install github.com/caveman-ai/trim-1/cmd/trim@latest

Use

From the command line:

trim --query "why does the build fail" build.log > build.trimmed.log
cat long-document.md | trim --query "what is the refund policy" --point balanced

The trimmed context goes to stdout. A one-line summary goes to stderr:

trim: kept 246 lines, removed 189, 47831 -> 36344 bytes

From Go:

import trim "github.com/caveman-ai/trim-1"

res := trim.Compress(context, query, trim.Options{Point: "balanced"})
fmt.Print(res.Output)

trim.Score(context, query) returns every line with its keep probability, if you want to make the selection yourself.

Which setting to use

--point decides how hard trim-2 cuts: conservative, balanced (the default), aggressive, max, or smart_max. Cutting harder costs quality, because every removed line is one the model can no longer read.

  • balanced is the default for coding-agent tool outputs and documents.
  • conservative keeps more context when missing a single line is costly.
  • aggressive and max cut harder on verbose logs and traces.
  • smart_max uses balanced on source code and diffs and max on everything else (logs, search results, prose, dumps). It picks by the shape of the context, not the query.

From Go, Options{AnnotateOmitted: true} adds a short checked summary to each removal marker, such as an omitted run's error and warning count on a log, the symbols it covered in code, or the files it covered in a diff.

When it does nothing

trim-2 fails closed. It returns the context unchanged, and says why on stderr, when:

  • the query is blank, too vague (no informative terms or identifiers), or asks for the whole context (review the whole file, list every item),
  • the context is under 512 bytes (source code under 900 bytes at balanced and smart_max, under 1,200 bytes at conservative),
  • the context is over 8 MiB or 200,000 lines,
  • the context already has a removal marker line, such as trim-2's own output,
  • the cut would remove less than 5% of the bytes.

The trim command exits with status 2 on a missing --query or an unknown --point. Flags go before the file name.

Test

go test ./...

TestPredictionParity checks the Go tree evaluation against the training library's own predictions, bit for bit. TestGolden pins the full output on a sample log.

License

Apache-2.0. model.go includes a copy of Go's math.Exp, under the BSD license in LICENSE-go. trim-2 is the model inside Caveman.

Explore projetos relacionados

Carregando…