C API reference · Kjarni 0.2.8

image

kjarni_image_index_new

enum KjarniErrorCode kjarni_image_index_new(const char *model_dir, struct KjarniImageIndex **out);

Loads CLIP from a model directory, as kjarni model download leaves it. A null model_dir uses the default model, clip-vit-base-32, downloading it on first use, the same as every other capability.

Safety model_dir must be null or a valid NUL-terminated path. out must be a valid pointer to write the handle into.

kjarni_image_index_free

void kjarni_image_index_free(struct KjarniImageIndex *index);

Frees an image index.

Safety index must be null, or a handle from kjarni_image_index_new that has not already been freed.

kjarni_image_index_add

enum KjarniErrorCode kjarni_image_index_add(struct KjarniImageIndex *index, const char *path);

Embeds one image file and adds or replaces it.

Safety Both pointers must be valid; path must be NUL-terminated.

kjarni_image_index_add_directory

enum KjarniErrorCode kjarni_image_index_add_directory(struct KjarniImageIndex *index, const char *dir, struct KjarniScanReport *report);

Walks a directory and indexes every image in it.

Safety index and dir must be valid; dir must be NUL-terminated. report may be null if the counts are not wanted.

enum KjarniErrorCode kjarni_image_index_search(const struct KjarniImageIndex *index, const char *query, uintptr_t top_k, struct KjarniImageResults *out);

Ranks indexed images against a description.

Scores are cosine similarities and are small in absolute terms even for a good match, typically 0.2 to 0.35. Only the ordering is meaningful.

Safety All pointers must be valid; query must be NUL-terminated. The result must be released with [kjarni_image_results_free].

kjarni_image_results_free

void kjarni_image_results_free(struct KjarniImageResults results);

Frees a result list and every path in it.

Safety results must come from kjarni_image_index_search and be freed once.

kjarni_image_index_save

enum KjarniErrorCode kjarni_image_index_save(const struct KjarniImageIndex *index, const char *path);

Writes the vectors to path. The images stay where they are.

Safety Both pointers must be valid; path must be NUL-terminated.

kjarni_image_index_load

enum KjarniErrorCode kjarni_image_index_load(struct KjarniImageIndex *index, const char *path, uintptr_t *count);

Loads previously computed vectors, leaving the models as they are.

Refuses an index whose vectors are the wrong width, which means it was built with a different checkpoint and cannot be compared against this one.

Safety Both pointers must be valid; path must be NUL-terminated. count may be null.

kjarni_image_index_len

uintptr_t kjarni_image_index_len(const struct KjarniImageIndex *index);

How many images are indexed.

Safety index must be null or a live handle.

Kjarni runs the same engine on every platform: