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

Diagram

Input Data

Agent: EmbeddingAgent

Output Result

Fields

NameTypeDescription
nameStringAgent name
modelStringModel name
configEmbeddingConfigEmbedding configuration
verboseboolVerbose output

Methods

new

rust
fn new() -> EmbeddingAgentBuilder

Create a new builder

simple

rust
fn simple() -> Result<Self>

Create a simple embedding agent with default settings

embed

rust
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:

NameType
text&str

embed_batch

rust
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:

NameType
texts&[&str]

similarity

rust
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:

NameType
text1&str
text2&str

find_most_similar

rust
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:

NameType
query&str
candidates&[&str]
top_kusize

Source

View on GitHub

praisonai/src/embedding/mod.rs at line 229


Related Documentation