{"record":{"id":"c52c922dfa86e84c","repo":"sigoden/aichat","slug":"no-rag-files","errorCode":null,"errorMessage":"No RAG files","messagePattern":"No RAG files","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/rag/mod.rs","lineNumber":499,"sourceCode":"                    texts.push(document.page_content.clone())\n                }\n                files.push((next_file_id, file));\n                next_file_id += 1;\n            }\n\n            let embeddings_data = EmbeddingsData::new(texts, false);\n            embeddings = self\n                .create_embeddings(embeddings_data, spinner.clone())\n                .await?;\n        }\n\n        let to_delete_file_ids: Vec<_> = to_deleted.values().flatten().copied().collect();\n        self.data.del(to_delete_file_ids);\n        self.data.add(next_file_id, files, document_ids, embeddings);\n        self.data.document_paths = document_paths.into_iter().collect();\n\n        if self.data.files.is_empty() {\n            bail!(\"No RAG files\");\n        }\n\n        progress(&spinner, \"Building store\".into());\n        self.hnsw = self.data.build_hnsw();\n        self.bm25 = self.data.build_bm25();\n\n        Ok(())\n    }\n\n    async fn hybird_search(\n        &self,\n        query: &str,\n        top_k: usize,\n        rerank_model: Option<&str>,\n    ) -> Result<Vec<(DocumentId, String)>> {\n        let (vector_search_results, keyword_search_results) = tokio::join!(\n            self.vector_search(query, top_k, 0.0),\n            self.keyword_search(query, top_k, 0.0),","sourceCodeStart":481,"sourceCodeEnd":517,"githubUrl":"https://github.com/sigoden/aichat/blob/82976d349ad97ac9aae0655ad631dace5e2a6385/src/rag/mod.rs#L481-L517","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add at least one supported document to the configured documents directory","Verify the documents directory path in your RAG config points to a non-empty folder","Fix load failures (permissions, unsupported formats) reported before this error","If you intentionally want an empty state, clear the RAG session/role instead of syncing an empty directory"],"exampleFix":"// before\nrag.sync_documents(&progress)?;\n// after\nlet files: Vec<_> = std::fs::read_dir(&docs_dir)?.collect();\nif files.is_empty() {\n    eprintln!(\"No documents to index; skipping RAG sync\");\n} else {\n    rag.sync_documents(&progress)?;\n}","handlingStrategy":"validation","validationCode":"let has_docs = std::fs::read_dir(&docs_dir)\n    .map(|mut d| d.next().is_some())\n    .unwrap_or(false);\nif !has_docs {\n    eprintln!(\"No documents to index; skipping RAG sync\");\n    return;\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = rag.sync_documents(&progress) {\n    if e.to_string() == \"No RAG files\" {\n        eprintln!(\"RAG has no indexed documents; add files to the documents directory\");\n    } else { return Err(e); }\n}","preventionTips":["Keep at least one supported document in the documents directory","Verify the documents directory path in config before syncing","Fix loader errors reported before the sync"],"tags":["rag","empty","documents"],"backgroundTag":"empty-required-field","analyzedSha":"82976d349ad97ac9aae0655ad631dace5e2a6385","analyzedAt":"2026-09-09T18:33:06.139Z","contentChangedAt":"2026-09-09T18:33:06.139Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}