Skip to content

API reference

This page is intentionally simple for now. Replace with generated stubs later if preferred.

ImageHashIndex

Main in-memory index.

php
$index = new ImageHashIndex();

add()

Add a precomputed hash.

php
$index->add(string $id, string $hash): void

Example:

php
$index->add('image-1', 'f123456789abcdef');

Search by hash.

php
$index->search(string $hash, int $maxDistance = 10, int $limit = 10): array

Example:

php
$matches = $index->search('f123456789abcdef', maxDistance: 5, limit: 20);

save()

Save the index to disk.

php
$index->save(string $path): void

load()

Load a saved index.

php
$index = ImageHashIndex::load(string $path);

Result shape

Expected result shape:

php
[
    [
        'id' => 'image-1',
        'distance' => 0,
    ],
    [
        'id' => 'image-2',
        'distance' => 2,
    ],
]

Native tools, weird experiments, and practical performance work.