summaryrefslogtreecommitdiffstats
path: root/src/config
diff options
context:
space:
mode:
Diffstat (limited to 'src/config')
-rw-r--r--src/config/input.rs9
-rw-r--r--src/config/mod.rs29
2 files changed, 26 insertions, 12 deletions
diff --git a/src/config/input.rs b/src/config/input.rs
index 4ddc06f..935d517 100644
--- a/src/config/input.rs
+++ b/src/config/input.rs
@@ -169,8 +169,13 @@ impl Input {
if !self.text.is_empty() {
let rag = self.config.read().rag.clone();
if let Some(rag) = rag {
- let top_k = self.config.read().rag_top_k;
- let embeddings = rag.search(&self.text, top_k, abort_signal).await?;
+ let (top_k, minimum_score) = {
+ let config = self.config.read();
+ (config.rag_top_k, config.rag_minimum_score)
+ };
+ let embeddings = rag
+ .search(&self.text, top_k, minimum_score, abort_signal)
+ .await?;
let text = self.config.read().rag_template(&embeddings, &self.text);
self.patched_text = Some(text);
self.rag_name = Some(rag.name().to_string());
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 41e449a..b2e4517 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -62,18 +62,18 @@ const SUMMARIZE_PROMPT: &str =
const SUMMARY_PROMPT: &str = "This is a summary of the chat history as a recap: ";
const RAG_TEMPLATE: &str = r#"Use the following context as your learned knowledge, inside <context></context> XML tags.
- <context>
- __CONTEXT__
- </context>
+<context>
+__CONTEXT__
+</context>
- When answer to user:
- - If you don't know, just say that you don't know.
- - If you don't know when you are not sure, ask for clarification.
- Avoid mentioning that you obtained the information from the context.
- And answer according to the language of the user's question.
+When answer to user:
+- If you don't know, just say that you don't know.
+- If you don't know when you are not sure, ask for clarification.
+Avoid mentioning that you obtained the information from the context.
+And answer according to the language of the user's question.
- Given the context information, answer the query.
- Query: __INPUT__"#;
+Given the context information, answer the query.
+Query: __INPUT__"#;
const LEFT_PROMPT: &str = "{color.green}{?session {?bot {bot}#}{session}{?role /}}{!session {?bot {bot}}}{role}{?rag @{rag}}{color.cyan}{?session )}{!session >}{color.reset} ";
const RIGHT_PROMPT: &str = "{color.purple}{?session {?consume_tokens {consume_tokens}({consume_percent}%)}{!consume_tokens {consume_tokens}}}{color.reset}";
@@ -105,6 +105,7 @@ pub struct Config {
pub rag_chunk_size: Option<usize>,
pub rag_chunk_overlap: Option<usize>,
pub rag_top_k: usize,
+ pub rag_minimum_score: f32,
pub rag_template: Option<String>,
pub compress_threshold: usize,
pub summarize_prompt: Option<String>,
@@ -157,6 +158,7 @@ impl Default for Config {
rag_chunk_size: None,
rag_chunk_overlap: None,
rag_top_k: 4,
+ rag_minimum_score: 0.0,
rag_template: None,
compress_threshold: 4000,
summarize_prompt: None,
@@ -439,6 +441,7 @@ impl Config {
("temperature", format_option_value(&role.temperature())),
("top_p", format_option_value(&role.top_p())),
("rag_top_k", self.rag_top_k.to_string()),
+ ("rag_minimum_score", self.rag_minimum_score.to_string()),
("function_calling", self.function_calling.to_string()),
("compress_threshold", self.compress_threshold.to_string()),
("dry_run", self.dry_run.to_string()),
@@ -491,6 +494,11 @@ impl Config {
self.rag_top_k = value;
}
}
+ "rag_minimum_score" => {
+ if let Some(value) = parse_value(value)? {
+ self.rag_minimum_score = value;
+ }
+ }
"function_calling" => {
let value = value.parse().with_context(|| "Invalid value")?;
self.function_calling = value;
@@ -1049,6 +1057,7 @@ impl Config {
"temperature",
"top_p",
"rag_top_k",
+ "rag_minimum_score",
"function_calling",
"compress_threshold",
"save",