SemanticCache.check() unconditionally refreshes TTL on hit (sliding-window with no opt-out)

已关闭
#603 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 5 天内回复

@omribz156 已经在做这个了。

开始于 2026年5月25日。

  • #618 来自 @omribz156 —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
70/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
冷清
技术栈
python, redis

调研方向

从 redisvl/extensions/cache/llm/semantic.py 中 SemanticCache.check() 的第 432 行附近开始,然后阅读周围的 SemanticCache 构造函数以及当前的 TTL 刷新路径。验证所提议的构造函数标志和每次调用的覆盖选项在禁用时仍保持默认行为并允许纯读取;当两种选项都得到支持且不改变现有调用方时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

cache enhancement

Current behavior

SemanticCache.check (redisvl/extensions/cache/llm/semantic.py:432) refreshes the TTL of every matched entry on every hit:

# Refresh TTL on all found keys
for key in redis_keys:
    self.expire(key)

This is a sliding-window TTL: a popular entry effectively lives as long as it keeps getting hit. There is no constructor flag, per-call argument, or per-entry attribute to disable this.

Why this is a problem

Sliding window is the wrong default in any domain where the popularity of an entry correlates with the cost of it being stale:

  • a procedure superseded by a regulatory bulletin that the cache has not yet invalidated
  • a balance-patch-affected gameplay answer in a live-ops surface
  • a pricing or eligibility answer that changed at midnight

In these domains the most-asked question is the most likely to be cached and the most likely to fan out a stale answer. The standard mitigation today — store an absolute expires_at numeric and filter on it at read time — works but requires every customer to discover the pattern independently.

Proposed API

SemanticCache(
    name="cache",
    redis_url=...,
    refresh_ttl_on_hit=True,    # current behavior, default unchanged
)

cache.check(
    prompt=...,
    refresh_ttl=None,           # per-call override
)

refresh_ttl_on_hit=False would make check() a pure read. Customers wanting absolute expiry would set this to False, store a numeric expires_at filterable field, and filter on it.

Backwards compatibility

Default remains True. Existing behavior unchanged. Opt-in behavioral change for customers who need it.

Notes

Surfaced while writing a scoped semantic caching architecture spec; came up repeatedly when stress-testing the design against regulated and fast-mutating domains where sliding-window TTL is actively hostile.

主要语言
Python
星标
433
派生
120
平均合并
8 天 28 分钟
30 天内合并 PR
34

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

redis/redis-vl-python 的其他 Issue

查看 redis/redis-vl-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。