bilberrydb
v1.0.3
Published
TypeScript/JavaScript SDK for BilberryDB vector search API
Downloads
9
Maintainers
Readme
BilberryDB - Image Search
Developer SDK for creating image search engines with BilberryDB.
What it does
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 database.
Installation
npm install bilberrydbGetting API Keys
You need API keys to use BilberryDB:
- Visit www.bilberrydb.com
- Go to API Key section
- Click Create New API Key
- Enter API Key Name (like "My image search project")
- Click Create Key
Setup
- Create a
.envfile in your project root:
BILBERRY_API_KEY=your_api_key_here
BILBERRY_API_ID=your_registered_email_here- Replace
your_api_key_herewith your actual API key - Replace
your_registered_email_herewith the email you used to register
Usage
import * as bilberrydb from 'bilberrydb';
import dotenv from 'dotenv';
dotenv.config();
async function searchSimilarImages() {
try {
// Check if API keys exist
if (!process.env.BILBERRY_API_KEY || !process.env.BILBERRY_API_ID) {
throw new Error('Missing API keys in .env file');
}
// Connect to BilberryDB
const client = bilberrydb.init({
api_key: process.env.BILBERRY_API_KEY,
api_id: process.env.BILBERRY_API_ID
});
// Search for similar images
const vec = client.get_vec();
const results = await vec.search("path/to/your/image.jpg", {
top_k: 5 // Get top 5 similar images
});
// Show results
console.log(`Found ${results.length} similar images:`);
results.forEach((result, index) => {
const filename = result.filename || result.file_name || `item_${result.id}`;
console.log(`${index + 1}. Image: ${filename}`);
console.log(` Similarity: ${result.similarity_score.toFixed(3)}`);
console.log(` File Type: ${result.file_type}`);
});
} catch (error) {
console.error(`Search failed: ${error.message}`);
}
}
// Run the search
searchSimilarImages();How to use
- Replace
"path/to/your/image.jpg"with the actual path to your image - Change
top_k: 5to get more or fewer results - Run your script:
node your-script.js
What you get back
Each result includes:
- filename: Name of the similar image
- similarity_score: How similar it is (higher = more similar)
- file_type: Type of image file (jpg, png, etc.)
- id: Unique ID of the image
Common issues
"Missing API keys": Make sure your .env file has the correct API key and API ID.
"Search failed": Check that:
- Your image path is correct
- Your API keys are valid
- You have internet connection
Requirements
- Node.js 14 or higher
- Valid BilberryDB account and API keys
License
Check the bilberrydb package license for details.
