Skip to content

feat(ai): embeddings through the llm gateway, with embedding model evaluation #481

Closed

Description

@dan-petty

Context & Rationale

The embedding task still calls one Ollama node directly (embeddinggemma:300m), while the gateway now serves embeddings from every Ollama node (devops-embedding is bge-m3, and ollama/* passes any model through). Retrieval quality has never been compared on this repository.

Scope & Deliverables

  • Context & Rationale*: The embedding task still calls one Ollama node directly (embeddinggemma:300m), while the gateway now serves embeddings from every Ollama node (devops-embedding is bge-m3, and ollama/* passes any model through). Retrieval quality has never been compared on this repository.
  • Deliverable*: Point the embedding task at the gateway. Compare bge-m3, embeddinggemma and nomic-embed-text on retrieval over the indexed repository (devops ai rag, and the devops ai benchmark embedding runner): recall at k on a small labelled query set, indexing time and vector size. Re-index with the best model.
  • Constraint*: Changing the model means re-indexing Qdrant, since vector sizes differ (768 and 1024).

Strategic Alignment

  • Milestone: v0.2.23 (Foundational Architectural Guardrails & Project Hygiene)
  • Roadmap Reference: docs/ROADMAP.md

Update 2026-10-08: refinement

#1065 shipped. The READMEs still name embeddinggemma:300m (k8s/README.md:79, :88, :119-121; k8s/llm/profiles/README.md:100-103), while the gateway serves only bge-m3:latest (k8s/llm/gateway/configmap.yaml:53-59).

  • Both READMEs name only embedding groups the gateway serves.

Proposed design

Problem statement

The embedding task currently calls one Ollama node directly (embeddinggemma:300m), while the gateway now serves embeddings from every Ollama node. This prevents comparison of retrieval quality across different models and requires re-indexing Qdrant when changing models due to differing vector sizes.

Acceptance criteria

  • Criterion 1: The embedding task points at the LLM gateway instead of a direct Ollama node
    Verification: Verify that calls to the embedding endpoint route through the llm-gateway service rather than directly to an ollama pod
  • Criterion 2: Comparison of bge-m3, embeddinggemma and nomic-embed-text models on retrieval quality
    Verification: Run the devops ai benchmark embedding runner with all three models and compare recall at k scores on a small labelled query set
  • Criterion 3: Indexing time and vector size measurements for each model are recorded
    Verification: Execute re-indexing with each model and measure both indexing duration and final Qdrant collection vector sizes
  • Criterion 4: The best performing model is used for re-indexing the repository
    Verification: Confirm that after evaluation, the index is rebuilt using the highest performing model according to recall metrics

Key questions

  • What are the current embedding models available through the LLM gateway?: The gateway serves embeddings from every Ollama node, with devops-embedding using bge-m3 and ollama/* passing any model through. [sources: docs/ROADMAP.md]
  • What is the current direct Ollama node used for embeddings?: The embedding task currently calls one Ollama node directly (embeddinggemma:300m). [sources: docs/ROADMAP.md]
  • What models will be evaluated for retrieval quality?: The models to be compared are bge-m3, embeddinggemma and nomic-embed-text. [sources: docs/ROADMAP.md]
  • What are the constraints for changing embedding models?: Changing the model means re-indexing Qdrant since vector sizes differ (768 and 1024). [sources: docs/ROADMAP.md]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added this to the v0.2.23 milestone on Sep 24, 2026
  2. added
    type/feature
    scope/ai
    priority/p2-medium
    on Sep 24, 2026
  3. modified the milestones: v0.2.23, v0.2.24 on Sep 28, 2026
  4. added a commit that references this issue on Sep 28, 2026
  5. modified the milestones: v0.2.24, v0.2.23 on Sep 30, 2026
  6. removed this from the v0.2.23 milestone on Oct 1, 2026
  7. dan-petty commented on Oct 1, 2026

    @dan-petty
    OwnerAuthor

    Moved from the shipped v0.2.23 to the backlog. It is still valid (checked 2026-10-01), and P2 items don't displace P1 work in the planned releases.

  8. added
    priority/p3-low
    and removed
    priority/p2-medium
    on Oct 2, 2026
  9. dan-petty commented on Oct 2, 2026

    @dan-petty
    OwnerAuthor

    Grooming (2026-10-02): Priority p2-medium → p3-low. The routing half is already a config switch. What remains is a model-quality evaluation with no defect behind it.

    Checked against the code at the release/v0.2.25 tip.

  10. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    Retarget (2026-10-03). Source: the slow-tier plan (.data/slow-tier-plan-20261003.md, sections 1 and 3) and its verification pass.

    What is compared, and how.

    Why switch at all.

    • MTEB(Code, v1) nDCG@10 is 58.22 for BGE-M3 (dense) and 75.41 for Qwen3-Embedding-0.6B [sourced: https://arxiv.org/html/2506.05176, Table 9]. That is vendor-reported, not measured here. This item's A/B is what turns it into a measurement on this repository.
    • qwen3-embedding:0.6b is already devops-cli's default (config/defaults.py:201).
    • Ollama silently cuts bge-m3 inputs at about 2,048 tokens: it retries a too-long input truncated to its 2,048-token batch. Qwen3-Embedding reads up to 32K [code: Ollama v0.34.4 server/routes.go, per the plan's verification].
    • The Qdrant collections are effectively empty (76 of 76 searches returned nothing, qdrant-0 log), so switching costs one first index, estimated at 15–30 minutes on hog.

    Order.

    Running it (person-run).

    If qwen3-embedding wins.

    1. Rename the gateway group to qwen3-embedding:0.6b (model: ollama/qwen3-embedding:0.6b, model_info.mode: embedding) and set ai.tasks.embedding.model.
    2. Re-index: DEVOPS_CLI_AI_TASK_EMBEDDING_TIMEOUT=120 devops ai rag clear --force && devops ai rag index --force && devops ai rag index-kb.
    3. Check devops ai rag status. The plan's offline chunker run gives about 17,500 chunks.
    4. Recalibrate the 0.35 threshold through ai.rag.score_threshold, which fix(ai): a failing embedding model pauses rag lookups instead of ending rag for the run, and each embedding model gets its own prompts, cache keys, dimension and bounded chunks #1065 makes the code read. Use about 10 known path/symbol pairs and the cosine rag query prints after fix(ai): a rag collection records its embedding model, a mismatch fails instead of wiping the collection, and ranking keeps the cosine score #1066.

    Priority stays P3 for now. In practice it waits for #1065.

  11. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    Review redesign (#1137, 2026-10-03): this item is a phase P5 child (P5-4, conditional) and is not frozen: embeddings through the gateway serve chat and the KB index now, and any review embedding use waits for this item and #1066.

  12. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    Linked: #598, which fits models per Ollama tier with this item choosing the embedding model; that choice sets the background tier's second resident. Found by the 2026-10-08 backlog review.

  13. added this to the v0.2.39 milestone on Oct 17, 2026
  14. dan-petty commented on Oct 18, 2026

    @dan-petty
    OwnerAuthor

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

  15. dan-petty commented on Oct 22, 2026

    @dan-petty
    OwnerAuthor

    What changed

    #1931, merged into release/v0.2.39 as 80e07bb.

    Cause

    The gateway served bge-m3:latest as its one embedding group. The embedding task of the code defaults to qwen3-embedding:0.6b, and the gateway did not serve it. A person compared the two models on 2026-10-22 with devops ai benchmark --type embedding --code . --samples 100. The run used 100 queries over about 17,600 code chunks of this repository. It called Ollama directly through a port-forward, not the gateway, and other jobs used the machine at the same time. Both models give 1024-dimension vectors. qwen3-embedding:0.6b ranked the right chunk first for 74% of the queries, and bge-m3:latest did so for 53%. Its recall@3 was 86% against 62%, and its recall@5 was 89% against 64%. Its MRR was 0.804 against 0.583, and its nDCG@5 was 0.823 against 0.589. On the 99 code queries it ranked the right chunk first for 74 and bge-m3:latest for 52. The one config query says nothing: qwen3-embedding:0.6b missed it and bge-m3:latest found it. qwen3-embedding:0.6b is slower. Its p50 latency was 78.8 ms against 57.9 ms, and its throughput was 12.3 items per second against 15.6. Its p95 latency was 2,655 ms against 137 ms, but the runner takes the p95 from five single queries, so it is the slowest of five. The overall score of the runner was 80.45% against 68.74%.

    11 file(s) changed.

    How it was verified

    Check runs at 1c86b72:

    • Prune PR DevContainer Images: pass
    • Audit Defect PR Hardening: skipping
    • zizmor: pass
    • devops-cli: pass
    • bandit: pass
    • CodeQL: pass
    • Changed-Test Independence: pass
    • Static Analysis: pass
    • Tests & Coverage: pass
    • Rule Pack Tests: pass
    • Fail-to-Pass Check: pass
    • Fail-to-Pass Self-Check: pass
    • Analyze (python): pass
    • Analyze (actions): pass
    • Service Image: skipping
    • DevContainer Image: skipping
    • Dependency Freshness: skipping

    Acceptance Criteria of docs/agent/tasks/task-481-embeddings-through-the-gateway.md:

    • Both READMEs name only embedding groups the gateway serves. Each names the gateway's one embedding group alone (qwen3-embedding:0.6b since part 3). The new test failed for each of four places that named a model the ConfigMap lacked. These were the by-name list, the bullet, the example configuration and the profiles excerpt.
    • The new test reads the model groups from the ConfigMap rather than listing them, so renaming the gateway's embedding group fails it until the READMEs follow.
    • The test classifies no name by a table: a stale model the RAG embedder has no dimension for (mxbai-embed-large:latest, ollama/embeddinggemma:300m) fails the same way as embeddinggemma:300m.
    • The test reads only the repository's files and calls no gateway, Ollama or model.
    • The embedding benchmark ranks code chunks: --code <dir> queries each code chunk under the directory by its path and symbol names and aims the query at that chunk, with no hand-labelled set, model-written query or constant score, and --document and --code are refused together.
    • A runner built with no models benchmarks the two candidates, bge-m3:latest and qwen3-embedding:0.6b. EmbeddingBenchmarkRunner.__init__ is the one place that reads DEFAULT_EMBEDDING_BENCHMARK_MODELS, when models is empty. devops ai benchmark passes the models it parsed (--models, else ai.model), so it reaches the default only when --models holds no model name, as --models , does; a person-run names its models.
    • The comparison ran. A person measured both models on 2026-10-22 (see Measurement). qwen3-embedding:0.6b scored recall@1 of 74% against 53% for bge-m3:latest. Its MRR was 0.804 against 0.583, and its nDCG@5 was 0.823 against 0.589. Both give 1024-dimension vectors. qwen3-embedding:0.6b won.
    • The gateway serves qwen3-embedding:0.6b as its one embedding group, on the deployment that served bge-m3:latest (ollama-48gib-slow, model_info.mode: embedding). The tests read the group from the ConfigMap. No group for bge-m3:latest remains.
    • k8s/devops/configmap.example.yaml sets ai.tasks.embedding.model to the group the gateway serves. _collect_deploy_targets(["llm"], ...) lists the gateway ConfigMap, so deploy-stack --stack llm applies it.
    • The default gateway routes and the GPU matrix routes name the group the gateway serves. A test compares both, and the example ConfigMap of the jobs, with the gateway ConfigMap.
    • The knowledge base gives 1024 dimensions for qwen3-embedding:0.6b, the size that the benchmark measured.
    • Pending a person: deploy the gateway ConfigMap after the merge. Run uv run devops k8s deploy-stack --stack llm. On a cluster that Argo CD manages, the command applies no manifest of git. The llm Application then syncs the ConfigMap from main, after the release merges.
    • Pending a person: restart the gateway after the ConfigMap deploy, because it reads its configuration at start. Run kubectl -n llm rollout restart deployment/llm-gateway && kubectl -n llm rollout status deployment/llm-gateway. Follow-up issue fix(k8s): a changed gateway ConfigMap rolls the gateway deployment, so deploy-stack never leaves a stale pod #1929 makes a changed gateway ConfigMap roll the gateway deployment, so that deploy-stack never leaves a stale pod.
    • Pending a person: check the embedding group of the gateway. Set KEY to the gateway master key. Run kubectl -n llm port-forward svc/llm-gateway 4000:4000. In a second terminal, run curl -sS -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' http://localhost:4000/v1/embeddings -d '{"model":"qwen3-embedding:0.6b","input":"ping"}' | jq '.data[0].embedding | length'. The command prints 1024.
    • Pending a person: if the check fails, look for the model on the slow tier. Run kubectl -n llm exec ds/ollama-48gib-slow -- ollama list. Where the model is missing, run kubectl -n llm exec ds/ollama-48gib-slow -- ollama pull qwen3-embedding:0.6b. Then run the check again.
    • Pending a person: deploy the ConfigMap of the in-cluster jobs after the gateway restart. Run uv run devops k8s deploy-stack --stack devops. The command needs service.repos and service.machine_account in your config.yaml. A deployed devops-cli-config names bge-m3:latest until then, and the gateway no longer serves that model.
    • Pending a person: to deploy both ConfigMaps in one command, run uv run devops k8s deploy-stack --stack all in place of the llm and devops deploys. Then restart the gateway. The cluster jobs read their ConfigMap when they start, so they need no restart. roadmap-service stays at 0 replicas (chore(service): the roadmap service stays at 0 replicas, and its development is blocked, while its machine account is suspended #1562).
    • Pending a person: point your own config.yaml at the gateway model. Set ai.tasks.embedding.provider to gateway and ai.tasks.embedding.model to qwen3-embedding:0.6b. Set ai.gateway_url and the gateway key as in k8s/README.md. An agent never edits that file.
    • Pending a person: re-index with the winner after the steps above. Run export DEVOPS_CLI_AI_TASK_EMBEDDING_TIMEOUT=120 first, because the default timeout is 15 s (DEFAULT_RAG_EMBEDDING_TIMEOUT). Indexing sends batches of 32 to a tier that serves one request at a time. Then run uv run devops ai rag clear --force && uv run devops ai rag index --force && uv run devops ai rag index-kb. The clear comes first, because the index refuses a collection that another model indexed (fix(ai): a rag collection records its embedding model, a mismatch fails instead of wiping the collection, and ranking keeps the cosine score #1066).
    • Pending a person: record the cost of the re-index. Time the index --force step and note its wall time. Record the vector size that uv run devops ai rag status shows. The benchmark measured 1024.
    • Pending a person: recalibrate ai.rag.score_threshold (0.35). For about 10 known path and symbol pairs, run uv run devops ai rag query "<path> <symbol>" --min-score 0. Read the cosine of the known chunk. Set the threshold between those cosines and the cosines of unrelated chunks.
    • Pending a person: after the deploy, read the slow tier's embedding latency. Run kubectl -n llm logs ds/ollama-48gib-slow --since=15m | grep 'POST.*/api/embed' during the re-index. The benchmark p95 of qwen3-embedding:0.6b was 2,655 ms, the slowest of five single queries. Look for requests that take 15 s or more, the default timeout. The re-index step sets 120 s, so the 15 s limit applies to later lookups.
    • Not done: replace the runner's hand-written ranking and metrics (cosine_similarity called per chunk, compute_ndcg_at_k and the inline recall, MRR and nDCG loop in evaluate_model_on_server) with a numpy matrix product (numpy is in uv.lock) and pytrec-eval-terrier, or ir-measures if its named-measure API is preferred. Measured on this part's input (100 queries over the 7,699 chunks of src): 57 s with the runner's pure-Python cosine and sort, against 0.05 s for the numpy matrix and 0.01 s for the metrics. Both libraries gave the runner's recall@1/3/5 (9, 15, 18%) and nDCG@5 (0.138) exactly; MRR differed (0.150 against the runner's 0.151) only because their runs were cut at the top 100, and they break ties by document id where the runner takes the lower index, which differs only for chunks with identical content. The saving is about 2 minutes of a 27-minute run, because the embedding of the corpus dominated the run: 15.6 and 12.3 items per second over about 17,600 chunks is 19 and 24 minutes. pytrec-eval-terrier has no aarch64 wheel and needs a C compiler (gcc 15 or later needs CFLAGS=-std=gnu17), and the change touches the release image build. The estimate is 250k to 400k tokens and about an hour for one build and review (follow-up issue refactor(ai): rank the benchmark with numpy and pytrec-eval #1928).
  16. added a commit that references this issue on Oct 23, 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

    priority/p3-lowscope/aitype/feature

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions