Skip to content

gunterja/image_search_engine

Repository files navigation

Image Search Engine

A semantic image search engine built with Weaviate and Node.js that uses vector embeddings to find visually similar images.

Features

  • Semantic Image Search: Find images based on visual similarity using neural networks
  • Vector Database: Powered by Weaviate with img2vec-neural module
  • Batch Processing: Automatically indexes all images in a directory
  • Base64 Encoding: Handles image data as base64 for storage and retrieval

Prerequisites

  • Node.js 18+ (for top-level await support)
  • Docker and Docker Compose
  • Images to search through (place in ./img/ directory)

Installation

  1. Clone the repository

    git clone <your-repo-url>
    cd image_search_engine
  2. Install dependencies

    npm install
  3. Start Weaviate services

    docker-compose up -d
  4. Wait for services to be ready

    Weaviate and the img2vec-neural module need a moment to start up. You can check if they're ready by running:

    node app.js

Usage

Adding Images to the Database

  1. Place your images in the ./img/ directory
  2. Run the indexing script:
    node index.js

This will:

  • Create the Meme class schema (if it doesn't exist)
  • Process all images in the ./img/ directory
  • Store them as vector embeddings in Weaviate

Searching for Similar Images

The search functionality is built into index.js. It uses test2.jpeg as the query image and finds the most similar image from the database.

To search with a different image:

  1. Replace test2.jpeg with your query image
  2. Run: node index.js
  3. The most similar image will be saved as result.jpg

Project Structure

image_search_engine/
├── img/                    # Directory containing images to index
├── index.js               # Main script for indexing and searching
├── app.js                 # Simple schema viewer
├── docker-compose.yml     # Weaviate and img2vec services
├── package.json          # Node.js dependencies
├── test.jpeg             # Sample query image
├── test2.jpeg            # Sample query image
└── result.jpg            # Output of similarity search

Configuration

Weaviate Schema

The project uses a Meme class with the following properties:

  • image: blob data type for storing base64 encoded images
  • text: string data type for image descriptions
  • vectorizer: img2vec-neural for generating image embeddings

Docker Services

  • Weaviate: Main vector database (port 8080)
  • img2vec-neural: ResNet50-based image vectorization service

API Examples

Check Schema

import weaviate from "weaviate-ts-client";

const client = weaviate.client({
    scheme: "http",
    host: "localhost:8080"
});

const schema = await client.schema.getter().do();
console.log(schema);

Search Similar Images

const queryImage = Buffer.from(readFileSync('./query.jpg')).toString('base64');

const result = await client.graphql.get()
    .withClassName('Meme')
    .withFields(['image', 'text'])
    .withNearImage({ image: queryImage })
    .withLimit(5)
    .do();

Troubleshooting

Common Issues

  1. "Class already exists" error

    • This is normal on subsequent runs
    • The script automatically handles this case
  2. "ENOENT: no such file or directory"

    • Ensure your query image exists in the project root
    • Check that the ./img/ directory contains images to index
  3. Connection refused

    • Make sure Docker services are running: docker-compose up -d
    • Wait for services to fully start (can take 1-2 minutes)
  4. Module not found errors

    • Run npm install to install dependencies
    • Ensure you're using Node.js 18+ for ES modules support

Checking Service Status

# Check if containers are running
docker-compose ps

# View Weaviate logs
docker-compose logs weaviate

# View img2vec logs  
docker-compose logs i2v-neural

Dependencies

  • weaviate-ts-client: Official Weaviate TypeScript/JavaScript client
  • Node.js fs module: For file system operations

License

ISC

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

About

Create basic image similarity search from Fireship tutorial

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors