From 1ced451c2723c36b7e0cb70e6c0755cdbad457c3 Mon Sep 17 00:00:00 2001 From: sigoden Date: Thu, 27 Jun 2024 07:51:30 +0800 Subject: refactor: agent rag use `documents` field other than `embeddings` dir (#658) --- src/rag/mod.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/rag') diff --git a/src/rag/mod.rs b/src/rag/mod.rs index 3139b7e..f01fc0c 100644 --- a/src/rag/mod.rs +++ b/src/rag/mod.rs @@ -56,7 +56,7 @@ impl Rag { let mut rag = Self::create(config, name, save_path, data)?; let mut paths = doc_paths.to_vec(); if paths.is_empty() { - paths = add_doc_paths()?; + paths = add_document_paths()?; }; debug!("doc paths: {paths:?}"); let loaders = config.read().rag_document_loaders.clone(); @@ -233,7 +233,7 @@ impl Rag { progress(&spinner, "Gathering paths".into()); for path in paths { let path = path.as_ref(); - if path.starts_with("http://") || path.starts_with("https://") { + if Self::is_url_path(path) { if let Some(path) = path.strip_suffix("**") { new_paths.push((path.to_string(), RECURSIVE_URL_LOADER.into())); } else { @@ -337,6 +337,10 @@ impl Rag { Ok(()) } + pub fn is_url_path(path: &str) -> bool { + path.starts_with("http://") || path.starts_with("https://") + } + async fn hybird_search( &self, query: &str, @@ -628,8 +632,8 @@ fn set_chunk_overlay(default_value: usize) -> Result { value.parse().map_err(|_| anyhow!("Invalid chunk_overlay")) } -fn add_doc_paths() -> Result> { - let text = Text::new("Add document paths:") +fn add_document_paths() -> Result> { + let text = Text::new("Add documents:") .with_validator(required!("This field is required")) .with_help_message("e.g. file;dir/;dir/**/*.md;url;sites/**") .prompt()?; -- cgit v1.2.3