sigoden/aichat · error · anyhow::Error
Invalid chunk_size
Error message
Invalid chunk_size
What it means
In the interactive RAG setup wizard, set_chunk_size prompts the user for a chunk size and parses it as usize. Any non-numeric (or unparsable) input fails validation at parse time with this generic error.
Solutions
- Re-run the setup and enter a plain positive integer, e.g. 2000
- Use the interactive prompt's validator feedback — input must be an integer
- Edit the generated RAG config file directly to set chunk_size numerically
Example fix
// at the prompt // before: chunk size: 2k // after: chunk size: 2000
Defensive patterns
Strategy: validation
Validate before calling
fn valid_chunk_size(s: &str) -> bool { s.trim().parse::<usize>().is_ok() } Try / catch
let cs: usize = prompt_and_parse("chunk size").map_err(|_| {
eprintln!("Enter a plain positive integer, e.g. 2000"); retry()
})?; Prevention
- Enter plain integers without units or suffixes
- Strip whitespace before submitting prompt input
- Prefer editing the config file over interactive entry for scripted setups
When it happens
Trigger: Entering a value that doesn't parse as usize at the 'chunk size' prompt during rag create_config (e.g. '1k', '10.5', '', 'abc').
Common situations: Typing suffixed numbers like '512b' or '1k'; pasting values with whitespace/units; accidental non-digit input.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
AI-assisted analysis of sigoden/aichat@82976d349a (2026-09-09).
Data as JSON: /api/errors/42de5e557cf7d747.
Report an issue: GitHub.
Appendix: source
Thrown at src/rag/mod.rs:903
let default_value = model.default_chunk_size().to_string();
let help_message = model
.max_tokens_per_chunk()
.map(|v| format!("The model's max_tokens is {v}"));
let mut text = Text::new("Set chunk size:")
.with_default(&default_value)
.with_validator(move |text: &str| {
let out = match text.parse::<usize>() {
Ok(_) => Validation::Valid,
Err(_) => Validation::Invalid("Must be a integer".into()),
};
Ok(out)
});
if let Some(help_message) = &help_message {
text = text.with_help_message(help_message);
}
let value = text.prompt()?;
value.parse().map_err(|_| anyhow!("Invalid chunk_size"))
}
fn set_chunk_overlay(default_value: usize) -> Result<usize> {
let value = Text::new("Set chunk overlay:")
.with_default(&default_value.to_string())
.with_validator(move |text: &str| {
let out = match text.parse::<usize>() {
Ok(_) => Validation::Valid,
Err(_) => Validation::Invalid("Must be a integer".into()),
};
Ok(out)
})
.prompt()?;
value.parse().map_err(|_| anyhow!("Invalid chunk_overlay"))
}
fn add_documents() -> Result<Vec<String>> {
let text = Text::new("Add documents:")View on GitHub (pinned to 82976d349a)