| Crates.io | embedcache |
| lib.rs | embedcache |
| version | 0.1.0 |
| created_at | 2025-08-21 15:34:30.896013+00 |
| updated_at | 2025-08-21 15:34:30.896013+00 |
| description | High-performance text embedding service with caching capabilities |
| homepage | https://github.com/sokratis-xyz/embedcache |
| repository | https://github.com/sokratis-xyz/embedcache |
| max_upload_size | |
| id | 1804969 |
| size | 198,528 |
EmbedCache is a high-performance Rust library for generating text embeddings with built-in caching capabilities. It provides both a library interface for direct integration into your Rust projects and a REST API service for standalone deployment.
The library is designed to make it easy to generate high-quality embeddings for text data while minimizing computational costs through intelligent caching. Whether you're building a search engine, recommendation system, or any application that requires text embeddings, EmbedCache can help you do it efficiently.
EmbedCache solves the common problem of repeatedly computing embeddings for the same text data. It provides:
EmbedCache can be used in two primary ways:
The library handles all the complexity of model management, text chunking, embedding generation, and caching, allowing you to focus on building your application.
Add this to your Cargo.toml:
[dependencies]
embedcache = "0.1.0"
Or to install the embedcache binary directly from crates.io:
cargo install embedcache
Here's a simple example of using EmbedCache as a library in your Rust project:
use embedcache::{FastEmbedder, Embedder, get_embedding_model};
use fastembed::{TextEmbedding, InitOptions, EmbeddingModel};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize a model
let model = TextEmbedding::try_new(InitOptions {
model_name: EmbeddingModel::BGESmallENV15,
show_download_progress: true,
..Default::default()
})?;
// Create an embedder
let embedder = FastEmbedder { options: InitOptions::new(EmbeddingModel::BGESmallENV15) };
// Texts to embed
let texts = vec![
"This is an example sentence.".to_string(),
"Another example sentence for embedding.".to_string(),
];
// Generate embeddings
let embeddings = embedder.embed(&texts).await?;
println!("Generated {} embeddings", embeddings.len());
for (i, embedding) in embeddings.iter().enumerate() {
println!("Text {}: First 5 embedding values: {:?}", i, &embedding[..5.min(embedding.len())]);
}
Ok(())
}
To run the standalone service:
git clone https://github.com/sokratis-xyz/embedcache.git
cd embedcache
.env file with your configuration:SERVER_HOST=127.0.0.1
SERVER_PORT=8081
DB_PATH=cache.db
DB_JOURNAL_MODE=wal
ENABLED_MODELS=BGESmallENV15,AllMiniLML6V2
cargo build --release
cargo run --release
The server will start at http://127.0.0.1:8081 (or your configured host/port).
You can also run the installed binary directly:
embedcache
EmbedCache can also be used as a library in your own Rust projects. Add this to your Cargo.toml:
[dependencies]
embedcache = "0.1.0" # Use the latest version from crates.io
Then you can use the library functions in your code:
use embedcache::{embed_text, Config};
// Use the functions as needed
When running the embedcache service, the following endpoints are available:
POST /v1/embedGenerate embeddings for a list of text strings.
Request body:
{
"text": ["your text here", "another text"],
"config": {
"chunking_type": "words",
"chunking_size": 512,
"embedding_model": "BGESmallENV15"
}
}
POST /v1/processProcess a URL by extracting content, chunking, and generating embeddings.
Request body:
{
"url": "https://example.com",
"config": {
"chunking_type": "words",
"chunking_size": 512,
"embedding_model": "BGESmallENV15"
}
}
GET /v1/paramsList supported chunking types and embedding models.
See the examples directory for more detailed usage examples:
When running as a service, embedcache can be configured through environment variables:
| Environment Variable | Default | Description |
|---|---|---|
| SERVER_HOST | 127.0.0.1 | Server host address |
| SERVER_PORT | 8081 | Server port |
| DB_PATH | cache.db | SQLite database path |
| DB_JOURNAL_MODE | wal | SQLite journal mode (wal/truncate/persist) |
| ENABLED_MODELS | AllMiniLML6V2 | Comma-separated list of enabled models |
The service supports various embedding models including:
For a complete list when running as a service, check the /v1/params endpoint.
When using as a library, you can use any model supported by the fastembed crate.
When running as a service, API documentation is available at:
/swagger/redoc/rapidoc/openapi.jsonFor detailed documentation on using EmbedCache as a library, you can generate the Rust documentation:
cargo doc --open
This will open the documentation in your browser, showing all public APIs and usage examples.
EmbedCache provides a modular approach to text chunking through the ContentChunker trait. You can implement custom chunking strategies by implementing this trait:
use embedcache::{ContentChunker, AppState};
use async_trait::async_trait;
struct MyCustomChunker;
#[async_trait]
impl ContentChunker for MyCustomChunker {
async fn chunk(&self, content: &str, size: usize) -> Vec<String> {
// Your custom chunking logic here
vec![content.to_string()] // Simplified example
}
}
// Then register it with the AppState
// let mut chunkers = HashMap::new();
// chunkers.insert("my-custom-chunker".to_string(), Box::new(MyCustomChunker));
This allows you to easily extend the library with your own chunking algorithms while maintaining compatibility with the rest of the system.
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)