sigoden/aichat · error

No RAG

Error message

No RAG

What it means

Thrown by `GlobalConfig::edit_rag_docs` in src/config/mod.rs:1377 when there is no active RAG session: `config.read().rag` is `None`. Editing RAG documents only makes sense inside an active RAG session, so the function fails immediately instead of guessing which RAG to edit.

Solutions

  1. Enter RAG mode first (e.g. `.rag <name>` / `use_rag`) so `config.rag` is populated, then run edit-docs
  2. Call `use_rag(config, Some(name), signal)` programmatically before `edit_rag_docs`
  3. Check `config.read().rag.is_some()` before invoking and surface a friendlier message

Example fix

// before
config.edit_rag_docs(signal).await?;
// after
if config.read().rag.is_none() {
    config.use_rag(Some("mydocs"), signal).await?;
}
config.edit_rag_docs(signal).await?;
Defensive patterns

Strategy: validation

Validate before calling

if config.read().rag.is_none() {
    bail!("No RAG loaded; run '.rag <name>' before editing documents");
}

Try / catch

if let Err(e) = config.edit_rag_docs(signal).await {
    if e.to_string() == "No RAG" {
        eprintln!("Enter RAG mode first: .rag <name>");
        return Ok(());
    }
    return Err(e.into());
}

Prevention

When it happens

Trigger: Calling `Config::edit_rag_docs(config, abort_signal)` (or the `.rag edit-docs`-style command) without having entered RAG mode first — i.e. `config.rag` was never set via `use_rag`/`Rag::load`, or was cleared by `exit_rag`.

Common situations: Running the edit-docs command in a fresh session; running it after `.exit rag`; assuming a previously used RAG persists across sessions when it is only held in the in-memory config.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of sigoden/aichat@82976d349a (2026-09-09). Data as JSON: /api/errors/d35c3c696f9e2421. Report an issue: GitHub.

Appendix: source

Thrown at src/config/mod.rs:1377

                let rag_path = config.read().rag_file(name);
                if !rag_path.exists() {
                    if config.read().working_mode.is_cmd() {
                        bail!("Unknown RAG '{name}'")
                    }
                    Rag::init(config, name, &rag_path, &[], abort_signal).await?
                } else {
                    Rag::load(config, name, &rag_path)?
                }
            }
        };
        config.write().rag = Some(Arc::new(rag));
        Ok(())
    }

    pub async fn edit_rag_docs(config: &GlobalConfig, abort_signal: AbortSignal) -> Result<()> {
        let mut rag = match config.read().rag.clone() {
            Some(v) => v.as_ref().clone(),
            None => bail!("No RAG"),
        };

        let document_paths = rag.document_paths();
        let temp_file = temp_file(&format!("-rag-{}", rag.name()), ".txt");
        tokio::fs::write(&temp_file, &document_paths.join("\n"))
            .await
            .with_context(|| format!("Failed to write to '{}'", temp_file.display()))?;
        let editor = config.read().editor()?;
        edit_file(&editor, &temp_file)?;
        let new_document_paths = tokio::fs::read_to_string(&temp_file)
            .await
            .with_context(|| format!("Failed to read '{}'", temp_file.display()))?;
        let new_document_paths = new_document_paths
            .split('\n')
            .filter_map(|v| {
                let v = v.trim();
                if v.is_empty() {
                    None

View on GitHub (pinned to 82976d349a)