Crates.io | bilberrydb |
lib.rs | bilberrydb |
version | 0.1.1 |
created_at | 2025-08-31 13:19:30.986191+00 |
updated_at | 2025-08-31 13:31:21.449986+00 |
description | Developer SDK for creating image search engines, image classification models, image duplication recognition, and Visual recommender systems with BilberryDB. |
homepage | |
repository | https://bilberrydb.com |
max_upload_size | |
id | 1818546 |
size | 61,413 |
Developer SDK for creating image search engines, image classification models, image duplication recognition, and Visual recommender systems with BilberryDB.
This library helps you find images that look similar to a given image. Just provide an image path, and it will return the most similar images from your Bilberry Vector DB.
Add this to your Cargo.toml
:
[dependencies]
bilberrydb = "0.1.0"
tokio = { version = "1.0", features = ["full"] }
You need API keys to use BilberryDB:
.env
file in your project root:BILBERRY_API_KEY=your_api_key_here
BILBERRY_API_ID=your_registered_email_here
your_api_key_here
with your actual API keyyour_registered_email_here
with the email you used to registeruse bilberrydb::{init, BilberryConfig};
use dotenv::dotenv;
use std::env;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
dotenv().ok();
// Load API keys from environment variables
let api_key = env::var("BILBERRY_API_KEY")
.expect("Missing BILBERRY_API_KEY environment variable");
let api_id = env::var("BILBERRY_API_ID")
.expect("Missing BILBERRY_API_ID environment variable");
// Connect to BilberryDB
let client = init(BilberryConfig {
api_key,
api_id,
base_url: None,
})?;
// Search for similar images
let vec = client.get_vec();
let results = vec.search_by_path("./test-chair.jpg", Some(5)).await?;
// Show results
println!("Found {} similar images:", results.len());
for (index, result) in results.iter().enumerate() {
let filename = result.get_filename();
println!("{}. Image: {}", index + 1, filename);
println!(" Similarity: {:.3}", result.get_similarity_score());
println!(" File Type: {}", result.file_type);
}
Ok(())
}
use bilberrydb::{init, BilberryConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = init(BilberryConfig {
api_key: "your_api_key".to_string(),
api_id: "your_email@example.com".to_string(),
base_url: None,
})?;
// Read image data
let image_data = std::fs::read("path/to/your/image.jpg")?;
// Search using bytes
let vec = client.get_vec();
let results = vec.search_by_bytes(&image_data, Some(10)).await?;
for result in results {
println!("Similar image: {} (score: {:.3})",
result.get_filename(), result.similarity_score);
}
Ok(())
}
use bilberrydb::{init, BilberryConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = init(BilberryConfig {
api_key: "your_api_key".to_string(),
api_id: "your_email@example.com".to_string(),
base_url: None,
})?;
let vec = client.get_vec();
let items = vec.get_all_items(None).await?;
println!("Total items: {}", items.len());
for item in items {
println!("- {}: {} ({} bytes)",
item.id, item.filename, item.file_size);
}
Ok(())
}
"path/to/your/image.jpg"
with the actual path to your imageSome(5)
to get more or fewer resultscargo run
Each SearchResult
includes:
search_by_path(image_path, top_k)
- Search using file pathsearch_by_bytes(image_data, top_k)
- Search using image bytessearch_by_path_with_options(image_path, options)
- Advanced search with optionssearch_by_bytes_with_options(image_data, options)
- Advanced search with bytesget_all_items(content_type)
- Get all uploaded itemsdownload_file(item_id)
- Download a file by IDresult.get_filename()
- Get filename (handles both filename
and file_name
fields)The library uses Rust's Result
type for error handling:
match vec.search_by_path("image.jpg", Some(5)).await {
Ok(results) => {
// Handle successful results
for result in results {
println!("Found: {}", result.get_filename());
}
}
Err(e) => {
// Handle errors
eprintln!("Error: {}", e);
}
}
"Missing API keys": Make sure your environment variables are set correctly.
"Search failed": Check that:
"File not found": Make sure the image path exists and the file is accessible.
To run the examples:
# Set environment variables
export BILBERRY_API_KEY="your_api_key_here"
export BILBERRY_API_ID="your_email@example.com"
# Run the basic search example
cargo run --example basic_search
To run tests:
cargo test
MIT License - see LICENSE file for details.