Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
1e52e75
Updated function name
luis-gasparschroeder Apr 24, 2025
5470f97
Simplified benchmark implementation
luis-gasparschroeder Apr 24, 2025
a78b2bb
Refactoring benchmark
luis-gasparschroeder Apr 25, 2025
f5cad74
Continue refactoring benchmark
luis-gasparschroeder Apr 25, 2025
671268d
Continue refactoring benchmark
luis-gasparschroeder Apr 25, 2025
8edeeb7
Fixed indexing
luis-gasparschroeder Apr 25, 2025
a985b21
Improved plots
luis-gasparschroeder Apr 25, 2025
3f95236
Fixed indexing
luis-gasparschroeder Apr 25, 2025
2b013d6
Fixed function header
luis-gasparschroeder Apr 25, 2025
a8497db
Added new metrics
luis-gasparschroeder Apr 25, 2025
7d025d7
Unified common stats functions
luis-gasparschroeder Apr 25, 2025
bd2c900
Unified common stats functions in plot functions
luis-gasparschroeder Apr 25, 2025
a5e462d
Removed legacy code
luis-gasparschroeder Apr 25, 2025
8ebfe3f
Fix div by zero
luis-gasparschroeder Apr 25, 2025
60707f5
Fixed tp,fp,tn,fn computation and removed async
luis-gasparschroeder Apr 26, 2025
3ab40d5
Added cache hit counter
luis-gasparschroeder Apr 26, 2025
b7e3389
Optimizations and optimizations
luis-gasparschroeder Apr 27, 2025
d0ea8e7
Included fisher conf approx
luis-gasparschroeder Apr 28, 2025
077b061
Benchmark unification
luis-gasparschroeder Apr 28, 2025
5eb7dad
Merged
luis-gasparschroeder Apr 28, 2025
a955018
Simplified
luis-gasparschroeder Apr 28, 2025
50f1779
Implemented bootstrap-based variance
luis-gasparschroeder Apr 29, 2025
cb35c07
Added delta method
luis-gasparschroeder Apr 29, 2025
2174ae5
Added variance map and delta
luis-gasparschroeder Apr 29, 2025
046e4c1
Works
luis-gasparschroeder Apr 29, 2025
0bf72d5
Cleaned code
luis-gasparschroeder Apr 29, 2025
8a2db86
Added global logic
luis-gasparschroeder Apr 30, 2025
a89d86b
Added path checks to avoid re-computation
luis-gasparschroeder Apr 30, 2025
0b6c4aa
Implemented plots
luis-gasparschroeder Apr 30, 2025
05d2b4c
Fixed epsilon grid
luis-gasparschroeder May 1, 2025
24a54ec
Cleaned code
luis-gasparschroeder May 1, 2025
38307e7
Updated plots
luis-gasparschroeder May 1, 2025
39440b7
Merge branch 'master' into lgs/benchmarking-baselines
luis-gasparschroeder May 5, 2025
dbf346d
Added baseline
luis-gasparschroeder May 5, 2025
6f6c9ca
Implemented benchmark logic
luis-gasparschroeder May 5, 2025
3158f88
Simplified benchmark
luis-gasparschroeder May 5, 2025
a55e288
Simplified benchmark
luis-gasparschroeder May 5, 2025
ff8964b
Fixed linting errors
luis-gasparschroeder May 5, 2025
e994c58
Fixed duplicate
luis-gasparschroeder May 5, 2025
69db521
Updated lock file
luis-gasparschroeder May 5, 2025
fd3be7a
Added comments
luis-gasparschroeder May 5, 2025
29eafb7
Initial IID implementation
luis-gasparschroeder May 6, 2025
8b4c953
Initial IID implementation
luis-gasparschroeder May 6, 2025
b424b58
Updated conf interval iter
luis-gasparschroeder May 6, 2025
7b93efc
Merge branch 'master' into lgs/iid-baseline
luis-gasparschroeder May 7, 2025
727f596
Graph update
luis-gasparschroeder May 9, 2025
caf2da9
Fixed linting errors
luis-gasparschroeder May 9, 2025
4636375
Fixed file format
luis-gasparschroeder May 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ temp/*
*.log
bin/*
.venv/
.env
.env
*.png
81 changes: 54 additions & 27 deletions benchmarks/_plotter_combined.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,14 @@ def generate_combined_plots(
vectorq_global_data_frames: Dict[float, pd.DataFrame] = {}
for global_file_path in vectorq_global_files:
with open(global_file_path, "r") as f:
data: Any = json.load(f)
dataframe, _ = convert_to_dataframe_from_json_file(data)
delta: float = data["config"]["delta"]
vectorq_global_data_frames[delta] = dataframe
try:
data: Any = json.load(f)
dataframe, _ = convert_to_dataframe_from_json_file(data)
delta: float = data["config"]["delta"]
vectorq_global_data_frames[delta] = dataframe
except Exception as e:
print(f"Error loading {global_file_path}: {e}")
continue

__plot_roc(
static_data_frames=static_data_frames,
Expand Down Expand Up @@ -184,14 +188,15 @@ def __plot_roc(
static_tpr_values,
"o-",
color="blue",
linewidth=2,
linewidth=3,
label="GPTCache",
markersize=8,
markersize=10,
)

for i, threshold in enumerate(static_thresholds):
if i == 0 or i == len(static_thresholds) - 1:
label = f"{threshold:.2f}"
# label = f"{threshold:.2f}"
label = None
else:
label = None
plt.annotate(
Expand Down Expand Up @@ -226,14 +231,15 @@ def __plot_roc(
vectorq_local_tpr_values,
"o-",
color="green",
linewidth=2,
label="VectorQ (Local)",
markersize=8,
linewidth=3,
label="vCache",
markersize=10,
)

for i, _ in enumerate(vectorq_local_tpr_values):
if i == 0 or i == len(vectorq_local_deltas) - 1:
label = f"{vectorq_local_deltas[i]:.2f}"
# label = f"{vectorq_local_deltas[i]:.2f}"
label = None
else:
label = None
plt.annotate(
Expand Down Expand Up @@ -265,14 +271,15 @@ def __plot_roc(
vectorq_global_tpr_values,
"o-",
color="red",
linewidth=2,
label="VectorQ (Global)",
markersize=8,
linewidth=3,
label="vCache (Ablation)",
markersize=10,
)

for i, delta in enumerate(vectorq_global_deltas):
if i == 0 or i == len(vectorq_global_deltas) - 1:
label = f"{delta:.2f}"
# label = f"{delta:.2f}"
label = None
else:
label = None
plt.annotate(
Expand All @@ -294,9 +301,17 @@ def __plot_roc(

plt.xlim(0, 1)
plt.ylim(0, 1)
yticks = plt.yticks()[0]
if yticks[0] == 0.0:
plt.yticks(yticks[1:])

plt.gca().spines["top"].set_linewidth(1)
plt.gca().spines["right"].set_linewidth(1)
plt.gca().spines["bottom"].set_linewidth(1)
plt.gca().spines["left"].set_linewidth(1)

filename = results_dir + f"/roc_{timestamp}.pdf"
plt.savefig(filename, format="pdf", bbox_inches="tight")
plt.savefig(filename, format="pdf", transparent=True)
plt.close()


Expand Down Expand Up @@ -618,14 +633,15 @@ def __plot_cache_hit_vs_error_rate(
static_cache_hit_rates,
"o-",
color="blue",
linewidth=2,
linewidth=3,
label="GPTCache",
markersize=8,
markersize=10,
)

for i, threshold in enumerate(static_thresholds):
if i == 0 or i == len(static_thresholds) - 2:
label = f"{threshold:.2f}"
# label = f"{threshold:.2f}"
label = None
else:
label = None
plt.annotate(
Expand Down Expand Up @@ -662,17 +678,18 @@ def __plot_cache_hit_vs_error_rate(
vectorq_local_cache_hit_rates,
"o-",
color="green",
linewidth=2,
label="VectorQ (Local)",
markersize=8,
linewidth=3,
label="vCache",
markersize=10,
)

for i, _ in enumerate(vectorq_local_error_rates):
if i == 0:
continue

if i == 0 or i == len(vectorq_local_deltas) - 1:
label = f"{vectorq_local_deltas[i]:.2f}"
# label = f"{vectorq_local_deltas[i]:.2f}"
label = None
else:
label = None
plt.annotate(
Expand Down Expand Up @@ -705,14 +722,15 @@ def __plot_cache_hit_vs_error_rate(
vectorq_global_cache_hit_rates,
"o-",
color="red",
linewidth=2,
label="VectorQ (Global)",
markersize=8,
linewidth=3,
label="vCache (Ablation)",
markersize=10,
)

for i, delta in enumerate(vectorq_global_deltas):
if i == 0 or i == len(vectorq_global_deltas) - 1:
label = f"{delta:.2f}"
# label = f"{delta:.2f}"
label = None
else:
label = None
plt.annotate(
Expand All @@ -729,8 +747,17 @@ def __plot_cache_hit_vs_error_rate(
plt.grid(True, linestyle="--", alpha=0.7)
plt.legend(loc="best", fontsize=font_size - 2)
plt.tick_params(axis="both", labelsize=font_size - 2)

plt.xlim(0, 0.3)
plt.ylim(0, 1)
yticks = plt.yticks()[0]
if yticks[0] == 0.0:
plt.yticks(yticks[1:])

plt.gca().spines["top"].set_linewidth(1)
plt.gca().spines["right"].set_linewidth(1)
plt.gca().spines["bottom"].set_linewidth(1)
plt.gca().spines["left"].set_linewidth(1)

filename = results_dir + f"/cache_hit_vs_error_rate_{timestamp}.pdf"
plt.savefig(filename, format="pdf", bbox_inches="tight")
Expand Down
53 changes: 46 additions & 7 deletions benchmarks/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
from vectorq.vectorq_policy.strategies.dynamic_local_threshold import (
DynamicLocalThresholdPolicy,
)
from vectorq.vectorq_policy.strategies.iid_local_threshold import (
IIDLocalThresholdPolicy,
)
from vectorq.vectorq_policy.strategies.static_global_threshold import (
StaticGlobalThresholdPolicy,
)
Expand All @@ -64,7 +67,7 @@
########################################################################################################################

# Benchmark Config
MAX_SAMPLES: int = 5000
MAX_SAMPLES: int = 15000
CONFIDENCE_INTERVALS_ITERATIONS: int = 3
IS_LLM_JUDGE_BENCHMARK: bool = False

Expand Down Expand Up @@ -104,7 +107,7 @@
"ecommerce_dataset.json",
"semantic_prompt_cache_benchmark.json",
]
DATASETS_TO_EXCLUDE: List[str] = [DATASETS[0], DATASETS[2], DATASETS[3]]
DATASETS_TO_EXCLUDE: List[str] = [DATASETS[1], DATASETS[2]]

embedding_models: List[Tuple[str, str, str, int]] = [
EMBEDDING_MODEL_1,
Expand All @@ -123,9 +126,16 @@

# VectorQ Config
MAX_VECTOR_DB_CAPACITY: int = 100000
PLOT_FONT_SIZE: int = 24

SYSTEM_TYPES: List[str] = ["static", "dynamic_local", "dynamic_global", "all"]
PLOT_FONT_SIZE: int = 32

SYSTEM_TYPES: List[str] = [
"static",
"dynamic_local",
"dynamic_global",
"iid_local",
"all",
"just_plot",
]
SYSTEM_TYPE: str = SYSTEM_TYPES[3]


Expand Down Expand Up @@ -548,7 +558,36 @@ def main():
threshold=-1,
)

# Baseline 3) Static thresholds
# Baseline 3) IID Local thresholds
if SYSTEM_TYPE in ["iid_local", "all"]:
for delta in deltas:
for i in range(0, CONFIDENCE_INTERVALS_ITERATIONS):
path = os.path.join(
results_dir,
dataset,
embedding_model[1],
llm_model[1],
f"iid_local_{delta}_run_{i + 1}",
)
if os.path.exists(path) and os.listdir(path):
continue

logging.info(
f"Using IID local threshold with delta: {delta}. Run {i + 1} of {CONFIDENCE_INTERVALS_ITERATIONS}"
)

__run_baseline(
vectorq_policy=IIDLocalThresholdPolicy(delta=delta),
path=path,
dataset_file=dataset_file,
embedding_model=embedding_model,
llm_model=llm_model,
timestamp=timestamp,
delta=delta,
threshold=-1,
)

# Baseline 4) Static thresholds
if SYSTEM_TYPE in ["static", "all"]:
for threshold in static_thresholds:
path = os.path.join(
Expand Down Expand Up @@ -576,7 +615,7 @@ def main():
threshold=threshold,
)

if SYSTEM_TYPE == "all":
if SYSTEM_TYPE == "all" or SYSTEM_TYPE == "just_plot":
generate_combined_plots(
dataset=dataset,
embedding_model_name=embedding_model[1],
Expand Down
2 changes: 2 additions & 0 deletions vectorq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
from vectorq.vectorq_policy import (
DynamicGlobalThresholdPolicy,
DynamicLocalThresholdPolicy,
IIDLocalThresholdPolicy,
NoCachePolicy,
StaticGlobalThresholdPolicy,
VectorQPolicy,
Expand Down Expand Up @@ -89,4 +90,5 @@
"DynamicGlobalThresholdPolicy",
"StaticGlobalThresholdPolicy",
"NoCachePolicy",
"IIDLocalThresholdPolicy",
]
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ def __init__(
self.t_hat: float = None
self.t_prime: float = None
self.var_t: float = None
self.observations.append((0.0, 0))
self.observations.append((1.0, 1))
self.gamma: float = None
self.t_hat: float = None
##################################################
Expand Down
4 changes: 4 additions & 0 deletions vectorq/vectorq_policy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
from vectorq.vectorq_policy.strategies.dynamic_local_threshold import (
DynamicLocalThresholdPolicy,
)
from vectorq.vectorq_policy.strategies.iid_local_threshold import (
IIDLocalThresholdPolicy,
)
from vectorq.vectorq_policy.strategies.no_cache import NoCachePolicy
from vectorq.vectorq_policy.strategies.static_global_threshold import (
StaticGlobalThresholdPolicy,
Expand All @@ -15,5 +18,6 @@
"StaticGlobalThresholdPolicy",
"DynamicLocalThresholdPolicy",
"DynamicGlobalThresholdPolicy",
"IIDLocalThresholdPolicy",
"NoCachePolicy",
]
4 changes: 2 additions & 2 deletions vectorq/vectorq_policy/strategies/dynamic_global_threshold.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(
Args
delta: float - The delta value to use
"""
self.bayesian = _Bayesian(delta=delta)
self.bayesian = _Algorithm(delta=delta)
self.similarity_evaluator: SimilarityEvaluator = None
self.inference_engine: InferenceEngine = None
self.cache: Cache = None
Expand Down Expand Up @@ -107,7 +107,7 @@ class _Action(Enum):
EXPLOIT = "exploit"


class _Bayesian:
class _Algorithm:
def __init__(self, delta: float):
self.delta: float = delta
self.P_c: float = 1.0 - self.delta
Expand Down
8 changes: 5 additions & 3 deletions vectorq/vectorq_policy/strategies/dynamic_local_threshold.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
EmbeddingMetadataObj,
)
from vectorq.vectorq_core.cache.embedding_store.embedding_store import EmbeddingStore
from vectorq.vectorq_core.similarity_evaluator import SimilarityEvaluator
from vectorq.vectorq_core.similarity_evaluator import (
SimilarityEvaluator,
)
from vectorq.vectorq_policy.vectorq_policy import VectorQPolicy


Expand All @@ -30,7 +32,7 @@ def __init__(self, delta: float = 0.01):
Args
delta: float - The delta value to use
"""
self.bayesian = _Bayesian(delta=delta)
self.bayesian = _Algorithm(delta=delta)
self.similarity_evaluator: SimilarityEvaluator = None
self.inference_engine: InferenceEngine = None
self.cache: Cache = None
Expand Down Expand Up @@ -104,7 +106,7 @@ class _Action(Enum):
EXPLOIT = "exploit"


class _Bayesian:
class _Algorithm:
def __init__(self, delta: float):
self.delta: float = delta
self.P_c: float = 1.0 - self.delta
Expand Down
Loading