Skip to content

fix(core): carry corpus_id on Embedding for vector corpus scoping (ADR-0004 §3) - #175

Merged
officialCodeWork merged 1 commit into
mainfrom
fix/embedding-corpus-id
Jun 9, 2026
Merged

fix(core): carry corpus_id on Embedding for vector corpus scoping (ADR-0004 §3)#175
officialCodeWork merged 1 commit into
mainfrom
fix/embedding-corpus-id

Conversation

@officialCodeWork

Copy link
Copy Markdown
Owner

fix(core): carry corpus_id on Embedding for vector corpus scoping (ADR-0004 §3)

The bug

Embedding carried no corpus, so the vector arm could not honour the
corpus_ids filter
on retrieve_ids: the noop store ignored corpus_ids
entirely and QdrantVectorStore stamped an empty corpus. A corpus-scoped vector
retrieval could therefore surface chunks from sibling corpora — a tenant/corpus
isolation gap (ADR-0004 §3).

The fix

  • Add an optional corpus_id to Embedding (core type + proto/core.proto
    field 6 + regenerated dist/schemas/Embedding.json).
  • The embedder SPI has no corpus, so the ingest pipeline stamps each embedding
    from its source Chunk
    ; the noop store and all five vector backends now
    filter on corpus_ids and surface corpus_id on the ChunkRef.
  • A None corpus never matches a non-empty corpus_ids filter — the safe,
    no-leak direction (query-side / HyDE embeddings carry no corpus).
  • New contract tests (isolation / surfacing / empty-filter / none-never-matches)
    • an ingest corpus-scoping test; ADR-0004 §3 and the backends reference updated.

Verification (local — see note)

  • Schema, proto, and OpenAPI drift gates: OK (regenerated artifacts in sync)
  • mypy --strict (329 files) ✅ · ruff
  • pytest contract + ingest + core + backends + ingest + ragctl ✅

Note: this repo's GitHub Actions are currently failing at startup org-wide
(Actions billing/spending-limit — unrelated dependabot PRs fail identically).
Verified locally; should go green once Actions are restored.

🤖 Generated with Claude Code

…R-0004 §3)

Close the ADR-0004 §3 gap: Embedding carried no corpus, so the vector arm
could not honour the corpus_ids filter on retrieve_ids — the noop store
ignored corpus_ids entirely and QdrantVectorStore stamped an empty corpus
("corpus_id not in Embedding"). A corpus-scoped vector retrieval could
therefore surface chunks from sibling corpora.

Add an optional corpus_id to Embedding (core type + proto field 6 + the
regenerated dist schema). The embedder SPI has no corpus, so the ingest
pipeline stamps each embedding from its source Chunk; the noop store and the
five backends now filter on corpus_ids and surface corpus_id on the ChunkRef.
A None corpus never matches a non-empty corpus_ids filter — the safe,
no-leak direction (query-side / HyDE embeddings carry no corpus). ragctl's
noop demos pass corpus_id through. Adds contract tests (isolation / surfacing
/ empty-filter / none-never-matches) + an ingest corpus-scoping test; ADR-0004
§3 and the backends reference updated.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@officialCodeWork
officialCodeWork merged commit 35a9952 into main Jun 9, 2026
13 of 18 checks passed
officialCodeWork pushed a commit that referenced this pull request Jun 9, 2026
… doc tests (Step 7.5)

Publish the docs as a Docusaurus 3 site that sources the repo docs/ tree in
place (single source of truth, no copy step; markdown.format 'detect' so the
hand-written .md renders as CommonMark).

- website/: Docusaurus scaffold (config, sidebars, theme, tsconfig).
- scripts/gen_api_reference.py: renders dist/openapi.json -> docs/reference/
  rest-api.md (43 paths). Drift-gated like dist/schemas + the proto stubs.
- tests/docs/: asserts every ragctl subcommand and /v1 path in a quickstart is
  real (registered CLI command / OpenAPI path). No services needed.
- .github/workflows/docs.yml: api-ref drift, doc tests, codespell, lychee
  offline link-check, npm run build.
- task docs:api / docs:dev / docs:build.

Deferred: Algolia search, versioned docs, the deploy workflow. Also records the
backlog PR-history rows for #175-#177. ADR-0047.

Verified locally: ruff, ruff format, tests/docs (3), gen_api_reference run,
208-link relative check. (npm site build is a CI step.)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant