Skip to content

feat(embeddings): port provider implementations#58

Merged
senamakel merged 4 commits into
tinyhumansai:mainfrom
senamakel:feat/port-embeddings
Jul 12, 2026
Merged

feat(embeddings): port provider implementations#58
senamakel merged 4 commits into
tinyhumansai:mainfrom
senamakel:feat/port-embeddings

Conversation

@senamakel

@senamakel senamakel commented Jul 12, 2026

Copy link
Copy Markdown
Member

Summary

Port the OpenHuman embedding provider implementations into tinyagents. This adds native Voyage, Cohere, Ollama, cloud, and no-op models, shared retry/rate-limit behavior, and stable provider/model/signature identity on EmbeddingModel.

API Or Behavior Changes

EmbeddingModel now exposes name, model_id, and a stable signature. OpenAI preserves blank batch positions and provider implementations validate configuration before network calls.

Tests

  • cargo fmt --check
  • cargo clippy --all-targets -- -D warnings - not run locally
  • cargo clippy --all-targets --all-features -- -D warnings - not run locally
  • cargo build --all-targets - not run separately
  • cargo build --all-targets --all-features - not run separately
  • cargo test - focused suite run instead
  • cargo test --all-features - not run locally

Focused validation: cargo test --lib harness::embeddings (35 passed).

Documentation

Public APIs and provider behavior are documented inline; no separate docs page exists for this module.

Summary by CodeRabbit

  • New Features

    • Added support for Cohere, Voyage, Ollama, and OpenAI-compatible cloud embedding providers.
    • Added a no-op embedding option for deployments without semantic search.
    • Added provider identity signatures for consistent embedding configuration tracking.
    • Added configurable request rate limiting and retry handling for temporary service errors.
    • Improved embedding validation, endpoint handling, and response consistency checks.
  • Bug Fixes

    • Improved handling of blank inputs, missing credentials, invalid responses, and provider-specific failures.

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 13 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 73307439-c830-4e94-888c-29f98c38d7f3

📥 Commits

Reviewing files that changed from the base of the PR and between ca47b5b and 8f75355.

📒 Files selected for processing (9)
  • src/harness/embeddings/cloud.rs
  • src/harness/embeddings/cohere.rs
  • src/harness/embeddings/mod.rs
  • src/harness/embeddings/noop.rs
  • src/harness/embeddings/ollama.rs
  • src/harness/embeddings/openai.rs
  • src/harness/embeddings/rate_limit.rs
  • src/harness/embeddings/test.rs
  • src/harness/embeddings/types.rs
📝 Walkthrough

Walkthrough

The PR expands embedding support with Cloud, Cohere, Ollama, Voyage, and no-op providers. It adds stable embedding identities, shared rate limiting and retry handling, stricter OpenAI-compatible validation, public exports, tests, and dependency updates.

Changes

Embedding provider expansion

Layer / File(s) Summary
Embedding contract and request controls
src/harness/embeddings/types.rs, src/harness/embeddings/rate_limit.rs, src/harness/embeddings/retry_after.rs, Cargo.toml
Embedding models gain stable provider/model signatures, with shared per-URL rate limiting and bounded Retry-After backoff.
OpenAI-compatible embedding flow
src/harness/embeddings/openai.rs
OpenAI requests gain configurable dimensions and API-key enforcement, URL/model normalization, stricter response validation, and transient-error retries.
Provider implementations
src/harness/embeddings/cloud.rs, src/harness/embeddings/cohere.rs, src/harness/embeddings/ollama.rs, src/harness/embeddings/voyage.rs, src/harness/embeddings/noop.rs
Adds Cloud, Cohere, Ollama, Voyage, and no-op embedding models with provider-specific validation and request behavior.
Public wiring and validation
src/harness/embeddings/mod.rs, src/harness/embeddings/test.rs, examples/local_model_probe.rs
Exports the new providers and shared helpers, adds identity/signature tests, and reformats probe output expressions without changing behavior.

Estimated code review effort: 4 (Complex) | ~45 minutes

Poem

I’m a rabbit with vectors tucked under my ear,
New clouds and Cohere hop closer this year.
Ollama trots, Voyage sails bright,
Retries and rate limits keep requests just right.
No-op naps softly in zero-dimension light.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 34.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the PR’s main change: porting embedding provider implementations.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ca47b5b20b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/harness/embeddings/openai.rs Outdated
Comment thread src/harness/embeddings/noop.rs Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/harness/embeddings/cloud.rs (1)

71-78: 🚀 Performance & Scalability | 🔵 Trivial | 🏗️ Heavy lift

Reuse a shared client for cloud embedding requests. CloudEmbeddingModel::embed rebuilds OpenAiEmbeddingModel on every call (src/harness/embeddings/cloud.rs:71-78), so the underlying reqwest::Client and its connection pool are discarded each time. Add a path that keeps one client on CloudEmbeddingModel and only swaps the bearer token per request.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/harness/embeddings/cloud.rs` around lines 71 - 78, Update
CloudEmbeddingModel and its embed method to retain and reuse a single underlying
reqwest client across requests, while applying the current bearer token for each
call. Avoid constructing a new OpenAiEmbeddingModel/client in every embed
invocation, and preserve the existing base URL, model, dimensions, and API-key
behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/harness/embeddings/mod.rs`:
- Around line 281-282: Make the request-control modules declared privately in
the embeddings module, then explicitly re-export only the documented host-facing
functions and constants from rate_limit and retry_after. Avoid exposing helper
functions such as acquire or parsing internals through public module paths,
while preserving the intended external API.

In `@src/harness/embeddings/rate_limit.rs`:
- Around line 18-25: Update the nested condition around BUCKETS in the
rate-limit reset logic to use a let-chain combining previous != per_minute with
the optional registry check. Preserve the existing lock, poison recovery, and
clear behavior.

---

Nitpick comments:
In `@src/harness/embeddings/cloud.rs`:
- Around line 71-78: Update CloudEmbeddingModel and its embed method to retain
and reuse a single underlying reqwest client across requests, while applying the
current bearer token for each call. Avoid constructing a new
OpenAiEmbeddingModel/client in every embed invocation, and preserve the existing
base URL, model, dimensions, and API-key behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2112dbd5-5a87-419c-9e1f-a78fcf5cae4f

📥 Commits

Reviewing files that changed from the base of the PR and between 9d56bf2 and ca47b5b.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (13)
  • Cargo.toml
  • examples/local_model_probe.rs
  • src/harness/embeddings/cloud.rs
  • src/harness/embeddings/cohere.rs
  • src/harness/embeddings/mod.rs
  • src/harness/embeddings/noop.rs
  • src/harness/embeddings/ollama.rs
  • src/harness/embeddings/openai.rs
  • src/harness/embeddings/rate_limit.rs
  • src/harness/embeddings/retry_after.rs
  • src/harness/embeddings/test.rs
  • src/harness/embeddings/types.rs
  • src/harness/embeddings/voyage.rs

Comment thread src/harness/embeddings/mod.rs Outdated
Comment thread src/harness/embeddings/rate_limit.rs Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f60981bdce

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/harness/embeddings/cohere.rs Outdated
Comment thread src/harness/embeddings/cohere.rs Outdated
Comment thread src/harness/embeddings/ollama.rs Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 777cd7600c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/harness/embeddings/cohere.rs Outdated
Comment thread src/harness/embeddings/ollama.rs

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8f75355727

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +257 to +258
if live.is_empty() {
return Ok(vec![Vec::new(); texts.len()]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject all-blank Ollama batches

When every input is blank, live is empty and this returns one zero-dimensional vector per input even though OllamaEmbeddingModel::dimensions() is 1024. That still violates the EmbeddingModel contract in types.rs and surfaces as a vector-store dimension error for Retriever::retrieve(" ", ...) against a nonempty Ollama index instead of rejecting invalid provider input; mixed blank batches now error, so all-blank batches should too or return valid 1024-dimensional placeholders.

Useful? React with 👍 / 👎.

Comment on lines +37 to +39
.with_dimensions(dimensions)
.with_base_url(base_url)
.with_send_dimensions(false)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Send Voyage output_dimension for custom dimensions

When callers use VoyageEmbeddingModel::with_options(key, "voyage-3-large", 512, ...), the wrapper records and later validates 512 dimensions, but this path sends no dimension request to Voyage. Voyage's API uses output_dimension for supported lower dimensions and otherwise returns the model default (1024 for voyage-3-large; see https://docs.voyageai.com/reference/embeddings-api), so every non-default dimension call fails with a dimension mismatch instead of producing the requested vector size.

Useful? React with 👍 / 👎.

Comment on lines +59 to +60
async fn embed(&self, texts: &[String]) -> Result<Vec<Vec<f32>>> {
self.inner.embed(texts).await

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Set Voyage input_type for retrieval calls

For Voyage retrievers, Retriever::retrieve now calls embed_query, but VoyageEmbeddingModel does not override it, so the default query path calls this same document embed method and the OpenAI-shaped body has neither input_type: "query" nor input_type: "document". Voyage recommends those values for search and prepends different retrieval prompts for each (https://docs.voyageai.com/reference/embeddings-api), so Voyage-backed retrieval loses the provider's query/document tuning even though the trait now supports asymmetric providers.

Useful? React with 👍 / 👎.

@senamakel senamakel merged commit 19dc2c4 into tinyhumansai:main Jul 12, 2026
2 checks passed
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