sigoden/aichat · error

No RAG files

Error message

No RAG files

What it means

`sync_documents` throws `bail!("No RAG files")` when, after rebuilding the data store, `self.data.files` is empty — i.e. no documents were successfully loaded/indexed. The library refuses to build an empty HNSW/BM25 store, since RAG cannot operate without at least one indexed file.

Solutions

  1. Add at least one supported document to the configured documents directory
  2. Verify the documents directory path in your RAG config points to a non-empty folder
  3. Fix load failures (permissions, unsupported formats) reported before this error
  4. If you intentionally want an empty state, clear the RAG session/role instead of syncing an empty directory

Example fix

// before
rag.sync_documents(&progress)?;
// after
let files: Vec<_> = std::fs::read_dir(&docs_dir)?.collect();
if files.is_empty() {
    eprintln!("No documents to index; skipping RAG sync");
} else {
    rag.sync_documents(&progress)?;
}
Defensive patterns

Strategy: validation

Validate before calling

let has_docs = std::fs::read_dir(&docs_dir)
    .map(|mut d| d.next().is_some())
    .unwrap_or(false);
if !has_docs {
    eprintln!("No documents to index; skipping RAG sync");
    return;
}

Try / catch

if let Err(e) = rag.sync_documents(&progress) {
    if e.to_string() == "No RAG files" {
        eprintln!("RAG has no indexed documents; add files to the documents directory");
    } else { return Err(e); }
}

Prevention

When it happens

Trigger: Calling sync_documents/refresh_document_paths when the documents directory is empty, when every document failed to load, or when all previously indexed files were deleted and no new valid files exist.

Common situations: Misconfigured documents directory path (wrong or empty folder); all documents removed from disk; loader failures for every file (bad formats, permissions); pointing the RAG config at a directory that only contains unsupported files.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at src/rag/mod.rs:499

                    texts.push(document.page_content.clone())
                }
                files.push((next_file_id, file));
                next_file_id += 1;
            }

            let embeddings_data = EmbeddingsData::new(texts, false);
            embeddings = self
                .create_embeddings(embeddings_data, spinner.clone())
                .await?;
        }

        let to_delete_file_ids: Vec<_> = to_deleted.values().flatten().copied().collect();
        self.data.del(to_delete_file_ids);
        self.data.add(next_file_id, files, document_ids, embeddings);
        self.data.document_paths = document_paths.into_iter().collect();

        if self.data.files.is_empty() {
            bail!("No RAG files");
        }

        progress(&spinner, "Building store".into());
        self.hnsw = self.data.build_hnsw();
        self.bm25 = self.data.build_bm25();

        Ok(())
    }

    async fn hybird_search(
        &self,
        query: &str,
        top_k: usize,
        rerank_model: Option<&str>,
    ) -> Result<Vec<(DocumentId, String)>> {
        let (vector_search_results, keyword_search_results) = tokio::join!(
            self.vector_search(query, top_k, 0.0),
            self.keyword_search(query, top_k, 0.0),

View on GitHub (pinned to 82976d349a)