Skip to content

Commit c9357c3

Browse files
committed
Rename LangCacheWrapper to LangCacheSemanticCache
The name "LangCacheWrapper" just doesn't hit as deep. Also, it doesn't follow the same pattern as "SemanticCache," the Redis-based cache in this library. Seeing "Cache" twice feels better than "Wrapper."
1 parent 69407f6 commit c9357c3

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

redisvl/extensions/cache/llm/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
This module provides LLM cache implementations for RedisVL.
55
"""
66

7-
from redisvl.extensions.cache.llm.langcache import LangCacheWrapper
7+
from redisvl.extensions.cache.llm.langcache import LangCacheSemanticCache
88
from redisvl.extensions.cache.llm.schema import (
99
CacheEntry,
1010
CacheHit,
@@ -14,7 +14,7 @@
1414

1515
__all__ = [
1616
"SemanticCache",
17-
"LangCacheWrapper",
17+
"LangCacheSemanticCache",
1818
"CacheEntry",
1919
"CacheHit",
2020
"SemanticCacheIndexSchema",

redisvl/extensions/cache/llm/langcache.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
logger = get_logger(__name__)
1616

1717

18-
class LangCacheWrapper(BaseLLMCache):
18+
class LangCacheSemanticCache(BaseLLMCache):
1919
"""LLM Cache implementation using the LangCache managed service.
2020
2121
This cache uses the LangCache API service for semantic caching of LLM
@@ -24,9 +24,9 @@ class LangCacheWrapper(BaseLLMCache):
2424
Example:
2525
.. code-block:: python
2626
27-
from redisvl.extensions.cache.llm import LangCacheWrapper
27+
from redisvl.extensions.cache.llm import LangCacheSemanticCache
2828
29-
cache = LangCacheWrapper(
29+
cache = LangCacheSemanticCache(
3030
name="my_cache",
3131
server_url="https://api.langcache.com",
3232
cache_id="your-cache-id",
@@ -79,9 +79,9 @@ def __init__(
7979
self._distance_scale = distance_scale
8080

8181
if not cache_id:
82-
raise ValueError("cache_id is required for LangCacheWrapper")
82+
raise ValueError("cache_id is required for LangCacheSemanticCache")
8383
if not api_key:
84-
raise ValueError("api_key is required for LangCacheWrapper")
84+
raise ValueError("api_key is required for LangCacheSemanticCache")
8585

8686
super().__init__(name=name, ttl=ttl, **kwargs)
8787

@@ -117,7 +117,7 @@ def _create_client(self):
117117
from langcache import LangCacheClient
118118
except ImportError as e:
119119
raise ImportError(
120-
"The langcache package is required to use LangCacheWrapper. "
120+
"The langcache package is required to use LangCacheSemanticCache. "
121121
"Install it with: pip install langcache"
122122
) from e
123123

tests/unit/test_langcache_wrapper.py renamed to tests/unit/test_langcache_semantic_cache.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
"""Unit tests for LangCacheWrapper."""
1+
"""Unit tests for LangCacheSemanticCache."""
22

33
import importlib.util
44
from unittest.mock import AsyncMock, MagicMock, patch
55

66
import pytest
77

8-
from redisvl.extensions.cache.llm.langcache import LangCacheWrapper
8+
from redisvl.extensions.cache.llm.langcache import LangCacheSemanticCache
99

1010

1111
@pytest.fixture
1212
def mock_langcache_client():
1313
"""Create a mock LangCache client via the wrapper factory method."""
14-
with patch.object(LangCacheWrapper, "_create_client") as mock_create_client:
14+
with patch.object(LangCacheSemanticCache, "_create_client") as mock_create_client:
1515
mock_client = MagicMock()
1616
mock_create_client.return_value = mock_client
1717

@@ -28,13 +28,13 @@ def mock_langcache_client():
2828
importlib.util.find_spec("langcache") is None,
2929
reason="langcache package not installed",
3030
)
31-
class TestLangCacheWrapper:
32-
"""Test suite for LangCacheWrapper."""
31+
class TestLangCacheSemanticCache:
32+
"""Test suite for LangCacheSemanticCache."""
3333

3434
def test_init_requires_cache_id(self):
3535
"""Test that cache_id is required."""
3636
with pytest.raises(ValueError, match="cache_id is required"):
37-
LangCacheWrapper(
37+
LangCacheSemanticCache(
3838
name="test",
3939
server_url="https://api.example.com",
4040
cache_id="",
@@ -44,7 +44,7 @@ def test_init_requires_cache_id(self):
4444
def test_init_requires_api_key(self):
4545
"""Test that api_key is required."""
4646
with pytest.raises(ValueError, match="api_key is required"):
47-
LangCacheWrapper(
47+
LangCacheSemanticCache(
4848
name="test",
4949
server_url="https://api.example.com",
5050
cache_id="test-cache",
@@ -54,7 +54,7 @@ def test_init_requires_api_key(self):
5454
def test_init_requires_at_least_one_search_strategy(self):
5555
"""Test that at least one search strategy must be enabled."""
5656
with pytest.raises(ValueError, match="At least one of use_exact_search"):
57-
LangCacheWrapper(
57+
LangCacheSemanticCache(
5858
name="test",
5959
server_url="https://api.example.com",
6060
cache_id="test-cache",
@@ -67,7 +67,7 @@ def test_init_success(self, mock_langcache_client):
6767
"""Test successful initialization."""
6868
mock_create_client, _ = mock_langcache_client
6969

70-
cache = LangCacheWrapper(
70+
cache = LangCacheSemanticCache(
7171
name="test_cache",
7272
server_url="https://api.example.com",
7373
cache_id="test-cache-id",
@@ -93,7 +93,7 @@ def test_store(self, mock_langcache_client):
9393
mock_response.entry_id = "entry-123"
9494
mock_client.set.return_value = mock_response
9595

96-
cache = LangCacheWrapper(
96+
cache = LangCacheSemanticCache(
9797
name="test",
9898
server_url="https://api.example.com",
9999
cache_id="test-cache",
@@ -123,7 +123,7 @@ async def test_astore(self, mock_langcache_client):
123123
mock_response.entry_id = "entry-456"
124124
mock_client.set_async = AsyncMock(return_value=mock_response)
125125

126-
cache = LangCacheWrapper(
126+
cache = LangCacheSemanticCache(
127127
name="test",
128128
server_url="https://api.example.com",
129129
cache_id="test-cache",
@@ -158,7 +158,7 @@ def test_check(self, mock_langcache_client):
158158
mock_response.data = [mock_entry]
159159
mock_client.search.return_value = mock_response
160160

161-
cache = LangCacheWrapper(
161+
cache = LangCacheSemanticCache(
162162
name="test",
163163
server_url="https://api.example.com",
164164
cache_id="test-cache",
@@ -198,7 +198,7 @@ async def test_acheck(self, mock_langcache_client):
198198
mock_response.data = [mock_entry]
199199
mock_client.search_async = AsyncMock(return_value=mock_response)
200200

201-
cache = LangCacheWrapper(
201+
cache = LangCacheSemanticCache(
202202
name="test",
203203
server_url="https://api.example.com",
204204
cache_id="test-cache",
@@ -232,7 +232,7 @@ def test_check_with_distance_threshold(self, mock_langcache_client):
232232
mock_response.data = [mock_entry]
233233
mock_client.search.return_value = mock_response
234234

235-
cache = LangCacheWrapper(
235+
cache = LangCacheSemanticCache(
236236
name="test",
237237
server_url="https://api.example.com",
238238
cache_id="test-cache",
@@ -268,7 +268,7 @@ def test_check_with_attributes(self, mock_langcache_client):
268268
mock_response.data = [mock_entry]
269269
mock_client.search.return_value = mock_response
270270

271-
cache = LangCacheWrapper(
271+
cache = LangCacheSemanticCache(
272272
name="test",
273273
server_url="https://api.example.com",
274274
cache_id="test-cache",
@@ -296,7 +296,7 @@ def test_delete(self, mock_langcache_client):
296296
"""Test deleting the entire cache."""
297297
_, mock_client = mock_langcache_client
298298

299-
cache = LangCacheWrapper(
299+
cache = LangCacheSemanticCache(
300300
name="test",
301301
server_url="https://api.example.com",
302302
cache_id="test-cache",
@@ -314,7 +314,7 @@ async def test_adelete(self, mock_langcache_client):
314314

315315
mock_client.delete_query_async = AsyncMock()
316316

317-
cache = LangCacheWrapper(
317+
cache = LangCacheSemanticCache(
318318
name="test",
319319
server_url="https://api.example.com",
320320
cache_id="test-cache",
@@ -329,7 +329,7 @@ def test_delete_by_id(self, mock_langcache_client):
329329
"""Test deleting a single entry by ID."""
330330
_, mock_client = mock_langcache_client
331331

332-
cache = LangCacheWrapper(
332+
cache = LangCacheSemanticCache(
333333
name="test",
334334
server_url="https://api.example.com",
335335
cache_id="test-cache",
@@ -342,7 +342,7 @@ def test_delete_by_id(self, mock_langcache_client):
342342

343343
def test_update_not_supported(self, mock_langcache_client):
344344
"""Test that update raises NotImplementedError."""
345-
cache = LangCacheWrapper(
345+
cache = LangCacheSemanticCache(
346346
name="test",
347347
server_url="https://api.example.com",
348348
cache_id="test-cache",
@@ -355,7 +355,7 @@ def test_update_not_supported(self, mock_langcache_client):
355355
@pytest.mark.asyncio
356356
async def test_aupdate_not_supported(self, mock_langcache_client):
357357
"""Test that async update raises NotImplementedError."""
358-
cache = LangCacheWrapper(
358+
cache = LangCacheSemanticCache(
359359
name="test",
360360
server_url="https://api.example.com",
361361
cache_id="test-cache",
@@ -373,7 +373,7 @@ def test_import_error_when_langcache_not_installed():
373373
pytest.skip("langcache package is installed")
374374

375375
with pytest.raises(ImportError, match="langcache package is required"):
376-
LangCacheWrapper(
376+
LangCacheSemanticCache(
377377
name="test",
378378
server_url="https://api.example.com",
379379
cache_id="test-cache",

0 commit comments

Comments
 (0)