Skip to content

feat(multimodal): FakeEmbeddingEngine + MemoryVectorStore (closes #147, #149)#186

Open
stevei101 wants to merge 3 commits into
developfrom
feat/multimodal-test-doubles
Open

feat(multimodal): FakeEmbeddingEngine + MemoryVectorStore (closes #147, #149)#186
stevei101 wants to merge 3 commits into
developfrom
feat/multimodal-test-doubles

Conversation

@stevei101
Copy link
Copy Markdown
Contributor

Summary

⚠️ Stack order

This PR is stacked on top of #185 (multimodal foundation). It references types that don't exist on develop yet. Either:

  1. Merge feat(multimodal): cross-modal types + trait seams (closes #146, #148, #153, #156) #185 first, then this PR rebases cleanly onto develop; or
  2. Squash-merge both together in one go.

The branch is rebased onto feat/multimodal-foundation locally; once #185 lands, GitHub will auto-detect the rebase.

What's inside

FakeEmbeddingEngine#147

Method Purpose
new() Default: 8-dim hash-seeded
with_fixed_vector(v) Same vector for every input
with_hash_seeded_vector(dim) Deterministic per-input vectors
with_failure(msg) Inject EmbeddingError::LocalInference
with_delay(d) Inject latency via tokio::time::sleep
call_count() / reset_call_count() Assert on engine usage

MemoryVectorStore#149

Method Purpose
new(), with_capacity(n) Construction
stats() -> StoreStats Total + per-modality counts
Full VectorStore impl Cosine similarity, exact O(n), filters

Filter support: content type, date range, metadata tag equality, min score.

Test plan

  • cargo test -p graphrag-core --features multimodal --lib385/385 pass (10 new fakes tests + 12 foundation + 363 pre-existing)
  • cargo test -p graphrag-core --features multimodal --doc multimodal:: — 3/3 doctests pass
  • cargo clippy -p graphrag-core --features multimodal --all-targets -- -D warnings clean
  • MSRV-clean: uses Option::map_or not is_none_or (latter is 1.82+; project MSRV is 1.70)
  • CI green on PR

Refs

🤖 Generated with Claude Code

principle-lgtm and others added 3 commits June 3, 2026 09:42
, #156)

Introduces the multimodal RAG foundation under a new `multimodal` feature
flag in graphrag-core. Types + async traits only; no backend impls yet —
those land in follow-on PRs per meta-epic #182.

Module layout (`graphrag-core/src/multimodal/`):
- `types`     — `ContentType`, `MultimodalContent`, `ContentSource`
- `embedding` — `Embedding`, `EmbeddingMetadata`, `ModelInfo`,
                `EmbeddingEngine` trait, `EmbeddingError`
- `store`     — `SearchFilters`, `SearchResult`, `VectorStore` trait,
                `VectorStoreError`
- `ingest`    — `MultimodalIngestor` trait, `IngestError`
- `search`    — `CrossModalSearcher` trait, `SearchError`

Closes #146, #148, #153, #156. Lays groundwork for #147, #149, #150,
#151, #152, #154, #155, #157, #158, #159.

Design notes:
- Additive to the existing text-only `EmbeddingProvider` — text-only
  callers stay where they are.
- `Embedding::vector` is `Vec<f32>` (not a const-generic length); backends
  report dimensionality via `ModelInfo`, callers validate per-store.
- `VectorStore::search_by_type` and `_batch` methods ship with default
  impls so backends can override progressively.
- `IngestError::UnsupportedMime` field renamed `source` → `origin` to
  avoid thiserror's implicit `#[source]` convention.
- `ContentSource::DirectContent.data` → `bytes` to satisfy the workspace
  clippy `disallowed_names` rule (per AGENTS.md).
- Each public type carries a doctest or unit test; `multimodal::*`
  tests: 12 lib + 2 doctests, all green.

Refs meta-epic #182, TDD `docs/tdd-multimodal-and-service.md` phase 2.1.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Lands the in-memory test doubles for the multimodal seams introduced in
PR #185. Both live in `graphrag-core/src/multimodal/fakes.rs` behind the
existing `multimodal` feature flag.

`FakeEmbeddingEngine` (#147):
- Builder pattern with `new`, `with_fixed_vector`, `with_hash_seeded_vector`,
  `with_failure`, `with_delay`
- `call_count()` and `reset_call_count()` for test assertions
- Deterministic hash-seeded mode: identical inputs → identical vectors,
  distinct inputs → distinct vectors
- Failure injection returns `EmbeddingError::LocalInference`
- Latency injection via `tokio::time::sleep` for timeout/concurrency tests

`MemoryVectorStore` (#149):
- `new`, `with_capacity`, `stats() -> StoreStats`
- Exact cosine similarity (O(n) per query) — fine at test sizes
- Filter support: content type, date range, metadata tag equality, min score
- Default `store_batch` + `search_by_type` inherited from the trait

10 unit tests covering both fakes + 1 doctest on the builder. All green.

Refs meta-epic #182, TDD phase 3.1.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (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.

Implement FakeEmbeddingEngine for Testing

2 participants