Image Similarity Search with LM-Kit.NET
🎯 Purpose of the Sample
This Image Similarity Search demo illustrates how developers can use the LM-Kit.NET SDK to efficiently identify visually similar images within a dataset. By converting images into embeddings (numerical representations of visual features), this sample demonstrates how to easily perform similarity searches, enabling applications like content recommendation, image categorization, product matching, and visual search enhancement.
The demo leverages the Embedder
and VectorSearch
classes, providing an intuitive and high-level API for generating and comparing image embeddings.
🚀 Problem Solved
Finding visually similar images manually is cumbersome and impractical at scale. LM-Kit's image similarity search solves this problem by:
- Automating image comparison using visual embeddings
- Quickly retrieving relevant matches from large image collections
- Reducing manual effort and significantly increasing accuracy
This empowers developers to build smarter applications that respond to visual input rapidly and precisely.
💻 Sample Application Description
This demo is a console-based application showcasing image embedding generation and vector-based similarity search:
- Embedding Generation: Images are processed through a pre-trained model, converting them into vector embeddings representing their visual characteristics.
- Data Storage: Generated embeddings are stored locally in a vector database (
collection.ds
), enabling quick similarity searches. - Similarity Search: When provided with a query image, the system computes its embedding and retrieves visually similar images from the stored embeddings based on cosine similarity scores.
✨ Key Features
- 🔍 Visual Search: Rapidly identify visually related images.
- 🖼️ Versatile Application: Suitable for product recommendations, content filtering, duplicate detection, etc.
- 🔗 High-Level API: Simple integration using
Embedder
andVectorSearch
. - ⚡ On-Device Processing: No external cloud services required, enhancing privacy and performance.
🧠 Supported Models
The sample supports image embedding models like:
- Nomic Embed Vision
- Other vision embedding models compatible with LM-Kit
🛠️ Getting Started
📋 Prerequisites
- .NET Framework 4.6.2 or .NET 6.0
📥 Download the Project
▶️ Running the Application
📂 Clone the repository:
git clone https://github.com/LM-Kit/lm-kit-net-samples.git
📁 Navigate to the project directory:
cd lm-kit-net-samples/console_net/image_similarity_search
🔨 Build and run the application:
dotnet build dotnet run
💡 Example Usage
Load Images into the Database:
- The demo pre-loads example images (
house1.jpg
,cat1.jpg
,dog1.jpg
, etc.) into the local embedding database.
- The demo pre-loads example images (
Perform a Similarity Search:
- Provide the path to a new query image (e.g.,
cat3.jpg
). - The demo calculates the visual embedding and retrieves the most visually similar images stored previously.
- Provide the path to a new query image (e.g.,
📌 Viewing Results
Output:
Top similar images:
===================================
cat2: score = 0.8869
cat1: score = 0.8748
dog2: score = 0.7374
...
This output ranks stored images by visual similarity, helping developers easily integrate advanced image-based search capabilities into their applications.