Skip to content

Commit 45e8ac2

Browse files
committed
remove llamastack neural reranker and add unit tests
Signed-off-by: Anxhela Coba <acoba@redhat.com>
1 parent 7ca2038 commit 45e8ac2

3 files changed

Lines changed: 509 additions & 8 deletions

File tree

src/models/config.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,8 +1827,6 @@ class RerankerConfiguration(ConfigurationBase):
18271827
description="Cross-encoder model name for reranking RAG chunks. "
18281828
"Defaults to 'cross-encoder/ms-marco-MiniLM-L6-v2' from sentence-transformers.",
18291829
)
1830-
model_id: str = "meta-llama/llama-cross-encoder-base"
1831-
provider_id: str = "meta-reference"
18321830
top_k_multiplier: float = 2.0 # fetch 2x, rerank, keep top_k
18331831
byok_boost: float = 1.2
18341832
okp_boost: float = 1.0
@@ -1843,8 +1841,6 @@ def mark_as_explicitly_configured(self) -> Self:
18431841
# This allows auto-enabling when user hasn't touched reranker settings
18441842
# Check if any field differs from default values
18451843
default_model = "cross-encoder/ms-marco-MiniLM-L6-v2"
1846-
default_model_id = "meta-llama/llama-cross-encoder-base"
1847-
default_provider_id = "meta-reference"
18481844
default_top_k_multiplier = 2.0
18491845
default_byok_boost = 1.2
18501846
default_okp_boost = 1.0
@@ -1853,17 +1849,13 @@ def mark_as_explicitly_configured(self) -> Self:
18531849
current_values = [
18541850
self.enabled,
18551851
self.model,
1856-
self.model_id,
1857-
self.provider_id,
18581852
self.top_k_multiplier,
18591853
self.byok_boost,
18601854
self.okp_boost,
18611855
]
18621856
default_values = [
18631857
True,
18641858
default_model,
1865-
default_model_id,
1866-
default_provider_id,
18671859
default_top_k_multiplier,
18681860
default_byok_boost,
18691861
default_okp_boost,
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
"""Unit tests for RerankerConfiguration model."""
2+
3+
import pytest
4+
from pydantic import ValidationError
5+
6+
from models.config import RerankerConfiguration
7+
8+
9+
class TestRerankerConfiguration:
10+
"""Tests for RerankerConfiguration model."""
11+
12+
def test_default_values(self) -> None:
13+
"""Test that RerankerConfiguration has correct default values."""
14+
config = RerankerConfiguration()
15+
assert config.enabled is True
16+
assert config.model == "cross-encoder/ms-marco-MiniLM-L6-v2"
17+
assert config.top_k_multiplier == 2.0
18+
assert config.byok_boost == 1.2
19+
assert config.okp_boost == 1.0
20+
21+
def test_custom_model(self) -> None:
22+
"""Test configuration with custom cross-encoder model."""
23+
config = RerankerConfiguration(
24+
model="cross-encoder/ms-marco-TinyBERT-L2-v2"
25+
)
26+
assert config.model == "cross-encoder/ms-marco-TinyBERT-L2-v2"
27+
assert config.enabled is True
28+
29+
def test_disabled_reranker(self) -> None:
30+
"""Test configuration with reranker disabled."""
31+
config = RerankerConfiguration(enabled=False)
32+
assert config.enabled is False
33+
assert config.model == "cross-encoder/ms-marco-MiniLM-L6-v2"
34+
35+
def test_custom_boost_factors(self) -> None:
36+
"""Test configuration with custom boost factors."""
37+
config = RerankerConfiguration(
38+
byok_boost=1.5,
39+
okp_boost=0.8
40+
)
41+
assert config.byok_boost == 1.5
42+
assert config.okp_boost == 0.8
43+
44+
def test_custom_top_k_multiplier(self) -> None:
45+
"""Test configuration with custom top_k_multiplier."""
46+
config = RerankerConfiguration(top_k_multiplier=3.0)
47+
assert config.top_k_multiplier == 3.0
48+
49+
def test_all_custom_values(self) -> None:
50+
"""Test configuration with all custom values."""
51+
config = RerankerConfiguration(
52+
enabled=False,
53+
model="custom-cross-encoder",
54+
top_k_multiplier=1.5,
55+
byok_boost=2.0,
56+
okp_boost=0.5
57+
)
58+
assert config.enabled is False
59+
assert config.model == "custom-cross-encoder"
60+
assert config.top_k_multiplier == 1.5
61+
assert config.byok_boost == 2.0
62+
assert config.okp_boost == 0.5
63+
64+
def test_explicit_configuration_detection(self) -> None:
65+
"""Test that explicitly configured values are detected."""
66+
# Non-default values should mark as explicitly configured
67+
config = RerankerConfiguration(enabled=False)
68+
assert hasattr(config, "_explicitly_configured")
69+
# Note: The actual _explicitly_configured logic is private
70+
# and tested through integration tests
71+
72+
def test_invalid_field_rejected(self) -> None:
73+
"""Test that invalid fields are rejected due to extra='forbid'."""
74+
with pytest.raises(ValidationError):
75+
RerankerConfiguration(invalid_field="value")

0 commit comments

Comments
 (0)