Skip to content

fix(k8s): the q4_0 ollama-16gib tier makes different embedding vectors, so a fallback rag batch puts drifted vectors in the index #2396

Closed

Description

@dan-petty

Problem Description

ollama-16gib sets OLLAMA_KV_CACHE_TYPE: q4_0. The other eight tiers set q8_0 (k8s/llm/profiles/ollama-profiles.yaml). Ollama passes the value to llama-server for every model, also for the embedding model (--cache-type-k q4_0 --cache-type-v q4_0). The 4-bit KV cache changes the vectors of qwen3-embedding:0.6b: for the same input, a vector from ollama-16gib has a cosine of 0.78 to 0.92 against a vector from a q8_0 tier.

The gateway lists ollama-16gib-fast as an order: 2 deployment of qwen3-embedding:0.6b (k8s/llm/gateway/config.yaml). When an order-1 tier fails or cools down, a RAG batch goes to it. Its vectors then go into the same Qdrant collection as the q8_0 vectors, and retrieval of those chunks gets worse. Nothing records which tier made a vector.

Reproduction Steps

  1. Make sure that ollama-16gib has no model loaded (kubectl -n llm exec ds/ollama-16gib -c ollama -- ollama ps), so the test evicts nothing.
  2. Port-forward ds/ollama-16gib and ds/ollama-48gib-slow.
  3. Send the same /api/embed request to each: {"model": "qwen3-embedding:0.6b", "input": [<three texts>], "options": {"num_ctx": 8192}}.
  4. Compute the cosine of each pair of vectors.

Expected vs Actual Behavior

  • Expected: every tier that serves the embedding group makes the same vector for the same input (cosine 0.999 or more, the noise between two GPU families).
  • Actual: on 2026-10-28, with Ollama 0.34.4, three texts gave cosines of 0.858, 0.922 and 0.784 between ollama-16gib (q4_0) and ollama-48gib-slow (q8_0). On Ollama 0.40.12, with the KV cache type equal, the same comparison across two GPU families gave 0.9995 to 0.9997, so the KV cache type causes the difference.

Environment Diagnostics

  • Ollama 0.34.4 on every tier. 0.40.12 passes OLLAMA_KV_CACHE_TYPE to llama-server in the same way (llm/server.go, llm/llama_server.go).
  • qwen3-embedding:0.6b, Q8_0 GGUF, last-token pooling.

Logs, Traces, or Terminal Output

llama-server command on the q8_0 tier: --cache-type-k q8_0 --cache-type-v q8_0 --flash-attn auto --embedding -b 2048 -ub 2048. On a q4_0 tier the same command has --cache-type-k q4_0 --cache-type-v q4_0.

Proposed design

Problem statement

The ollama-16gib tier sets OLLAMA_KV_CACHE_TYPE to q4_0 while the other eight tiers set q8_0. Ollama passes this value to llama-server for every model, including the embedding model. The 4-bit KV cache changes the vectors of qwen3-embedding:0.6b, so a vector from the 16gib tier has a cosine of 0.78 to 0.92 against a vector from a q8_0 tier. When the gateway routes a RAG embedding batch to the 16gib tier as an order-2 fallback, the drifted vectors enter the shared Qdrant collection and degrade retrieval quality for those chunks.

Acceptance criteria

  • Criterion 1: The ollama-16gib DaemonSet in k8s/llm/profiles/ollama-profiles.yaml sets OLLAMA_KV_CACHE_TYPE to q8_0.
    Verification: Read the ollama-16gib container env block in k8s/llm/profiles/ollama-profiles.yaml and confirm the value is q8_0.
  • Criterion 2: All nine Ollama tiers in ollama-profiles.yaml use the same OLLAMA_KV_CACHE_TYPE value.
    Verification: Grep for OLLAMA_KV_CACHE_TYPE in k8s/llm/profiles/ollama-profiles.yaml and confirm every occurrence has the value q8_0.
  • Criterion 3: After the change, the same /api/embed request sent to ollama-16gib and ollama-48gib-slow returns vectors with a cosine similarity of 0.999 or higher.
    Verification: Port-forward both DaemonSets, send the same three-text embedding request to each, and compute the pairwise cosine. Every pair must be 0.999 or above.

Key questions

  • Will the 16gib tier have enough VRAM for a q8_0 KV cache with its 48000-token context and two loaded models?: Yes. The 16gib tier uses a shorter context (48000) than the other embedding tiers (128000 or more), and the issue and intake both treat the one-line change as safe. The knowledge base document confirms q4_0 saves roughly 50% of per-slot VRAM, so q8_0 uses more, but the shorter context and the tier's 16-to-20 GiB GPU target absorb the difference. (proposed) [sources: k8s/llm/profiles/ollama-profiles.yaml:117, src/devops_cli/ai/knowledge_base/it_domains/tools/ollama.md:31, openspec/changes/archive/2026-10-28-2395-ollama-0-40-12/design.md:16]
  • Should the fix also add metadata to record which tier produced each vector in the Qdrant collection?: No. The intake scopes this item to the one-line config fix. Recording the producing tier is a separate concern and is not part of this change. (proposed) [sources: k8s/llm/gateway/config.yaml]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/bug
    on Oct 28, 2026
  2. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.

    • Type: type/bug. A configuration error (q4_0 vs q8_0) produces wrong embedding vectors, which is a defect in the deployment profile.
    • Priority: P2-Medium. The bug silently degrades RAG retrieval only when the order-1 tier fails, so it is not a crash but it corrupts index data.
    • Value: Medium. Drifted vectors in the shared Qdrant collection reduce retrieval quality for every chunk they affect, but the trigger is a fallback scenario.
    • Effort: Low. The core fix is changing OLLAMA_KV_CACHE_TYPE from q4_0 to q8_0 in the profile YAML, a one-line config edit.
    • Related: fix(k8s): the gateway spreads embedding batches over both order 1 tiers, not only the first #2027, which asks for a different change. Both items concern the embedding fallback path across tiers, but #2027 fixes routing spread while this candidate fixes the KV cache type that makes fallback vectors inconsistent.
  3. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    Status set to Ready at bb46660 (see proposed design in issue body).

  4. added
    priority/p2-medium
    status/ready
    value/medium
    effort/low
    scope/k8s
    on Oct 28, 2026
  5. devops-cli-service commented on Nov 1, 2026

    @devops-cli-service
    Contributor

    Staged: branch fix/2396-the-q4-0-ollama-16gib-tier, draft pull request #2988. The pull request plans the item and closes no issue.

    The task groups, with the tokens of the inputs of each step, for a budget of 40000 tokens:

    1. Set q8_0 KV cache on ollama-16gib: 3007 tokens
  6. added a commit that references this issue on Nov 1, 2026
  7. removed
    status/ready
    on Nov 1, 2026
  8. 43 remaining items

  9. added
    status/planned
    and removed
    owner/service
    status/blocked
    on Nov 1, 2026
  10. devops-cli-service commented on Nov 1, 2026

    @devops-cli-service
    Contributor

    Cleared the stop at group 1 by the rule digest: the runner image changed since the stop, from sha256:04d655904252706a7321aed38fa5cafd293625c5db469f252f57163a7c463f16 to sha256:c4ca1742d66bef1bfb15d41d7c54ebf2d0c674a8aaf413f2b28253a0963e4ab0. The item is Planned again, and the Service takes it in the next round. The Service clears a stop one time for each runner image. A new stop on this image waits for a comment implement: retry.

  11. added
    owner/service
    status/in-progress
    status/in-review
    and removed
    status/planned
    status/in-progress
    on Nov 1, 2026
  12. devops-cli-service commented on Nov 1, 2026

    @devops-cli-service
    Contributor

    Pull request #3101 is ready for review. The checks passed.

    Spend: 36 model requests, 876581 input tokens, 4851 output tokens.

  13. devops-cli-service commented on Nov 1, 2026

    @devops-cli-service
    Contributor

    The runner Job devops-cli-runner-20261101-201520-b97a ended: succeeded.
    Image digest: sha256:c4ca1742d66bef1bfb15d41d7c54ebf2d0c674a8aaf413f2b28253a0963e4ab0

    The last lines of its log:

    Tool call: shell, started: git grep -h -A1 <masked> -- ...
    Tool call: shell, program git, refused.
    Tool call: grep, ok.
    Tool call: shell, started: uv run devops ci test tests/ai/benchmark/test_k8s_llm_gateway.py ...
    Tool call: shell, program uv, ok.
    Tool call: shell, started: grep -n <masked> k8s/llm/profiles/ollama-profiles.yaml | wc ...
    Tool call: shell, program grep, refused.
    Tool call: shell, started: uv run python -c <masked>
    Tool call: shell, program uv, refused.
    Tool call: shell, started: grep -A2 -B2 OLLAMA_KV_CACHE_TYPE k8s/llm/profiles/ollama-profiles.yaml | ...
    Tool call: shell, program grep, refused.
    Tool call: grep, ok.
    Tool call: shell, started: grep <masked> k8s/llm/profiles/ollama-profiles.yaml | wc -l
    Tool call: shell, program grep, refused.
    Tool call: grep, ok.
    Tool call: grep, ok.
    Tool call: read_file, ok.
    Tool call: shell, started: other
    Tool call: shell, program other, refused.
    Tool call: shell, started: git diff --stat
    Tool call: shell, program git, ok.
    Tool call: shell, started: git diff
    Tool call: shell, program git, ok.
    Tool call: shell, started: other
    Tool call: shell, program other, refused.
    Tool call: shell, started: git log --oneline -1
    Tool call: shell, program git, ok.
    Tool call: edit_file, ok.
    Tool call: shell, started: git status
    Tool call: shell, program git, ok.
    Tool call: shell, started: git diff k8s/llm/profiles/ollama-profiles.yaml | head -20
    Tool call: shell, program git, refused.
    Tool call: shell, started: git diff k8s/llm/profiles/ollama-profiles.yaml
    Tool call: shell, program git, ok.
    Tool call: shell, started: git grep -c <masked> k8s/llm/profiles/ollama-profiles.yaml
    Tool call: shell, program git, ok.
    Tool call: shell, started: git grep -c <masked> k8s/llm/profiles/ollama-profiles.yaml
    Tool call: shell, program git, ok.
    ✓ Took 1 item(s) to a ready pull request, stopped 0.
    Elapsed: 11m 29s
    
  14. removed
    owner/service
    on Nov 1, 2026
  15. removed
    status/in-review
    on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/lowpriority/p2-mediumscope/k8ssource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions