Embedding Agent • Rust AI Agent SDK
EmbeddingAgent: Agent for generating text embeddings. Provides embedding capabilities for text using AI embedding models, with support for batch processing and…
EmbeddingAgent
Defined in the embedding module.
Rust AI Agent SDK
Agent for generating text embeddings. Provides embedding capabilities for text using AI embedding models, with support for batch processing and similarity calculations. # Supported Providers – OpenAI: text-embedding-3-small, text-embedding-3-large, text-embedding-ada-002 – Azure: azure/text-embedding-3-small – Cohere: cohere/embed-english-v3.0 – Voyage: voyage/voyage-3 – Mistral: mistral/mistral-embed
Fields
| Name | Type | Description |
|---|---|---|
name | String | Agent name |
model | String | Model name |
config | EmbeddingConfig | Embedding configuration |
verbose | bool | Verbose output |
Methods
new
fn new() -> EmbeddingAgentBuilderCreate a new builder
simple
fn simple() -> Result<Self>Create a simple embedding agent with default settings
embed
async fn embed(&self, text: &str) -> Result<Vec<f32>>Generate embedding for a single text. # Arguments * text – Text to embed # Returns Vector of floats representing the embedding
Parameters:
| Name | Type |
|---|---|
text | &str |
embed_batch
async fn embed_batch(&self, texts: &[&str]) -> Result<EmbeddingResult>Generate embeddings for multiple texts. # Arguments * texts – Slice of texts to embed # Returns EmbeddingResult containing all embeddings
Parameters:
| Name | Type |
|---|---|
texts | &[&str] |
similarity
async fn similarity(&self, text1: &str, text2: &str) -> Result<f32>Calculate cosine similarity between two texts. # Arguments text1 – First text text2 – Second text # Returns Cosine similarity score (0.0 to 1.0)
Parameters:
| Name | Type |
|---|---|
text1 | &str |
text2 | &str |
find_most_similar
async fn find_most_similar(
&self,
query: &str,
candidates: &[&str],
top_k: usize,
) -> Result<Vec<SimilarityResult>>Find the most similar texts to a query. # Arguments query – Query text candidates – List of candidate texts to compare * top_k – Number of top results to return # Returns List of SimilarityResult sorted by score (descending)
Parameters:
| Name | Type |
|---|---|
query | &str |
candidates | &[&str] |
top_k | usize |
Source
View on GitHubpraisonai/src/embedding/mod.rs at line 229