Repository navigation
Description
Problem Description
The Valkey tier of the embedding cache keys each vector by the configured model name and the text (EmbeddingsEngine._valkey_key, src/devops_cli/ai/rag/embeddings.py). The key does not hold the provider or the model name that the request sends. _openai_request_model sends text-embedding-3-small (1,536 dimensions) for qwen3-embedding:0.6b when the provider is openai or copilot with no gateway. The gateway sends qwen3-embedding:0.6b (1,024 dimensions). Both runs write to and read from the same Valkey key. When one Valkey serves both kinds of caller (the central store of #4517), a gateway run can get a vector of 1,536 dimensions, and cosine_similarity then gives 0.0, so intake can miss a duplicate.
PR #4546 fixed the same defect in the disk tier: its key holds the provider and the request model, and it records one vector length for each key. The Valkey tier is out of the scope of that PR.
Reproduction Steps
- Configure
ai.provider: openaiwith no gateway andai.tasks.embedding.model: qwen3-embedding:0.6b, with a Valkey atvalkey.url. - Embed a text with
EmbeddingsEngine. - Configure the gateway provider with the same model and the same Valkey, and embed the same text.
Expected vs Actual Behavior
Expected: the second run misses Valkey and sends the text to the gateway.
Actual: the second run gets the vector of 1,536 dimensions from Valkey.
Environment Diagnostics
Source read on origin/main 5f75d25 and on the branch of PR #4546.
Logs, Traces, or Terminal Output
None. Found by code reading during the review fix of PR #4546.
Proposed design
Problem statement
The Valkey embedding cache keys each vector by the configured model and the text. A direct OpenAI request sends text-embedding-3-small for qwen3-embedding:0.6b, but a gateway request sends qwen3-embedding:0.6b. Both requests use the same Valkey key. A gateway run can get a 1,536-dimension vector, and cosine_similarity returns 0.0. Intake can miss a duplicate. The fix makes the Valkey key hold the provider and the request model, as the disk tier does.
Acceptance criteria
Requirement: Valkey key holds the request identity
The Valkey embedding cache SHALL key each vector by the provider and the model name that the embedding request sends.
Scenario: Direct OpenAI and gateway requests use different keys
- WHEN A direct OpenAI engine and a gateway engine both use the configured model
qwen3-embedding:0.6band embed the same text. - THEN The two engines produce different Valkey keys for that text and query flag.
Requirement: Gateway run misses a direct OpenAI entry
A Valkey entry that a direct OpenAI request writes MUST NOT be returned to a gateway request for the same configured model.
Scenario: A gateway lookup after a direct OpenAI write misses
- WHEN A direct OpenAI engine writes the vector for a text to Valkey, and a gateway engine with the same configured model reads that text.
- THEN The gateway engine gets no vector from Valkey and sends the text to the gateway.
Requirement: Disk and Valkey tiers share one model identity
The disk tier and the Valkey tier SHALL use the same provider and request-model identity for an embedding.
Scenario: A disk hit writes to the Valkey key of the same request model
- WHEN The disk cache holds a vector for a text under the provider and request-model identity, and the engine reads that text.
- THEN The engine writes the vector to the Valkey key built from the same identity.
Existing Tool Considered
No alternatives check has run. No open, maintained tool or library covers this change; it edits the project's own cache-key code in EmbeddingsEngine. The change edits about 15 lines and adds tests. It costs about 3,000 output tokens to write, 1,000 tokens to review, and less than one hour. No separate code is kept; the existing cache tests cover it.
Key questions
- Which identity must the Valkey embedding key hold?: The provider and the request model that the request sends, which is the identity
_disk_cache_modelalready builds for the disk tier. (best practice) [sources: src/devops_cli/ai/rag/embeddings.py:1002, src/devops_cli/ai/rag/embeddings.py:1156, tests/ai/rag/test_embedding_disk_cache.py]- Rejected: Configured model only. A direct OpenAI request sends
text-embedding-3-smallforqwen3-embedding:0.6b, so a gateway request collides with it. - Chosen: Provider and request model. This separates a direct OpenAI request from a gateway request and matches the disk tier.
- Rejected: Provider and configured model. The provider alone does not separate the two request models.
- Rejected: Configured model only. A direct OpenAI request sends
- Should the disk and Valkey tiers share one key helper?: Yes. Rename
_disk_cache_modelto a neutral helper and use it in both tiers. (best practice) [sources: src/devops_cli/ai/rag/embeddings.py:1002, src/devops_cli/ai/rag/embeddings.py:1156]- Chosen: One shared helper. One identity cannot drift between the tiers.
- Rejected: A second expression in
_valkey_key. Two copies can diverge and bring back the collision. - Rejected: Leave the disk tier unchanged and change only Valkey. The two tiers would name the same request model differently.
- Should a Valkey entry also record its vector length?: No. The key now names the provider and the request model, so one key maps to one vector length. A length field would change the stored value format and add migration work for a collision that the key already prevents. (best practice) [sources: src/devops_cli/ai/rag/embeddings.py, tests/valkey/test_valkey_cache_tier.py]
- Chosen: Key identity only. The request model fixes the dimension, and the key now holds that model.
- Rejected: Store
{dimension, vector}. It changes the value format and needs a reader for old entries. - Rejected: Reject a vector when the known dimension differs. It adds a dimension lookup on the read path and does not separate the two request models.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Alternatives check of 2026-11-12: none.
Tool: none found.
Activity
dan-petty commentedon Nov 11, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
fixprefix of the title gives the type.(ai)scope of the title gives the scope.Wrong-dimension vectors cause missed duplicates, but only when two provider types share one Valkey store.It prevents silent data corruption in similarity scores for multi-provider setups.The fix mirrors PR #4546 disk-tier change: add provider and model to the key string in one function.Both concern the Valkey tier of the embedding cache, but #4447 enables the cache while this candidate fixes a key collision in it.devops-cli-service commentedon Nov 11, 2026
Status set to Ready at 4330ee4 (see proposed design in issue body).
devops-cli-service commentedon Nov 12, 2026
Alternatives check: none
Reason: The searches turned up no open, maintained tool or library that supplies this change: they returned only generic cache, Redis/Redis Stack image and MDN pages, none of which keys an embedding cache by the provider and request model. The need is an edit to the project's own cache-key code in
EmbeddingsEngine(_valkey_key, sharing the identity helper of the disk tier), which no external tool can provide.Tool: none found
Lacks:
EmbeddingsEnginecode, not an integration of an external librarySearches run:
Checked on 2026-11-12. A person decides what this means for the item. The check changes no label and closes no issue.
perf(roadmap): consolidate keeps its vectors in the shared tiers (#5099)
chore(main): release 0.138.0 (#5690)
devops-cli-service commentedon Nov 14, 2026
Released in v0.138.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.138.0
devops-cli-service commentedon Nov 14, 2026
Live since 2026-11-14 15:02 UTC