C API reference · Kjarni 0.2.8
Types
KjarniErrorCode
typedef enum KjarniErrorCode {
/**
* Operation completed successfully
*/
KJARNI_ERROR_CODE_OK = 0,
/**
* Null pointer passed to function
*/
KJARNI_ERROR_CODE_NULL_POINTER = 1,
/**
* Invalid UTF-8 string
*/
KJARNI_ERROR_CODE_INVALID_UTF8 = 2,
/**
* Model not found in registry
*/
KJARNI_ERROR_CODE_MODEL_NOT_FOUND = 3,
/**
* Failed to load model
*/
KJARNI_ERROR_CODE_LOAD_FAILED = 4,
/**
* Inference operation failed
*/
KJARNI_ERROR_CODE_INFERENCE_FAILED = 5,
/**
* GPU not available
*/
KJARNI_ERROR_CODE_GPU_UNAVAILABLE = 6,
/**
* Invalid configuration
*/
KJARNI_ERROR_CODE_INVALID_CONFIG = 7,
/**
* Operation was cancelled
*/
KJARNI_ERROR_CODE_CANCELLED = 8,
/**
* Operation timed out
*/
KJARNI_ERROR_CODE_TIMEOUT = 9,
/**
* Stream has ended
*/
KJARNI_ERROR_CODE_STREAM_ENDED = 10,
/**
* A panic in the engine was caught at the ABI boundary. The library is in an
* unspecified state for the operation that failed; the handle itself remains
* valid to free. `kjarni_last_error_message` names the entry point.
*/
KJARNI_ERROR_CODE_PANIC = 11,
/**
* Unknown error
*/
KJARNI_ERROR_CODE_UNKNOWN = 255,
} KjarniErrorCode;
Error codes returned by Kjarni FFI functions.
KjarniDevice
typedef enum KjarniDevice {
/**
* Use CPU for inference
*/
KJARNI_DEVICE_CPU = 0,
/**
* Use GPU for inference
*/
KJARNI_DEVICE_GPU = 1,
} KjarniDevice;
Device selection for inference.
KjarniProgressStage
typedef enum KjarniProgressStage {
KJARNI_PROGRESS_STAGE_SCANNING = 0,
KJARNI_PROGRESS_STAGE_LOADING = 1,
KJARNI_PROGRESS_STAGE_EMBEDDING = 2,
KJARNI_PROGRESS_STAGE_WRITING = 3,
KJARNI_PROGRESS_STAGE_COMMITTING = 4,
KJARNI_PROGRESS_STAGE_SEARCHING = 5,
KJARNI_PROGRESS_STAGE_RERANKING = 6,
} KjarniProgressStage;
Progress stage enum for FFI
KjarniSearchMode
typedef enum KjarniSearchMode {
KJARNI_SEARCH_MODE_KEYWORD = 0,
KJARNI_SEARCH_MODE_SEMANTIC = 1,
KJARNI_SEARCH_MODE_HYBRID = 2,
} KjarniSearchMode;
KjarniCancelToken
typedef struct KjarniCancelToken KjarniCancelToken;
Cancellation token
KjarniChat
typedef struct KjarniChat KjarniChat;
Opaque handle to a Chat instance.
KjarniChatConversation
typedef struct KjarniChatConversation KjarniChatConversation;
Opaque handle to a stateful ChatConversation.
Owns the history and holds a raw pointer back to the parent Chat. The parent Chat must outlive this handle.
KjarniClassifier
typedef struct KjarniClassifier KjarniClassifier;
Opaque handle to a Classifier.
KjarniEmbedder
typedef struct KjarniEmbedder KjarniEmbedder;
Opaque handle to an Embedder instance.
KjarniImageIndex
typedef struct KjarniImageIndex KjarniImageIndex;
An image index with its models loaded.
KjarniIndexer
typedef struct KjarniIndexer KjarniIndexer;
Opaque handle to an Indexer instance.
Created via kjarni_indexer_new, must be freed via kjarni_indexer_free
KjarniReranker
typedef struct KjarniReranker KjarniReranker;
Opaque handle to a Reranker
KjarniSearcher
typedef struct KjarniSearcher KjarniSearcher;
KjarniSummarizer
typedef struct KjarniSummarizer KjarniSummarizer;
Opaque handle to a Summarizer.
KjarniTranscriber
typedef struct KjarniTranscriber KjarniTranscriber;
Opaque handle to a Transcriber.
KjarniTranslator
typedef struct KjarniTranslator KjarniTranslator;
Opaque handle to a Translator.
data
typedef struct KjarniFloatArray {
float *data;
Float array returned by FFI functions. Caller must free with kjarni_float_array_free.
data
typedef struct KjarniFloat2DArray {
float *data;
2D float array for batch results. Caller must free with kjarni_float_2d_array_free.
strings
typedef struct KjarniStringArray {
char **strings;
String array. Caller must free with kjarni_string_array_free.
device
typedef struct KjarniChatConfig {
/**
* Device to use (0 = CPU, 1 = GPU)
*/
enum KjarniDevice device;
Configuration for creating a Chat instance.
temperature
typedef struct KjarniGenerationConfig {
/**
* Sampling temperature. -1.0 = use default.
*/
float temperature;
Generation parameters. Use -1 sentinel values to keep model defaults.
user_data
typedef bool (*KjarniStreamCallbackFn)(const char *text, void *user_data);
Token callback for streaming. Return false to stop generation.
label
typedef struct KjarniClassResult {
char *label;
Single classification result (label + score).
results
typedef struct KjarniClassResults {
struct KjarniClassResult *results;
device
typedef struct KjarniClassifierConfig {
/**
* Device to use
*/
enum KjarniDevice device;
items
typedef struct KjarniClassBatch {
struct KjarniClassResults *items;
One [KjarniClassResults] per input text, in input order.
device
typedef struct KjarniEmbedderConfig {
/**
* Device to use (CPU or GPU)
*/
enum KjarniDevice device;
Configuration for creating an Embedder.
added
typedef struct KjarniScanReport {
uintptr_t added;
What a scan did. Files that could not be decoded are counted, not fatal: one truncated download should not abandon a scan of ten thousand photos.
path
typedef struct KjarniImageHit {
char *path;
One ranked image.
path is owned by this struct and freed by [kjarni_image_results_free].
hits
typedef struct KjarniImageResults {
struct KjarniImageHit *hits;
A ranked list, and how many images could not be read.
path
typedef struct KjarniIndexInfo {
/**
* Path to the index directory (must be freed)
*/
char *path;
Information about an existing index
device
typedef struct KjarniIndexerConfig {
/**
* Device to run embeddings on (CPU or GPU)
*/
enum KjarniDevice device;
Configuration for creating an Indexer
documents_indexed
typedef struct KjarniIndexStats {
/**
* Number of document chunks indexed (after splitting)
*/
uintptr_t documents_indexed;
stage
typedef struct KjarniProgress {
enum KjarniProgressStage stage;
Progress data passed to callbacks
user_data
typedef void (*KjarniProgressCallbackFn)(struct KjarniProgress progress, void *user_data);
Generic callback function pointer type for progress
index
typedef struct KjarniRerankResult {
uintptr_t index;
Single rerank result
results
typedef struct KjarniRerankResults {
struct KjarniRerankResult *results;
Array of rerank results
device
typedef struct KjarniRerankerConfig {
enum KjarniDevice device;
Configuration for Reranker
score
typedef struct KjarniSearchResult {
float score;
results
typedef struct KjarniSearchResults {
struct KjarniSearchResult *results;
mode
typedef struct KjarniSearchOptions {
int32_t mode;
device
typedef struct KjarniSearcherConfig {
enum KjarniDevice device;
device
typedef struct KjarniSummarizerConfig {
enum KjarniDevice device;
Configuration for a Summarizer.
device
typedef struct KjarniTranscriberConfig {
enum KjarniDevice device;
Configuration for a Transcriber.
start
typedef struct KjarniTranscriptionSegment {
/**
* Start, in seconds from the beginning of the audio.
*/
float start;
One timed piece of a transcript. text is owned by the enclosing
[KjarniTranscription].
text
typedef struct KjarniTranscription {
/**
* The whole transcript.
*/
char *text;
A transcript. Free with [kjarni_transcription_free].
device
typedef struct KjarniTranslatorConfig {
enum KjarniDevice device;
Configuration for a Translator.
Kjarni runs the same engine on every platform: