Skip to content

Commit 2fa2b00

Browse files
committed
add set threshold
1 parent 599be55 commit 2fa2b00

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "semantic-router"
3-
version = "0.0.23"
3+
version = "0.0.24"
44
description = "Super fast semantic router for AI decision making"
55
authors = [
66
"James Briggs <james@aurelio.ai>",

semantic_router/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
__all__ = ["RouteLayer", "HybridRouteLayer", "Route", "LayerConfig"]
66

7-
__version__ = "0.0.23"
7+
__version__ = "0.0.24"

semantic_router/splitters/rolling_window.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def __init__(
1414
self,
1515
encoder: BaseEncoder,
1616
threshold_adjustment=0.01,
17+
dynamic_threshold: bool = True,
1718
window_size=5,
1819
min_split_tokens=100,
1920
max_split_tokens=300,
@@ -25,6 +26,7 @@ def __init__(
2526
self.calculated_threshold: float
2627
self.encoder = encoder
2728
self.threshold_adjustment = threshold_adjustment
29+
self.dynamic_threshold = dynamic_threshold
2830
self.window_size = window_size
2931
self.plot_splits = plot_splits
3032
self.min_split_tokens = min_split_tokens
@@ -321,7 +323,10 @@ def __call__(self, docs: List[str]) -> List[DocumentSplit]:
321323
)
322324
docs = split_to_sentences(docs[0])
323325
encoded_docs = self.encode_documents(docs)
324-
self.find_optimal_threshold(docs, encoded_docs)
326+
if self.dynamic_threshold:
327+
self.find_optimal_threshold(docs, encoded_docs)
328+
else:
329+
self.calculated_threshold = self.encoder.score_threshold
325330
similarities = self.calculate_similarity_scores(encoded_docs)
326331
split_indices = self.find_split_indices(similarities=similarities)
327332
splits = self.split_documents(docs, split_indices, similarities)

0 commit comments

Comments
 (0)