C API reference · Kjarni 0.2.8
general
kjarni_init
enum KjarniErrorCode kjarni_init(void);
Initialize the Kjarni runtime. Optional - auto-initialized on first use.
kjarni_shutdown
void kjarni_shutdown(void);
Shutdown and cleanup. Call before process exit.
kjarni_version
const char *kjarni_version(void);
Get the library version string.
kjarni_float_array_free
void kjarni_float_array_free(struct KjarniFloatArray arr);
Free a float array allocated by Kjarni.
Safety
arrmust be a value returned by a search/embedding call, passed here exactly once. Its buffers are invalid to read afterwards.
kjarni_float_2d_array_free
void kjarni_float_2d_array_free(struct KjarniFloat2DArray arr);
Free a 2D float array allocated by Kjarni.
Safety
arrmust be a value returned bykjarni_embedder_encode_batch, passed here exactly once. Its buffers are invalid to read afterwards.
kjarni_string_free
void kjarni_string_free(char *s);
Free a string allocated by Kjarni.
Safety
smust be a valid, writable pointer to astd::ffi::c_char. It is written on both success and failure, and any buffers it receives are owned by the caller.
kjarni_string_array_free
void kjarni_string_array_free(struct KjarniStringArray arr);
Free a string array allocated by Kjarni.
Safety
arrmust be a value returned by a call that returns one, passed here exactly once. Its buffers are invalid to read afterwards.
kjarni_cosine_similarity
float kjarni_cosine_similarity(const float *a, const float *b, uintptr_t len);
Safety
amust be null, or point to at leastlenreadablef32values.bmust be null, or point to at leastlenreadablef32values.
kjarni_generation_config_default
struct KjarniGenerationConfig kjarni_generation_config_default(void);
Get default generation configuration (all sentinels = use model defaults).
kjarni_class_results_free
void kjarni_class_results_free(struct KjarniClassResults results);
Safety
resultsmust be a value returned bykjarni_classifier_classify, passed here exactly once. Its buffers are invalid to read afterwards.
kjarni_class_batch_free
void kjarni_class_batch_free(struct KjarniClassBatch batch);
Frees a batch from kjarni_classifier_classify_batch and every result in it.
Safety
batch must be a value returned by kjarni_classifier_classify_batch, passed
here exactly once.
kjarni_error_code_to_string
const char *kjarni_error_code_to_string(enum KjarniErrorCode err);
kjarni_error_name
const char *kjarni_error_name(enum KjarniErrorCode err);
Get the name of an error code as a C string.
kjarni_last_error_message
const char *kjarni_last_error_message(void);
Get the last error message. Returns NULL if no error.
kjarni_clear_error
void kjarni_clear_error(void);
Clear the last error.
kjarni_sigmoid
float kjarni_sigmoid(float x);
Puts a cross-encoder logit on a 0..1 scale.
Exported rather than reimplemented per binding. It is one line of arithmetic,
but the branch is not decoration: exp(-x) overflows to infinity for a large
negative x and inf / inf is NaN, which sorts unpredictably. A binding author
writing the obvious one-liner gets a function that passes every value they try
and returns NaN in production, so there is one implementation and it lives
here.
Monotonic, so ranking is identical either way; only the numbers move. Scores stay logits by default because that is what PyTorch returns.
kjarni_rerank_results_free
void kjarni_rerank_results_free(struct KjarniRerankResults results);
Free rerank results
Safety
resultsmust be a value returned by a rerank call, passed here exactly once. Its buffers are invalid to read afterwards.
kjarni_transcription_free
void kjarni_transcription_free(struct KjarniTranscription transcription);
Free a transcript and every string in it.
Safety
transcriptionmust be a value written by a transcribe call, passed here exactly once.
Kjarni runs the same engine on every platform: