sigoden/aichat · info

No sources

Error message

No sources

What it means

Thrown by `GlobalConfig::rag_sources` in src/config/mod.rs:1426 when a RAG session IS active but `rag.get_last_sources()` returns `None` — meaning no retrieval has produced citation sources yet (e.g. no query has been answered through the RAG since it was loaded). It is distinct from the 'No RAG' branch in the same function, which fires when no RAG is loaded at all.

Solutions

  1. Run at least one RAG-backed query first, then request the sources
  2. If the query legitimately matched nothing, treat 'no sources' as an expected empty state rather than an error
  3. Check `rag.get_last_sources().is_some()` before calling and fall back to a friendly message

Example fix

// before
let sources = Config::rag_sources(&config)?;
// after
match config.read().rag.as_ref().and_then(|r| r.get_last_sources()) {
    Some(s) => println!("{s}"),
    None => println!("No sources yet — run a RAG query first"),
}
Defensive patterns

Strategy: fallback

Validate before calling

let has_sources = config.read().rag.as_ref()
    .and_then(|r| r.get_last_sources()).is_some();
if !has_sources {
    eprintln!("No sources yet — run a RAG-backed query first");
}

Try / catch

match Config::rag_sources(&config) {
    Ok(s) => println!("{s}"),
    Err(e) if e.to_string() == "No sources" => println!("(no sources recorded yet)"),
    Err(e) => return Err(e.into()),
}

Prevention

When it happens

Trigger: Calling `Config::rag_sources(config)` right after entering RAG mode, before any chat/query has run through the RAG; after a query that retrieved nothing; after the sources cache was cleared on a fresh `Rag::load`.

Common situations: Users asking for '.last sources' (or equivalent) immediately after loading a RAG; scripts that fetch sources before the first RAG-backed answer; queries whose embedding matched no documents.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


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

Appendix: source

Thrown at src/config/mod.rs:1426

    }

    pub async fn rebuild_rag(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().to_vec();
        rag.refresh_document_paths(&document_paths, true, config, abort_signal)
            .await?;
        config.write().rag = Some(Arc::new(rag));
        Ok(())
    }

    pub fn rag_sources(config: &GlobalConfig) -> Result<String> {
        match config.read().rag.as_ref() {
            Some(rag) => match rag.get_last_sources() {
                Some(v) => Ok(v),
                None => bail!("No sources"),
            },
            None => bail!("No RAG"),
        }
    }

    pub fn rag_info(&self) -> Result<String> {
        if let Some(rag) = &self.rag {
            rag.export()
        } else {
            bail!("No RAG")
        }
    }

    pub fn exit_rag(&mut self) -> Result<()> {
        self.rag.take();
        Ok(())
    }

View on GitHub (pinned to 82976d349a)