A semantic image search engine built with Weaviate and Node.js that uses vector embeddings to find visually similar images.
- 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
- Node.js 18+ (for top-level await support)
- Docker and Docker Compose
- Images to search through (place in
./img/directory)
-
Clone the repository
git clone <your-repo-url> cd image_search_engine
-
Install dependencies
npm install
-
Start Weaviate services
docker-compose up -d
-
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
- Place your images in the
./img/directory - Run the indexing script:
node index.js
This will:
- Create the
Memeclass schema (if it doesn't exist) - Process all images in the
./img/directory - Store them as vector embeddings in Weaviate
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:
- Replace
test2.jpegwith your query image - Run:
node index.js - The most similar image will be saved as
result.jpg
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
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
- Weaviate: Main vector database (port 8080)
- img2vec-neural: ResNet50-based image vectorization service
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);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();-
"Class already exists" error
- This is normal on subsequent runs
- The script automatically handles this case
-
"ENOENT: no such file or directory"
- Ensure your query image exists in the project root
- Check that the
./img/directory contains images to index
-
Connection refused
- Make sure Docker services are running:
docker-compose up -d - Wait for services to fully start (can take 1-2 minutes)
- Make sure Docker services are running:
-
Module not found errors
- Run
npm installto install dependencies - Ensure you're using Node.js 18+ for ES modules support
- Run
# Check if containers are running
docker-compose ps
# View Weaviate logs
docker-compose logs weaviate
# View img2vec logs
docker-compose logs i2v-neural- weaviate-ts-client: Official Weaviate TypeScript/JavaScript client
- Node.js fs module: For file system operations
ISC
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request