Skip to content

Commit 8a80166

Browse files
fix(search): remove bm25 config file dependency (#48)
1 parent 334b346 commit 8a80166

9 files changed

Lines changed: 17 additions & 112 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 63 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configuration/bm25.yml

Lines changed: 0 additions & 2 deletions
This file was deleted.

crates/core/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ workspace = true
2323
ignore = "^0.4"
2424
rust-stemmers = "^1.2"
2525
stop-words = "^0.10"
26-
config = { version = "^0.15", default-features = false, features = ["yaml"] }
2726
serde = { version = "^1.0", features = ["derive"] }
2827
serde_json = "^1.0"
2928
rayon = "^1.11"

crates/core/src/error.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
#[derive(Debug, thiserror::Error)]
2-
pub enum RankingError {
3-
#[error("failed to load BM25 configuration")]
4-
ConfigLoad(#[from] config::ConfigError),
5-
#[error("failed to determine current directory")]
6-
CurrentDir(#[source] std::io::Error),
7-
}
8-
91
#[derive(Debug, thiserror::Error)]
102
pub enum EvalError {
113
#[error("failed to parse evaluation data")]

crates/core/src/ranking/bm25.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,21 @@ use dashmap::DashMap;
22
use rayon::iter::{ParallelBridge, ParallelIterator};
33

44
use crate::{
5-
error::RankingError,
65
index::{DocId, PostingList, RankedIndexReader, Term},
76
query::{AnalyzedQuery, QueryTerm},
87
ranking::{scorer::Scorer, utils::idf},
98
};
109

11-
#[derive(serde::Deserialize, Debug, Clone)]
10+
#[derive(Debug, Clone)]
1211
pub struct BM25HyperParams {
1312
pub k1: f64,
1413
pub b: f64,
1514
}
1615

17-
pub fn get_configuration() -> Result<BM25HyperParams, RankingError> {
18-
let base_path = std::env::current_dir().map_err(RankingError::CurrentDir)?;
19-
let configuration_directory = base_path.join("configuration");
20-
21-
let settings = config::Config::builder()
22-
.add_source(config::File::from(configuration_directory.join("bm25.yml")))
23-
.build()?;
24-
25-
Ok(settings.try_deserialize::<BM25HyperParams>()?)
16+
impl Default for BM25HyperParams {
17+
fn default() -> Self {
18+
Self { k1: 1.2, b: 0.75 }
19+
}
2620
}
2721

2822
pub struct BM25 {

crates/core/src/ranking/bm25f.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use dashmap::DashMap;
44
use rayon::iter::{ParallelBridge, ParallelIterator};
55

66
use crate::{
7-
error::RankingError,
87
index::{DocId, DocumentField, PostingList, RankedIndexReader, Term, TermDocument},
98
query::{AnalyzedQuery, QueryIntent, QueryTerm},
109
ranking::{scorer::Scorer, utils::idf},
@@ -106,10 +105,6 @@ impl BM25FHyperParams {
106105
}
107106
}
108107

109-
pub fn get_configuration() -> Result<BM25FHyperParams, RankingError> {
110-
Ok(BM25FHyperParams::code_search_defaults())
111-
}
112-
113108
pub struct BM25F {
114109
pub hyper_params: BM25FHyperParams,
115110
}

crates/core/src/ranking/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub mod scorer;
1010
pub mod tf_idf;
1111
mod utils;
1212

13-
pub use bm25::{BM25, BM25HyperParams, get_configuration};
13+
pub use bm25::{BM25, BM25HyperParams};
1414
pub use bm25f::{BM25F, BM25FHyperParams};
1515
pub use cosine_similarity::CosineSimilarity;
1616
pub use explanation::{

crates/core/src/ranking/scorer.rs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
BM25, BM25F, BM25FHyperParams, BM25HyperParams, CosineSimilarity, FieldContribution,
1111
ProximityConfig, QueryLikelihood, QueryLikelihoodParams, ScoreExplanation,
1212
ScoreWithExplanation, ScoredWithExplanations, StaticQualityContribution, TFIDF,
13-
TermExplanation, get_configuration, idf,
13+
TermExplanation, idf,
1414
},
1515
};
1616

@@ -518,22 +518,12 @@ impl FromStr for RankingAlgo {
518518
fn from_str(s: &str) -> Result<Self, Self::Err> {
519519
match s {
520520
"cosim" => Ok(RankingAlgo::CosineSimilarity),
521-
"bm25" => {
522-
let hyper_params =
523-
get_configuration().map_err(|e| format!("failed to load BM25 config: {e}"))?;
524-
525-
Ok(RankingAlgo::BM25(hyper_params))
526-
}
521+
"bm25" => Ok(RankingAlgo::BM25(BM25HyperParams::default())),
527522
"bm25f" => Ok(RankingAlgo::BM25F(BM25FHyperParams::code_search_defaults())),
528-
"bm25-proximity" | "proximity" => {
529-
let hyper_params =
530-
get_configuration().map_err(|e| format!("failed to load BM25 config: {e}"))?;
531-
532-
Ok(RankingAlgo::BM25Proximity(
533-
hyper_params,
534-
ProximityConfig::default(),
535-
))
536-
}
523+
"bm25-proximity" | "proximity" => Ok(RankingAlgo::BM25Proximity(
524+
BM25HyperParams::default(),
525+
ProximityConfig::default(),
526+
)),
537527
"ql" | "ql-dirichlet" | "query-likelihood" => Ok(RankingAlgo::QueryLikelihood(
538528
QueryLikelihoodParams::dirichlet_defaults(),
539529
)),

data/eval/repo_reaper.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,20 +197,20 @@
197197
]
198198
},
199199
{
200-
"query": "bm25 hyperparameters load configuration bm25 yml",
201-
"narrative": "Find where BM25 k1 and b are loaded from configuration.",
200+
"query": "bm25 hyperparameters default k1 b",
201+
"narrative": "Find where BM25 k1 and b defaults are defined.",
202202
"query_shape": "configuration",
203203
"results": [
204204
{
205205
"path": "core/src/ranking/bm25.rs",
206-
"content": "get_configuration reads configuration/bm25.yml and deserializes BM25HyperParams.",
206+
"content": "BM25HyperParams defines the built-in k1 and b defaults.",
207207
"relevant": true,
208208
"rank": 1,
209209
"evidence": [
210210
{
211211
"start_line": 13,
212-
"end_line": 28,
213-
"snippet": "pub struct BM25HyperParams"
212+
"end_line": 21,
213+
"snippet": "impl Default for BM25HyperParams"
214214
}
215215
]
216216
}

0 commit comments

Comments
 (0)