| Crates.io | lumosai-vector-fastembed |
| lib.rs | lumosai-vector-fastembed |
| version | 0.1.4 |
| created_at | 2025-06-09 09:10:26.910109+00 |
| updated_at | 2025-06-14 13:43:50.569512+00 |
| description | FastEmbed integration for LumosAI vector storage - local embedding generation |
| homepage | https://lumosai.dev |
| repository | https://github.com/louloulin/lumos.ai.git |
| max_upload_size | |
| id | 1705698 |
| size | 171,019 |
FastEmbed integration for LumosAI vector storage, providing fast, local embedding generation without external API dependencies.
Add this to your Cargo.toml:
[dependencies]
lumosai-vector-fastembed = "0.1.0"
lumosai-vector-core = "0.1.0"
use lumosai_vector_fastembed::{FastEmbedProvider, FastEmbedModel};
use lumosai_vector_core::traits::EmbeddingModel;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create FastEmbed provider
let provider = FastEmbedProvider::with_model(FastEmbedModel::BGESmallENV15).await?;
// Generate single embedding
let embedding = provider.embed_text("Hello, world!").await?;
println!("Embedding dimensions: {}", embedding.len());
// Generate batch embeddings
let texts = vec![
"First document".to_string(),
"Second document".to_string(),
"Third document".to_string(),
];
let embeddings = provider.embed_batch(&texts).await?;
println!("Generated {} embeddings", embeddings.len());
Ok(())
}
use lumosai_vector_fastembed::{
FastEmbedProvider, FastEmbedModel, FastEmbedConfigBuilder
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create custom configuration
let config = FastEmbedConfigBuilder::new()
.max_batch_size(128)
.show_download_progress(true)
.num_threads(4)
.cache_dir("/tmp/fastembed_models")
.build();
// Create provider with custom config
let provider = FastEmbedProvider::new(FastEmbedModel::BGEBaseENV15, config).await?;
// Use the provider...
let embedding = provider.embed_text("Custom configuration example").await?;
Ok(())
}
| Model | Dimensions | Max Length | Best For |
|---|---|---|---|
BGESmallENV15 |
384 | 512 | Fast general purpose |
BGEBaseENV15 |
768 | 512 | Balanced quality/speed |
BGELargeENV15 |
1024 | 512 | High quality |
AllMiniLML6V2 |
384 | 256 | Lightweight, fast |
AllMiniLML12V2 |
384 | 256 | Better than L6 |
| Model | Dimensions | Languages | Best For |
|---|---|---|---|
MultilingualE5Small |
384 | 100+ | Multilingual apps |
MultilingualE5Base |
768 | 100+ | High-quality multilingual |
MultilingualE5Large |
1024 | 100+ | Best multilingual quality |
// For fast, general purpose English text
FastEmbedModel::BGESmallENV15
// For balanced performance and quality
FastEmbedModel::BGEBaseENV15
// For highest quality English embeddings
FastEmbedModel::BGELargeENV15
// For multilingual applications
FastEmbedModel::MultilingualE5Small
// For real-time applications
FastEmbedModel::AllMiniLML6V2
use lumosai_vector_fastembed::FastEmbedConfigBuilder;
let config = FastEmbedConfigBuilder::new()
.max_batch_size(256) // Maximum texts per batch
.show_download_progress(true) // Show model download progress
.num_threads(4) // Number of processing threads
.cache_dir("/path/to/cache") // Model cache directory
.build();
| Model | Single | Batch (256) | Memory Usage |
|---|---|---|---|
| BGE Small | 50 | 800 | ~500MB |
| BGE Base | 30 | 500 | ~1GB |
| BGE Large | 20 | 300 | ~2GB |
| MiniLM L6 | 80 | 1200 | ~300MB |
Benchmarks on Intel i7-10700K, 32GB RAM
use lumosai_vector_fastembed::{FastEmbedProvider, FastEmbedModel};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let provider = FastEmbedProvider::with_model(
FastEmbedModel::MultilingualE5Small
).await?;
let multilingual_texts = vec![
"Hello, how are you?".to_string(), // English
"Hola, ΒΏcΓ³mo estΓ‘s?".to_string(), // Spanish
"Bonjour, comment allez-vous?".to_string(), // French
"δ½ ε₯½οΌδ½ ε₯½εοΌ".to_string(), // Chinese
];
let embeddings = provider.embed_batch(&multilingual_texts).await?;
// Calculate cross-language similarity
let similarity = cosine_similarity(&embeddings[0], &embeddings[1]);
println!("English-Spanish similarity: {:.3}", similarity);
Ok(())
}
use lumosai_vector_fastembed::{FastEmbedProvider, FastEmbedModel};
async fn semantic_search() -> Result<(), Box<dyn std::error::Error>> {
let provider = FastEmbedProvider::with_model(FastEmbedModel::BGESmallENV15).await?;
// Index documents
let documents = vec![
"Machine learning is a subset of AI",
"Deep learning uses neural networks",
"Natural language processing handles text",
"Computer vision processes images",
];
let doc_embeddings = provider.embed_batch(&documents.iter().map(|s| s.to_string()).collect::<Vec<_>>()).await?;
// Search query
let query = "artificial intelligence algorithms";
let query_embedding = provider.embed_text(query).await?;
// Find most similar document
let mut similarities = Vec::new();
for (i, doc_emb) in doc_embeddings.iter().enumerate() {
let sim = cosine_similarity(&query_embedding, doc_emb);
similarities.push((i, sim));
}
similarities.sort_by(|a, b| b.1.partial_cmp(&a.1).unwrap());
println!("Most similar: {} (similarity: {:.3})",
documents[similarities[0].0], similarities[0].1);
Ok(())
}
Run the included examples:
# Basic embedding generation
cargo run --example basic_embedding
# Batch processing optimization
cargo run --example batch_embedding
# Vector search and similarity
cargo run --example vector_search
use lumosai_vector_fastembed::{FastEmbedProvider, FastEmbedModel};
use lumosai_vector_core::traits::VectorStorage;
// Use with any LumosAI vector storage backend
let embedding_provider = FastEmbedProvider::with_model(FastEmbedModel::BGESmallENV15).await?;
let vector_storage = /* your vector storage implementation */;
// The embedding provider implements the EmbeddingModel trait
// and can be used with any LumosAI vector storage backend
Contributions are welcome! Please see our Contributing Guide for details.
This project is licensed under the MIT License - see the LICENSE file for details.