Skip to content

Commit 479eb26

Browse files
Updated benchmark default configuration and improved instructions
* Updated benchmark default configuration and improved instructions * Updated benchmark default configuration and improved instructions
1 parent a901045 commit 479eb26

6 files changed

Lines changed: 132 additions & 39 deletions

File tree

benchmarks/benchmark.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
SimilarityMetricType,
9090
)
9191
from vcache.vcache_core.cache.eviction_policy.eviction_policy import EvictionPolicy
92-
from vcache.vcache_core.cache.eviction_policy.strategies.scu import SCUEvictionPolicy
92+
from vcache.vcache_core.cache.eviction_policy.strategies.mru import MRUEvictionPolicy
9393
from vcache.vcache_core.similarity_evaluator import SimilarityEvaluator
9494
from vcache.vcache_core.similarity_evaluator.strategies.benchmark_comparison import (
9595
BenchmarkComparisonSimilarityEvaluator,
@@ -186,7 +186,7 @@ class Baseline(Enum):
186186
187187
Each baseline represents a different caching strategy:
188188
- GPTCache: Static threshold-based caching
189-
- VCacheLocal: vCache with local threshold adaptation
189+
- VCacheLocal: vCache with local threshold adaptation (original vCache version)
190190
- VCacheGlobal: vCache with global threshold adaptation
191191
- BerkeleyEmbedding: Fine-tuned embeddings with static threshold
192192
- VCacheBerkeleyEmbedding: vCache with fine-tuned embeddings
@@ -213,8 +213,11 @@ class Dataset(Enum):
213213
(with relative paths from benchmarks/your_datasets/).
214214
"""
215215

216+
# HuggingFace: https://huggingface.co/datasets/vCache/SemBenchmarkClassification
216217
SEM_BENCHMARK_CLASSIFICATION = "vCache/SemBenchmarkClassification"
218+
# HuggingFace: https://huggingface.co/datasets/vCache/SemBenchmarkLmArena
217219
SEM_BENCHMARK_ARENA = "vCache/SemBenchmarkLmArena"
220+
# HuggingFace: https://huggingface.co/datasets/vCache/SemBenchmarkSearchQueries
218221
SEM_BENCHMARK_SEARCH_QUERIES = "vCache/SemBenchmarkSearchQueries"
219222
# Example for custom dataset. The path is relative to 'benchmarks/your_datasets/'
220223
CUSTOM_EXAMPLE = "your_datasets/your_custom_dataset.parquet"
@@ -235,7 +238,7 @@ class GeneratePlotsOnly(Enum):
235238
### Benchmark Config ###################################################################################################
236239
########################################################################################################################
237240

238-
CONFIDENCE_INTERVALS_ITERATIONS: int = 1
241+
CONFIDENCE_INTERVALS_ITERATIONS: int = 3
239242
DISABLE_PROGRESS_BAR: bool = False
240243
KEEP_SPLIT: int = 100
241244
MAX_VECTOR_DB_CAPACITY: int = 150000
@@ -252,33 +255,37 @@ class GeneratePlotsOnly(Enum):
252255
int,
253256
]
254257
] = [
258+
# vCache Paper: Figure 4 and 5 (top row)
255259
(
256260
EmbeddingModel.E5_LARGE_V2,
257261
LargeLanguageModel.GPT_4O_MINI,
258262
Dataset.SEM_BENCHMARK_ARENA,
259263
GeneratePlotsOnly.NO,
260264
BenchmarkComparisonSimilarityEvaluator(),
261-
SCUEvictionPolicy(max_size=100000, watermark=0.99, eviction_percentage=0.1),
265+
MRUEvictionPolicy(max_size=100000, watermark=0.99, eviction_percentage=0.1),
262266
60000,
263267
),
268+
# vCache Paper: Figure 4 and 5 (bottom row)
264269
(
265270
EmbeddingModel.GTE,
266271
LargeLanguageModel.LLAMA_3_8B,
267-
Dataset.SEM_BENCHMARK_ARENA,
272+
Dataset.SEM_BENCHMARK_CLASSIFICATION,
268273
GeneratePlotsOnly.NO,
269274
StringComparisonSimilarityEvaluator(),
270-
SCUEvictionPolicy(max_size=100000, watermark=0.99, eviction_percentage=0.1),
275+
MRUEvictionPolicy(max_size=100000, watermark=0.99, eviction_percentage=0.1),
271276
45000,
272277
),
278+
# vCache Paper: Figure 6 and 7
273279
(
274280
EmbeddingModel.GTE,
275281
LargeLanguageModel.LLAMA_3_8B,
276282
Dataset.SEM_BENCHMARK_SEARCH_QUERIES,
277283
GeneratePlotsOnly.NO,
278284
BenchmarkComparisonSimilarityEvaluator(),
279-
SCUEvictionPolicy(max_size=160000, watermark=0.99, eviction_percentage=0.1),
285+
MRUEvictionPolicy(max_size=160000, watermark=0.99, eviction_percentage=0.1),
280286
150000,
281287
),
288+
# Custom Dataset
282289
(
283290
EmbeddingModel.OPENAI_TEXT_EMBEDDING_SMALL,
284291
LargeLanguageModel.GPT_4_1,
@@ -289,7 +296,7 @@ class GeneratePlotsOnly(Enum):
289296
model_name="gpt-4.1-nano-2025-04-14", temperature=0.0
290297
)
291298
),
292-
SCUEvictionPolicy(max_size=2000, watermark=0.99, eviction_percentage=0.1),
299+
MRUEvictionPolicy(max_size=2000, watermark=0.99, eviction_percentage=0.1),
293300
50,
294301
),
295302
]

vcache/vcache_core/cache/eviction_policy/strategies/fifo.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,33 @@
88

99

1010
class FIFOEvictionPolicy(EvictionPolicy):
11-
"""
12-
Implements a First-In, First-Out (FIFO) eviction policy.
11+
def __init__(
12+
self, max_size: int, watermark: float = 0.95, eviction_percentage: float = 0.1
13+
):
14+
"""
15+
Implements a First-In, First-Out (FIFO) eviction policy.
16+
17+
This policy evicts items in the order they were added to the cache.
18+
The eviction process is triggered when the number of items in the cache
19+
exceeds a "high-watermark" threshold, which is a percentage of the
20+
absolute `max_size`. Once triggered, the policy will evict a number
21+
of items equivalent to `eviction_percentage` of the `max_size`.
22+
23+
Example:
24+
With `max_size=1000`, `watermark=0.9`, and `eviction_percentage=0.2`,
25+
eviction starts when the cache size grows beyond 900 items. The
26+
policy will then remove 200 items (0.2 * 1000).
1327
14-
This policy evicts items in the order they were added to the cache.
15-
"""
28+
Args:
29+
max_size: The absolute maximum number of items the cache can hold.
30+
watermark: The percentage of `max_size` that triggers eviction.
31+
eviction_percentage: The percentage of `max_size` to evict.
32+
"""
33+
super().__init__(
34+
max_size=max_size,
35+
watermark=watermark,
36+
eviction_percentage=eviction_percentage,
37+
)
1638

1739
def update_eviction_metadata(self, metadata: EmbeddingMetadataObj) -> None:
1840
"""This method is not used in the FIFO policy."""

vcache/vcache_core/cache/eviction_policy/strategies/lru.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,35 @@
99

1010

1111
class LRUEvictionPolicy(EvictionPolicy):
12-
"""
13-
Implements a Least Recently Used (LRU) eviction policy.
12+
_MIN_DATETIME: datetime = datetime.min.replace(tzinfo=timezone.utc)
13+
14+
def __init__(
15+
self, max_size: int, watermark: float = 0.95, eviction_percentage: float = 0.1
16+
):
17+
"""
18+
Implements a Least Recently Used (LRU) eviction policy.
1419
15-
This policy evicts items that have not been accessed for the longest time.
16-
"""
20+
This policy evicts items that have not been accessed for the longest time.
21+
The eviction process is triggered when the number of items in the cache
22+
exceeds a "high-watermark" threshold, which is a percentage of the
23+
absolute `max_size`. Once triggered, the policy will evict a number
24+
of items equivalent to `eviction_percentage` of the `max_size`.
1725
18-
_MIN_DATETIME: datetime = datetime.min.replace(tzinfo=timezone.utc)
26+
Example:
27+
With `max_size=1000`, `watermark=0.9`, and `eviction_percentage=0.2`,
28+
eviction starts when the cache size grows beyond 900 items. The
29+
policy will then remove 200 items (0.2 * 1000).
30+
31+
Args:
32+
max_size: The absolute maximum number of items the cache can hold.
33+
watermark: The percentage of `max_size` that triggers eviction.
34+
eviction_percentage: The percentage of `max_size` to evict.
35+
"""
36+
super().__init__(
37+
max_size=max_size,
38+
watermark=watermark,
39+
eviction_percentage=eviction_percentage,
40+
)
1941

2042
def update_eviction_metadata(self, metadata: EmbeddingMetadataObj) -> None:
2143
"""Updates the metadata object's last-accessed timestamp.

vcache/vcache_core/cache/eviction_policy/strategies/mru.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,36 @@
99

1010

1111
class MRUEvictionPolicy(EvictionPolicy):
12-
"""
13-
Implements a Most Recently Used (MRU) eviction policy.
12+
_MIN_DATETIME: datetime = datetime.min.replace(tzinfo=timezone.utc)
13+
14+
def __init__(
15+
self, max_size: int, watermark: float = 0.95, eviction_percentage: float = 0.1
16+
):
17+
"""
18+
Implements a Most Recently Used (MRU) eviction policy.
1419
15-
This policy evicts items that have been accessed most recently. This can be
16-
useful in scenarios where older items are more likely to be re-accessed.
17-
"""
20+
This policy evicts items that have been accessed most recently. This can be
21+
useful in scenarios where older items are more likely to be re-accessed.
22+
The eviction process is triggered when the number of items in the cache
23+
exceeds a "high-watermark" threshold, which is a percentage of the
24+
absolute `max_size`. Once triggered, the policy will evict a number
25+
of items equivalent to `eviction_percentage` of the `max_size`.
1826
19-
_MIN_DATETIME: datetime = datetime.min.replace(tzinfo=timezone.utc)
27+
Example:
28+
With `max_size=1000`, `watermark=0.9`, and `eviction_percentage=0.2`,
29+
eviction starts when the cache size grows beyond 900 items. The
30+
policy will then remove 200 items (0.2 * 1000).
31+
32+
Args:
33+
max_size: The absolute maximum number of items the cache can hold.
34+
watermark: The percentage of `max_size` that triggers eviction.
35+
eviction_percentage: The percentage of `max_size` to evict.
36+
"""
37+
super().__init__(
38+
max_size=max_size,
39+
watermark=watermark,
40+
eviction_percentage=eviction_percentage,
41+
)
2042

2143
def update_eviction_metadata(self, metadata: EmbeddingMetadataObj) -> None:
2244
"""Updates the metadata object's last-accessed timestamp.

vcache/vcache_core/cache/eviction_policy/strategies/no_eviction.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@
1010

1111

1212
class NoEvictionPolicy(EvictionPolicy):
13-
"""
14-
A policy that represents the absence of an eviction strategy.
15-
16-
This policy never flags the cache as ready for eviction and never selects
17-
any items to be removed. It is suitable for caches that are not size-limited
18-
or for testing purposes.
19-
"""
20-
2113
def __init__(self):
22-
"""Initializes the NoEvictionPolicy."""
14+
"""
15+
A policy that represents the absence of an eviction strategy.
16+
17+
This policy never flags the cache as ready for eviction and never selects
18+
any items to be removed. It is suitable for caches that are not size-limited
19+
or for testing purposes.
20+
"""
2321
# Intentionally override the parent __init__ to ignore sizing parameters.
2422
pass
2523

vcache/vcache_core/cache/eviction_policy/strategies/scu.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,37 @@
99

1010

1111
class SCUEvictionPolicy(EvictionPolicy):
12-
"""
13-
Implements the Sky Confident Utility (SCU) eviction policy.
12+
def __init__(
13+
self, max_size: int, watermark: float = 0.95, eviction_percentage: float = 0.1
14+
):
15+
"""
16+
Implements the Sky Confident Utility (SCU) eviction policy.
17+
18+
IMPORTANT: This policy can only be used with the VCacheLocal policy.
19+
20+
This policy uses a Pareto-optimal, distance-from-ideal framework to select
21+
victims for eviction, balancing an item's generality and the statistical
22+
confidence in its performance.
23+
The eviction process is triggered when the number of items in the cache
24+
exceeds a "high-watermark" threshold, which is a percentage of the
25+
absolute `max_size`. Once triggered, the policy will evict a number
26+
of items equivalent to `eviction_percentage` of the `max_size`.
1427
15-
IMPORTANT: This policy can only be used with the VerifiedDecisionPolicy.
28+
Example:
29+
With `max_size=1000`, `watermark=0.9`, and `eviction_percentage=0.2`,
30+
eviction starts when the cache size grows beyond 900 items. The
31+
policy will then remove 200 items (0.2 * 1000).
1632
17-
This policy uses a Pareto-optimal, distance-from-ideal framework to select
18-
victims for eviction, balancing an item's generality and the statistical
19-
confidence in its performance.
20-
"""
33+
Args:
34+
max_size: The absolute maximum number of items the cache can hold.
35+
watermark: The percentage of `max_size` that triggers eviction.
36+
eviction_percentage: The percentage of `max_size` to evict.
37+
"""
38+
super().__init__(
39+
max_size=max_size,
40+
watermark=watermark,
41+
eviction_percentage=eviction_percentage,
42+
)
2143

2244
def update_eviction_metadata(self, metadata: EmbeddingMetadataObj) -> None:
2345
"""This method is not used in the SCU policy."""

0 commit comments

Comments
 (0)