Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/build-release-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ on:
- 'README.md'

env:
GO_VERSION: '1.25.4' # Updated to match toolchain
BINARY_NAME: 'ingest'

permissions:
Expand Down
107 changes: 24 additions & 83 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Ingest parses directories of plain text files, such as source code, into a singl

![ingest](screenshot2.png)

Ingest can also pass the prompt directly to an LLM such as Ollama for processing.
Ingest can also pass the prompt directly to any OpenAI compatible API for processing.

![ingest with --llm](screenshot.png)

Expand All @@ -21,10 +21,9 @@ And ingest web URLs.
- Traverse directory structures and generate a tree view
- Include/exclude files based on glob patterns
- Compress code using Tree-sitter to extract key structural information while omitting implementation details
- Estimate vRAM requirements and check model compatibility using another package I've created called [quantest](https://github.com/sammcj/quantest)
- Parse output directly to LLMs such as Ollama or any OpenAI compatible API for processing
- Parse output directly to any OpenAI compatible API for processing
- Generate and include git diffs and logs
- Count tokens using offline tokeniser (default) or optionally use Anthropic API (API key required, but no charge for counting)
- Count tokens using a bundled offline tokeniser (default) or optionally use the Anthropic API (API key required, but no charge for counting)
- Customisable output templates
- Copy output to clipboard (when available)
- Export to file or print to console
Expand Down Expand Up @@ -79,7 +78,17 @@ $ ingest
[✅] Copied to clipboard successfully.
```

The first time ingest runs, it will download a small [tokeniser](https://github.com/pkoukk/tiktoken-go-loader/blob/main/assets/cl100k_base.tiktoken) called 'cl100k_base.tiktoken' this is used for tokenisation.
### Token counting

The tokeniser vocabularies (o200k_base and cl100k_base) are compiled into the binary, so ingest works offline and never downloads or caches anything.

Anthropic has never published a Claude tokeniser, so offline counts are produced with o200k_base and scaled to the model given by `--model` (default `claude-opus-5`):

- Claude Opus 4.7 and later, including Opus 5, Sonnet 5 and Fable 5, use a tokeniser that produces roughly 30% more tokens for the same text than earlier Claude models. These are scaled by 1.53.
- Earlier Claude models are scaled by 1.18.
- Non-Claude models are counted with their own vocabulary, so no scaling is applied.

Both factors are approximations that vary with content. For an exact count use `-a/--anthropic`, which calls Anthropic's `count_tokens` endpoint with the same `--model` (free, but needs `ANTHROPIC_API_KEY`). `--no-correction` reports the raw o200k_base count.

Generate a prompt from a directory, including only Python files:

Expand Down Expand Up @@ -117,78 +126,16 @@ Save output to to ~/ingest/<directory_name>.md:
ingest --save /path/to/project
```

### VRAM Estimation and Model Compatibility

Ingest includes a feature to estimate VRAM requirements and check model compatibility using the [Gollama](https://github.com/sammcj/gollama)'s vramestimator package. This helps you determine if your generated content will fit within the specified model, VRAM, and quantisation constraints.

To use this feature, add the following flags to your ingest command:

```shell
ingest --vram --model <model_id> [--memory <memory_in_gb>] [--quant <quantisation>] [--context <context_length>] [--kvcache <kv_cache_quant>] [--quanttype <quant_type>] [other flags] <paths>
```

Examples:

Estimate VRAM usage for a specific context:

```shell
ingest --vram --model NousResearch/Hermes-2-Theta-Llama-3-8B --quant q4_k_m --context 2048 --kvcache q4_0 .
# Estimated VRAM usage: 5.35 GB
```

Calculate maximum context for a given memory constraint:

```shell
ingest --vram --model NousResearch/Hermes-2-Theta-Llama-3-8B --quant q4_k_m --memory 6 --kvcache q8_0 .
# Maximum context for 6.00 GB of memory: 5069
```

Find the best BPW (Bits Per Weight):

```shell
ingest --vram --model NousResearch/Hermes-2-Theta-Llama-3-8B --memory 6 --quanttype gguf .
# Best BPW for 6.00 GB of memory: IQ3_S
```

The tool also works for exl2 (ExllamaV2) models:

```shell
ingest --vram --model NousResearch/Hermes-2-Theta-Llama-3-8B --quant 5.0 --context 2048 --kvcache q4_0 . # For exl2 models
ingest --vram --model NousResearch/Hermes-2-Theta-Llama-3-8B --quant 5.0 --memory 6 --kvcache q8_0 . # For exl2 models
```

When using the VRAM estimation feature along with content generation, ingest will provide information about the generated content's compatibility with the specified constraints:
Count tokens for a specific model, or exactly via the Anthropic API:

```shell
ingest --vram --model NousResearch/Hermes-2-Theta-Llama-3-8B --memory 8 --quant q4_0 .
⠋ Traversing directory and building tree... [0s]
[ℹ️] 14,702 Tokens (Approximate)
[ℹ️] Maximum context for 8.00 GB of memory: 10240
[✅] Generated content (14,702 tokens) fits within maximum context.
Top 15 largest files (by estimated token count):
1. /Users/samm/git/sammcj/ingest/main.go (4,682 tokens)
2. /Users/samm/git/sammcj/ingest/filesystem/filesystem.go (2,694 tokens)
3. /Users/samm/git/sammcj/ingest/README.md (1,895 tokens)
4. /Users/samm/git/sammcj/ingest/utils/utils.go (948 tokens)
5. /Users/samm/git/sammcj/ingest/config/config.go (884 tokens)
[✅] Copied to clipboard successfully.
ingest --model claude-fable-5 /path/to/project
ingest --anthropic /path/to/project
```

Available flags for VRAM estimation:

- `--vram`: Enable VRAM estimation and model compatibility check
- `--model`: Specify the model ID to check against (required for estimation)
- `--memory`: Specify the available memory in GB for context calculation (optional)
- `--quant`: Specify the quantisation type (e.g., q4_k_m) or bits per weight (e.g., 5.0)
- `--context`: Specify the context length for VRAM estimation (optional)
- `--kvcache`: Specify the KV cache quantisation (fp16, q8_0, or q4_0)
- `--quanttype`: Specify the quantisation type (gguf or exl2)

Ingest will provide appropriate output based on the combination of flags used, such as estimating VRAM usage, calculating maximum context, or finding the best BPW. If the generated content fits within the specified constraints, you'll see a success message. Otherwise, you'll receive a warning that the content may not fit.

## LLM Integration

Ingest can pass the generated prompt to LLMs that have an OpenAI compatible API such as [Ollama](https://ollama.com) for processing.
Ingest can pass the generated prompt to any OpenAI compatible API for processing.

```shell
ingest --llm /path/to/project
Expand Down Expand Up @@ -351,11 +298,10 @@ For persistent completions (loaded automatically in each new shell session), see

Ingest uses a configuration file located at `~/.config/ingest/ingest.json`.

You can make Ollama processing run without prompting setting `"llm_auto_run": true` in the config file.

The config file also contains:
The config file contains:

- `llm_model`: The model to use for processing the prompt, e.g. "llama3.1:8b-q5_k_m".
- `llm_model`: The model to use for processing the prompt with `--llm`. Required if you use `--llm`.
- `llm_base_url`: The OpenAI compatible endpoint, defaults to `$OPENAI_API_BASE` or `https://api.openai.com/v1`.
- `llm_prompt_prefix`: An optional prefix to prepend to the prompt, e.g. "This is my application."
- `llm_prompt_suffix`: An optional suffix to append to the prompt, e.g. "explain this code"

Expand All @@ -372,29 +318,24 @@ These directories will be created automatically on first run, along with README
- `--compress`: Enable code compression using Tree-sitter to extract key structural information while omitting implementation details
- `--config`: Opens the config file in the default editor
- `--no-correction`: Disable offline tokeniser correction factor (use raw token count)
- `--context`: Specify the context length for VRAM estimation
- `-c, --encoding`: Offline tokeniser vocabulary (o200k, cl100k)
- `-m, --model`: Model to count tokens for, defaults to claude-opus-5
- `--exclude-from-tree`: Exclude files/folders from the source tree based on exclude patterns
- `--git-diff-branch`: Generate git diff between two branches
- `--git-log-branch`: Retrieve git log between two branches
- `--include-priority`: Include files in case of conflict between include and exclude patterns
- `--json`: Print output as JSON
- `--kvcache`: Specify the KV cache quantisation
- `--llm`: Send the generated prompt to an OpenAI compatible LLM server (such as Ollama) for processing
- `--memory`: Specify the available memory in GB for context calculation
- `--model`: Specify the model ID for VRAM estimation
- `--llm`: Send the generated prompt to an OpenAI compatible LLM server for processing
- `--no-codeblock`: Disable wrapping code inside markdown code blocks
- `--no-default-excludes`: Disable default exclude patterns
- `--pattern-exclude`: Path to a specific .glob file for exclude patterns
- `--print-default-excludes`: Print the default exclude patterns
- `--print-default-template`: Print the default template
- `--quant`: Specify the quantisation type or bits per weight
- `--quanttype`: Specify the quantisation type (gguf or exl2)
- `--relative-paths`: Use relative paths instead of absolute paths
- `--report`: Print the largest parsed files
- `--save`: Save output to ~/ingest/<directory_name>.md
- `--tokens`: Display the token count of the generated prompt
- `--verbose`: Print verbose output
- `--vram`: Estimate VRAM usage and check model compatibility
- `--web-concurrent`: Maximum concurrent requests for web crawling
- `--web-depth`: Maximum depth for web crawling
- `--web-domains`: Comma-separated list of domains to restrict web crawling
Expand Down
32 changes: 6 additions & 26 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,9 @@ import (
"github.com/mitchellh/go-homedir"
)

type OllamaConfig struct {
Model string `json:"llm_model"`
PromptPrefix string `json:"llm_prompt_prefix"`
PromptSuffix string `json:"llm_prompt_suffix"`
AutoRun bool `json:"llm_auto_run"`
}

type Config struct {
Ollama []OllamaConfig `json:"ollama"`
LLM LLMConfig `json:"llm"`
AutoSave bool `json:"auto_save"`
LLM LLMConfig `json:"llm"`
AutoSave bool `json:"auto_save"`
}

type LLMConfig struct {
Expand All @@ -33,6 +25,8 @@ type LLMConfig struct {
PresencePenalty *float32 `json:"llm_presence_penalty,omitempty"`
FrequencyPenalty *float32 `json:"llm_frequency_penalty,omitempty"`
APIType string `json:"llm_api_type"`
PromptPrefix string `json:"llm_prompt_prefix"`
PromptSuffix string `json:"llm_prompt_suffix"`
}

// loads the config file
Expand Down Expand Up @@ -64,9 +58,6 @@ func LoadConfig() (*Config, error) {
if config.LLM.BaseURL == "" {
config.LLM.BaseURL = getDefaultBaseURL()
}
if config.LLM.Model == "" {
config.LLM.Model = "llama3.1:8b-instruct-q6_K"
}
if config.LLM.MaxTokens == 0 {
config.LLM.MaxTokens = 2048
}
Expand All @@ -79,18 +70,10 @@ func LoadConfig() (*Config, error) {

func createDefaultConfig(configPath string) (*Config, error) {
defaultConfig := Config{
Ollama: []OllamaConfig{
{
Model: "llama3.1:8b-instruct-q6_K",
PromptPrefix: "Code: ",
PromptSuffix: "",
AutoRun: false,
},
},
LLM: LLMConfig{
BaseURL: getDefaultBaseURL(),
Model: "llama3.1:8b-instruct-q6_K",
MaxTokens: 2048,
APIType: "OPEN_AI",
},
AutoSave: false,
}
Expand All @@ -117,10 +100,7 @@ func getDefaultBaseURL() string {
if url := os.Getenv("OPENAI_API_BASE"); url != "" {
return url
}
if url := os.Getenv("llm_HOST"); url != "" {
return url + "/v1"
}
return "http://localhost:11434/v1"
return "https://api.openai.com/v1"
}

// opens the config file in the default editor
Expand Down
64 changes: 27 additions & 37 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,69 +4,59 @@ go 1.25.6

require (
github.com/JohannesKaufmann/html-to-markdown v1.6.0
github.com/PuerkitoBio/goquery v1.11.0
github.com/PuerkitoBio/goquery v1.12.0
github.com/atotto/clipboard v0.1.4
github.com/bmatcuk/doublestar/v4 v4.9.2
github.com/charmbracelet/glamour v0.10.0
github.com/fatih/color v1.18.0
github.com/bmatcuk/doublestar/v4 v4.10.0
github.com/charmbracelet/glamour v1.0.0
github.com/fatih/color v1.19.0
github.com/ledongthuc/pdf v0.0.0-20250511090121-5959a4027728
github.com/mitchellh/go-homedir v1.1.0
github.com/pkoukk/tiktoken-go v0.1.8
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
github.com/sashabaranov/go-openai v1.41.2
github.com/schollz/progressbar/v3 v3.19.0
github.com/sashabaranov/go-openai v1.42.0
github.com/schollz/progressbar/v3 v3.19.1
github.com/smacker/go-tree-sitter v0.0.0-20240827094217-dd81d9e9be82
github.com/spf13/cobra v1.10.2
)

require (
github.com/andybalholm/cascadia v1.3.3 // indirect
github.com/charmbracelet/colorprofile v0.4.1 // indirect
github.com/charmbracelet/x/cellbuf v0.0.14 // indirect
github.com/charmbracelet/x/exp/slice v0.0.0-20260119114936-fd556377ea59 // indirect
github.com/andybalholm/cascadia v1.3.4 // indirect
github.com/charmbracelet/colorprofile v0.4.3 // indirect
github.com/charmbracelet/x/cellbuf v0.0.15 // indirect
github.com/charmbracelet/x/exp/slice v0.0.0-20260803091719-3755ebad01b1 // indirect
github.com/charmbracelet/x/term v0.2.2 // indirect
github.com/clipperhouse/displaywidth v0.7.0 // indirect
github.com/clipperhouse/stringish v0.1.1 // indirect
github.com/clipperhouse/uax29/v2 v2.3.1 // indirect
github.com/olekukonko/cat v0.0.0-20250911104152-50322a0618f6 // indirect
github.com/olekukonko/errors v1.2.0 // indirect
github.com/olekukonko/ll v0.1.4-0.20260115111900-9e59c2286df0 // indirect
github.com/sammcj/gollama v1.37.5 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/text v0.33.0 // indirect
github.com/clipperhouse/displaywidth v0.11.0 // indirect
github.com/clipperhouse/uax29/v2 v2.7.0 // indirect
github.com/xo/terminfo v1.0.0 // indirect
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 // indirect
golang.org/x/text v0.40.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

require (
github.com/alecthomas/chroma/v2 v2.23.0 // indirect
github.com/alecthomas/chroma/v2 v2.27.0 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/charmbracelet/lipgloss v1.1.1-0.20250404203927-76690c660834 // indirect
github.com/charmbracelet/x/ansi v0.11.4 // indirect
github.com/dlclark/regexp2 v1.11.5 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/charmbracelet/x/ansi v0.11.7 // indirect
github.com/dlclark/regexp2 v1.12.0 // indirect
github.com/dlclark/regexp2/v2 v2.6.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.19 // indirect
github.com/lucasb-eyer/go-colorful v1.4.1 // indirect
github.com/mattn/go-colorable v0.1.15 // indirect
github.com/mattn/go-isatty v0.0.24 // indirect
github.com/mattn/go-runewidth v0.0.27 // indirect
github.com/microcosm-cc/bluemonday v1.0.27 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.16.0 // indirect
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
github.com/olekukonko/tablewriter v1.1.3 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rs/zerolog v1.34.0 // indirect
github.com/sammcj/quantest v0.0.13
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/yuin/goldmark v1.7.16 // indirect
github.com/yuin/goldmark v1.8.5 // indirect
github.com/yuin/goldmark-emoji v1.0.6 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
golang.org/x/net v0.49.0 // indirect
golang.org/x/sys v0.40.0 // indirect
golang.org/x/term v0.39.0 // indirect
golang.org/x/net v0.57.0 // indirect
golang.org/x/sys v0.47.0 // indirect
golang.org/x/term v0.45.0 // indirect
)
Loading
Loading