Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(embed): add local embedding provider crate

Steven Enamakel030dbe8d37f2
diff --git a/crates/openhuman-embed/Cargo.toml b/crates/openhuman-embed/Cargo.toml
index 5a1ea20789..8240910c0b 100644
--- a/crates/openhuman-embed/Cargo.toml
+++ b/crates/openhuman-embed/Cargo.toml
@@ -50,6 +50,7 @@ tinyagents-session = { path = "../../vendor/tinyagents/crates/tinyagents-session
# The wire request/response types `complete` converts to; same path as the
# core's so one copy resolves.
tinyinference-llm = { path = "../../vendor/tinyagents/vendor/tinyinference/crates/tinyinference-llm" }
+tinyinference-embeddings = { path = "../../vendor/tinyagents/vendor/tinyinference/crates/tinyinference-embeddings" }
tokio = { version = "1", features = ["macros", "rt-multi-thread", "sync", "time"] }
url = "2"
uuid = { version = "1", features = ["v4"] }
diff --git a/crates/openhuman-embed/src/embeddings.rs b/crates/openhuman-embed/src/embeddings.rs
new file mode 100644
index 0000000000..e6a18b95bd
--- /dev/null
+++ b/crates/openhuman-embed/src/embeddings.rs
@@ -0,0 +1,31 @@
+//! Text embedding models, re-exported for hosts that index or search.
+//!
+//! The same models the core's memory layer embeds with, exposed directly so a
+//! host that keeps its own vector index (a code-search service, a reviewer's
+//! retrieval step) depends on one OpenHuman pin rather than a second copy of
+//! the inference crates.
+//!
+//! These are re-exports, not wrappers, on purpose: the embedding signature
+//! ([`format_embedding_signature`], [`EmbeddingModel::signature`]) decides
+//! which partition a stored vector belongs to, so a facade that reshaped it
+//! would silently move every host's existing vectors into a fresh, empty
+//! space. Re-exporting keeps the one source of truth.
+//!
+//! [`set_rate_limit`] is process-wide, like the provider quota it guards.
+//! Unlike [`Completer`](crate::complete::Completer), these models need no
+//! [`Runtime`](crate::Runtime).
+
+pub use tinyinference_embeddings::{
+ format_embedding_signature, set_rate_limit, CohereEmbeddingModel, EmbeddingModel,
+ MockEmbeddingModel, NoopEmbeddingModel, OllamaEmbeddingModel, OpenAiEmbeddingModel,
+ VoyageEmbeddingModel, COHERE_API_BASE, COHERE_DEFAULT_DIMENSIONS, COHERE_DEFAULT_MODEL,
+ DEFAULT_OLLAMA_DIMENSIONS, DEFAULT_OLLAMA_MODEL, DEFAULT_OLLAMA_URL,
+ DEFAULT_REQUESTS_PER_MINUTE, VOYAGE_API_BASE, VOYAGE_DEFAULT_DIMENSIONS,
+ VOYAGE_DEFAULT_MODEL,
+};
+/// Errors the embedding models return.
+pub use tinyinference_embeddings::{Error as EmbeddingError, Result as EmbeddingResult};
+
+#[cfg(test)]
+#[path = "embeddings_tests.rs"]
+mod tests;
diff --git a/crates/openhuman-embed/src/embeddings_tests.rs b/crates/openhuman-embed/src/embeddings_tests.rs
new file mode 100644
index 0000000000..dc4f108107
--- /dev/null
+++ b/crates/openhuman-embed/src/embeddings_tests.rs
@@ -0,0 +1,21 @@
+use super::*;
+
+#[tokio::test]
+async fn mock_model_embeds_through_the_facade() {
+ let model = MockEmbeddingModel::new(8);
+ let vectors = model
+ .embed(&["fn main() {}".to_string(), "struct S;".to_string()])
+ .await
+ .unwrap();
+ assert_eq!(vectors.len(), 2);
+ assert!(vectors.iter().all(|vector| vector.len() == 8));
+ let query = model.embed_query("main").await.unwrap();
+ assert_eq!(query.len(), 8);
+}
+
+#[test]
+fn signature_format_is_pinned() {
+ // Stored vectors are partitioned by this string; a change here re-homes
+ // every host's index, so it is asserted literally.
+ assert_eq!(format_embedding_signature("openai", "text-embedding-3-small", 1536), "openai:text-embedding-3-small:1536");
+}
diff --git a/crates/openhuman-embed/src/lib.rs b/crates/openhuman-embed/src/lib.rs
index 17191f5181..620344778e 100644
--- a/crates/openhuman-embed/src/lib.rs
+++ b/crates/openhuman-embed/src/lib.rs
@@ -93,6 +93,7 @@ mod core_agent;
mod error;
mod harness;
pub mod complete;
+pub mod embeddings;
pub mod memory;
mod runtime;
mod turn;