⚡ Rust Image Search
Source: examples/rust/image‑search
This guide demonstrates building an image-based similarity search application using the Rust SDK. It covers:
- Initializing
ahnlich-db
andahnlich-ai
stores - Ingesting image files as raw bytes into an AI Store
- Running similarity queries based on image embeddings
- Using metadata (e.g. tags) for filtering results
- Returning both vector similarity scores and original image references
🔧 What you’ll learn
- Setting up an AI Store via Rust client.
- Feeding images (byte streams) into the store.
- Querying the store with a new image file to retrieve visually similar results.
- Applying metadata filters (e.g.
tag == "nature"
). - Understanding handling of raw input retention for display.
💡 Highlighted snippet
let mut ai_client = AIClient::new("127.0.0.1:1370".to_string()).await?;
let tracing_id = None;
// create a store for images
ai_client.create_store(CreateStoreAI {
store: "image_store".to_string(),
index_model: AIModel::AllMiniLML6V2,
query_model: AIModel::AllMiniLML6V2,
predicates: Some(HashSet::from(["tag".to_string()])),
store_original: Some(true),
error_if_exists: Some(true),
}, tracing_id.clone()).await?;
// ingest image bytes with metadata
ai_client.set(SetAI {
store: "image_store".to_string(),
inputs: vec![
(StoreInput::RawBytes(img_bytes), HashMap::from([("tag".to_string(), "nature")]))
],
preprocess_action: Some(PreprocessAction::NoPreprocessing),
}, tracing_id.clone()).await?;
➕ Try it yourself
- Clone the example repository
- Launch
ahnlich-db
andahnlich-ai
locally via Docker or binaries - Modify the image folder path and metadata tags
- Build and run the Rust example app to visualize results