feat(cache): Sprint 29 β streaming response cache with SSE replay (v1.9.0) - #6
Merged
Merged
Conversation
β¦.9.0) Store complete SSE token sequences on /query/stream cache miss; replay at configured inter-chunk timing (replay_delay_ms) on cache hit. The streaming cache is a dedicated SemanticCache instance (no key collisions with the regular query cache) gated behind cache_stream_enabled (K3 off by default). - New module: konjoai/cache/streaming.py StreamChunk, StreamingCacheEntry, StreamingResponseCache, singleton factory - konjoai/api/routes/query.py: streaming cache lookup + chunk recording in query_stream(); replay returns StreamingResponse with cache_hit=True frames - konjoai/config.py: 3 new fields β cache_stream_enabled, cache_stream_replay_delay_ms, cache_stream_max_chunks (all K3/K5/K6 compliant) - konjoai/cache/__init__.py: re-export Sprint 29 public symbols - tests/unit/test_streaming_cache.py: 38 new tests (models, lookup, store, replay, singleton, API route hit/miss/disabled) - Version bump 1.8.0 β 1.9.0 https://claude.ai/code/session_0171rxj96JzbbH6JwuMu2zfx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
konjoai/cache/streaming.pyβStreamChunk,StreamingCacheEntry,StreamingResponseCache, singleton factory (get_streaming_cache)POST /query/streamnow checks the streaming cache before running the retrieval pipeline; on a miss it records each token and inter-chunk timing, then stores the complete response after the stream endsStreamingResponsereplaying stored SSE frames withcache_hit: truein every frame and configurable inter-chunk pacing (cache_stream_replay_delay_ms)False/0by default β K3):cache_stream_enabledβ master switchcache_stream_replay_delay_msβ fixed sleep between replayed chunks (0 = no sleep)cache_stream_max_chunksβ safety cap; oversized responses are not storedInvariant compliance
store()wraps inner cache write in try/except; logs warning, never raisesget_streaming_cache()returnsNonewhen eithercache_enabledorcache_stream_enabledisFalse; route falls through to full pipelineSemanticCacheinner instance assertsq_vecisfloat32atstore()asyncio,json,threading,time,dataclassesβ all stdlib; numpy already required/query/streamSSE contract is unchanged on miss;cache_hitkey absent on missTest plan
python -m pytest tests/unit/test_streaming_cache.py -vβ 38 tests passpython -m pytest tests/ -qβ 1 165 passed, 7 skipped, 0 failuresruff check/ruff format --checkβ cleanhttps://claude.ai/code/session_0171rxj96JzbbH6JwuMu2zfx
Generated by Claude Code