Skip to content

Commit

Permalink
feat: discontinue rag_min_score_* config items (#1081)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden authored Jan 10, 2025
1 parent 927b736 commit 486ee57
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 46 deletions.
12 changes: 5 additions & 7 deletions config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ summary_prompt: 'This is a summary of the chat history as a recap: '

# ---- RAG ----
# See [RAG-Guide](https://github.com/sigoden/aichat/wiki/RAG-Guide) for more details.
rag_embedding_model: null # Specifies the embedding model to use
rag_reranker_model: null # Specifies the rerank model to use
rag_top_k: 5 # Specifies the number of documents to retrieve
rag_chunk_size: null # Specifies the chunk size
rag_chunk_overlap: null # Specifies the chunk overlap
rag_min_score_vector_search: 0 # Specifies the minimum relevance score for vector-based searching
rag_min_score_keyword_search: 0 # Specifies the minimum relevance score for keyword-based searching
rag_embedding_model: null # Specifies the embedding model used for context retrieval
rag_reranker_model: null # Specifies the reranker model used for sorting retrieved documents
rag_top_k: 5 # Specifies the number of documents to retrieve for answering queries
rag_chunk_size: null # Defines the size of chunks for document processing in characters
rag_chunk_overlap: null # Defines the overlap between chunks
# Defines the query structure using variables like __CONTEXT__ and __INPUT__ to tailor searches to specific needs
rag_template: |
Answer the query based on the context while respecting the rules. (user query, some textual context and rules, all inside xml tags)
Expand Down
27 changes: 1 addition & 26 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ pub struct Config {
pub rag_top_k: usize,
pub rag_chunk_size: Option<usize>,
pub rag_chunk_overlap: Option<usize>,
pub rag_min_score_vector_search: f32,
pub rag_min_score_keyword_search: f32,
pub rag_template: Option<String>,

#[serde(default)]
Expand Down Expand Up @@ -197,8 +195,6 @@ impl Default for Config {
rag_top_k: 5,
rag_chunk_size: None,
rag_chunk_overlap: None,
rag_min_score_vector_search: 0.0,
rag_min_score_keyword_search: 0.0,
rag_template: None,

document_loaders: Default::default(),
Expand Down Expand Up @@ -1413,22 +1409,8 @@ impl Config {
abort_signal: AbortSignal,
) -> Result<String> {
let (reranker_model, top_k) = rag.get_config();
let (min_score_vector_search, min_score_keyword_search) = {
let config = config.read();
(
config.rag_min_score_vector_search,
config.rag_min_score_keyword_search,
)
};
let (embeddings, ids) = rag
.search(
text,
top_k,
min_score_vector_search,
min_score_keyword_search,
reranker_model.as_deref(),
abort_signal,
)
.search(text, top_k, reranker_model.as_deref(), abort_signal)
.await?;
let text = config.read().rag_template(&embeddings, text);
rag.set_last_sources(&ids);
Expand Down Expand Up @@ -2222,13 +2204,6 @@ impl Config {
if let Some(v) = read_env_value::<usize>(&get_env_name("rag_chunk_overlap")) {
self.rag_chunk_overlap = v;
}
if let Some(Some(v)) = read_env_value::<f32>(&get_env_name("rag_min_score_vector_search")) {
self.rag_min_score_vector_search = v;
}
if let Some(Some(v)) = read_env_value::<f32>(&get_env_name("rag_min_score_keyword_search"))
{
self.rag_min_score_keyword_search = v;
}
if let Some(v) = read_env_value::<String>(&get_env_name("rag_template")) {
self.rag_template = v;
}
Expand Down
16 changes: 3 additions & 13 deletions src/rag/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,19 +297,11 @@ impl Rag {
&self,
text: &str,
top_k: usize,
min_score_vector_search: f32,
min_score_keyword_search: f32,
rerank_model: Option<&str>,
abort_signal: AbortSignal,
) -> Result<(String, Vec<DocumentId>)> {
let ret = abortable_run_with_spinner(
self.hybird_search(
text,
top_k,
min_score_vector_search,
min_score_keyword_search,
rerank_model,
),
self.hybird_search(text, top_k, rerank_model),
"Searching",
abort_signal,
)
Expand Down Expand Up @@ -497,13 +489,11 @@ impl Rag {
&self,
query: &str,
top_k: usize,
min_score_vector_search: f32,
min_score_keyword_search: f32,
rerank_model: Option<&str>,
) -> Result<Vec<(DocumentId, String)>> {
let (vector_search_results, keyword_search_results) = tokio::join!(
self.vector_search(query, top_k, min_score_vector_search),
self.keyword_search(query, top_k, min_score_keyword_search)
self.vector_search(query, top_k, 0.0),
self.keyword_search(query, top_k, 0.0),
);

let vector_search_results = vector_search_results?;
Expand Down

0 comments on commit 486ee57

Please sign in to comment.