Skip to content

perf(ai): keep intake embeddings between CLI runs - #4546

Merged
dan-petty merged 3 commits into
mainfrom
perf/4447-keep-intake-embeddings-between-cli-runs
Nov 11, 2026
Merged

dan-petty merged 3 commits into
mainfrom
perf/4447-keep-intake-embeddings-between-cli-runs

Conversation

@dan-petty

@dan-petty dan-petty commented Nov 11, 2026 •

Copy link
Copy Markdown
Owner

Intake keeps its embeddings in a disk cache: a SQLite file under the data directory, through the stdlib sqlite3, keyed by the provider, the model name that the request sends and the SHA-256 of the text. The file records one vector length for each key, so a row of another length is a miss. The engine looks in memory, then Valkey, then the disk, and sends only the misses to the model. A corrupt entry or a broken file falls back to the model. The memory tier holds 2,048 vectors, and the lookup counter names the tier disk. Before, each workstation run embedded about 1,866 texts again in about 155 s, because no Valkey answers there. diskcache was rejected: not in uv.lock, pickle by default (GHSA-w8v5-vhqr-4h9v). No Valkey instance is added (#4517).

Closes #4447

Change: openspec/changes/archive/2026-11-11-4447-keep-intake-embeddings-between-cli-runs/

Intake gives its embeddings engine a disk cache: a SQLite file under the
data directory that keeps each vector by the embedding model and the
SHA-256 of the text. The engine looks in memory, then Valkey, then the
disk, and sends only the misses to the model. The memory tier holds 2,048
vectors, and the lookup counter names the tier disk.
@dan-petty dan-petty added type/infra Type infra: the build, CI, images or cluster scope/ai AI review pipeline, personas, prompts, LLM client, or RAG labels Nov 11, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Measurement: one intake call before and after

Host: the devcontainer workstation, 2026-11-11. No Valkey answers at valkey.url (devops valkey ping: Error 111 ... Connection refused). Command: devops roadmap intake --plan --title "perf(ai): probe the embedding phase of intake" --body-file <probe> --filed-by agent, run in one process with a wrapper of EmbeddingsEngine that counts the time in embed_texts, the /v1/embeddings requests, the texts sent to the model and the cache lookups. Each run held the intake lock, so no other intake ran at the same time.

Run Code Texts Embedding s Gateway embedding requests Texts to the model Memory hits Valkey hits Disk hits Misses Whole call s
Before origin/main 7234d71 1,866 155.1 59 1,866 0 0 — 1,866 249.2
After, first run (empty file) this branch 1,867 166.6 59 1,867 0 0 0 1,867 249.8
After, second run this branch 1,868 11.3 1 1 0 0 1,867 1 89.0

One new issue was filed between the runs, so the second run had one changed text.

The file ai/embeddings.db holds 1,867 vectors of 1,024 dimensions in 16.7 MB.

Where the 11.3 s of the second run goes:

  • Disk lookup of 1,867 texts: 0.55 s (read and decode of every row, load average about 48).
  • Valkey tier that refuses: 0.05 s for 1,867 reads and 0.04 s for 1,867 writes, behind the open breaker.
  • One gateway request for one text: about 10 s. Three single-text requests took 13.4 s, 9.4 s and 10.2 s.

Thus a run with no changed text spends less than 1 s in the embedding phase. A run with up to 32 changed texts (one batch) spends about one gateway request, about 10 s. The issue target of 5 s for 50 changed texts needs a faster single embedding request at the gateway; I add this measurement to #4404.

Tests that fail on the base

uv run devops ci fail-to-pass --base origin/main: 2 failed on base (test_a_second_intake_run_reads_the_embeddings_from_the_data_directory: [1, 1] != [1, 0]; test_the_memory_cache_holds_one_intake_comparison_set: 82 == 57), and tests/ai/rag/test_embedding_disk_cache.py errored on base (the module does not exist). Locally, tests/ai/rag, tests/roadmap/intake and tests/telemetry pass (953 tests), and the other tests that build the intake model, tests/invariants and tests/ai/benchmark pass (940 tests).

@dan-petty
dan-petty marked this pull request as ready for review November 11, 2026 08:27
A disk row had the configured model name only. A direct OpenAI request sends text-embedding-3-small for qwen3-embedding:0.6b, so a later gateway run got vectors of 1,536 dimensions for a model of 1,024. A row of any length that is a multiple of 8 bytes was a hit.

The engine now keys each row by the provider and the model name that the request sends. The file records one vector length for each key: a row of another length is a miss, and a write of a new length removes the rows of the old length.
@dan-petty
dan-petty force-pushed the perf/4447-keep-intake-embeddings-between-cli-runs branch from 11a6a98 to 7af81b9 Compare November 11, 2026 08:46
@dan-petty

Copy link
Copy Markdown
Owner Author

Review fix: one finding.

Finding 1 (major), src/devops_cli/ai/rag/embedding_disk_cache.py: a disk hit is not checked against the vector length, and the key holds the configured model name, not the model that the request names. Confirmed. Two new tests failed on the PR head before the fix: a stored valid blob of two doubles came back as a hit (assert (1, [[1.0, 2.0]]) == (2, ...)), and a vector from a direct OpenAI run (the request named text-embedding-3-small for qwen3-embedding:0.6b) was a hit for a later gateway run.

What I did (commit 115e8cc):

  • EmbeddingsEngine._disk_cache_model keys the disk rows by the provider and the model name that the request sends. _openai_request_model holds the name mapping, and _resolve_openai_endpoint_and_model uses it, so the request and the key cannot differ.
  • The file has a second table, dimensions, with one vector length for each key. get_many gives a hit only for a row of that length. put_many keeps only vectors of the length of the first vector, and a new length removes the rows of the old length.
  • New tests: test_a_stored_vector_of_another_length_goes_to_the_model, test_a_vector_of_the_model_that_a_direct_openai_request_names_is_a_miss_at_the_gateway, test_vectors_of_a_new_length_remove_the_rows_of_the_old_length.
  • The spec, design, proposal, tasks and docs/roadmap/intake.md describe the new key and the length rule. The archive stays the last commit.

Fail-to-pass:

  • uv run devops ci fail-to-pass --base 3841e9d5 (the PR head before the fix): 3 failed on base, 8 passed, 0 errored. The 3 that failed are the 3 new tests.
  • uv run devops ci fail-to-pass --base origin/main: the disk cache test module does not import on main (collection failure), and 2 tests fail on base: test_the_memory_cache_holds_one_intake_comparison_set and test_a_second_intake_run_reads_the_embeddings_from_the_data_directory. All pass on the head.

Other checks: uv run devops ci test tests/ai/rag tests/roadmap/intake: 550 passed. mypy on the two changed modules: no issues.

Out of scope: the Valkey tier has the same key gap (configured model name only). It is on main before this PR, so I filed #4569.

@dan-petty
dan-petty merged commit 812871e into main Nov 11, 2026
35 checks passed
@dan-petty
dan-petty deleted the perf/4447-keep-intake-embeddings-between-cli-runs branch November 11, 2026 11:56
dan-petty pushed a commit that referenced this pull request Nov 11, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.112.0](v0.111.0...v0.112.0)
(2026-11-11)


### Features

* **k8s:** export gateway spans without key metadata
([#4520](#4520))
([7234d71](7234d71))
* **k8s:** set the homelab domain in container env values
([#4608](#4608))
([a3bcf7c](a3bcf7c))
* **telemetry:** send pydantic-ai spans through the exporter seam
([#4538](#4538))
([fcf2a7a](fcf2a7a))


### Bug Fixes

* **ai:** price cached prompt tokens of chat calls
([#4584](#4584))
([f84bbe6](f84bbe6))
* **devcontainer:** stop uv noise lines in agent shells
([#4592](#4592))
([9ba375c](9ba375c))
* **k8s:** delete gateway management bodies from spans
([#4551](#4551))
([b835d3c](b835d3c))
* **k8s:** set the kube context and namespace on devops pods
([#4514](#4514))
([9087b39](9087b39))
* **roadmap:** a refused spec after the archive is a plan defect
([#4549](#4549))
([1db29f7](1db29f7))
* **roadmap:** count and log the reason of a left-out stage item
([#4541](#4541))
([5600179](5600179))
* **roadmap:** default the step ceiling to twice the budget
([#4556](#4556))
([1dfb6c8](1dfb6c8))
* **roadmap:** explain --trace shows the argument digest
([#4526](#4526))
([c92195f](c92195f))
* **roadmap:** explain totals count dropped model events
([#4543](#4543))
([fe0e979](fe0e979))
* **roadmap:** give each eval verify run its own report file
([#4534](#4534))
([ad27f2d](ad27f2d))
* **roadmap:** one event loop and a time limit for decide_all
([#4585](#4585))
([ec51e01](ec51e01))
* **roadmap:** scoped updates send requests with no row scope
([#4531](#4531))
([5f75d25](5f75d25))
* **roadmap:** the caller gate reads an added parameter span
([#4548](#4548))
([1ba07c1](1ba07c1))
* **roadmap:** the implement shell waits for its command
([#4536](#4536))
([571e044](571e044))
* **roadmap:** the module-test and caller gates read imports and calls
([#4490](#4490))
([8a22e82](8a22e82))
* **service:** put trace ids on Service JSON log lines
([#4511](#4511))
([0d7a0d2](0d7a0d2))


### Performance Improvements

* **ai:** keep intake embeddings between CLI runs
([#4546](#4546))
([812871e](812871e))
* **roadmap:** intake reads only the issues that changed
([#4552](#4552))
([7dfd155](7dfd155))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/ai AI review pipeline, personas, prompts, LLM client, or RAG type/infra Type infra: the build, CI, images or cluster

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(ai): keep intake embeddings between CLI runs

1 participant