summaryrefslogtreecommitdiffstats
path: root/src/rag
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-06-27 07:51:30 +0800
committerGitHub <noreply@github.com>2024-06-27 07:51:30 +0800
commit1ced451c2723c36b7e0cb70e6c0755cdbad457c3 (patch)
treeea994b6bf4a6ba0f209129419a54e04679c88562 /src/rag
parentf60df039979b8642aa82fec9e6ce56acb3a80f50 (diff)
downloadaichat-1ced451c2723c36b7e0cb70e6c0755cdbad457c3.tar.gz
refactor: agent rag use `documents` field other than `embeddings` dir (#658)
Diffstat (limited to 'src/rag')
-rw-r--r--src/rag/mod.rs12
1 files changed, 8 insertions, 4 deletions
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<usize> {
value.parse().map_err(|_| anyhow!("Invalid chunk_overlay"))
}
-fn add_doc_paths() -> Result<Vec<String>> {
- let text = Text::new("Add document paths:")
+fn add_document_paths() -> Result<Vec<String>> {
+ 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()?;