C API reference · Kjarni 0.2.8

reranker

kjarni_reranker_config_default

struct KjarniRerankerConfig kjarni_reranker_config_default(void);

Get default reranker configuration

kjarni_reranker_new

enum KjarniErrorCode kjarni_reranker_new(const struct KjarniRerankerConfig *config, struct KjarniReranker **out);

Create a new Reranker

Safety

  • out must be null, or a live handle returned by kjarni_reranker_new that has not been freed.

kjarni_reranker_free

void kjarni_reranker_free(struct KjarniReranker *reranker);

Free a Reranker

Safety

  • reranker must be null, or a handle returned by kjarni_reranker_new that has not already been passed to this function. It is invalid to use afterwards.

kjarni_reranker_score

enum KjarniErrorCode kjarni_reranker_score(struct KjarniReranker *reranker, const char *query, const char *document, float *out);

Score a single query-document pair

Safety

  • reranker must be null, or a live handle returned by kjarni_reranker_new that has not been freed.
  • query must be null, or a valid pointer to a nul-terminated C string.
  • document must be null, or a valid pointer to a nul-terminated C string.
  • out must be a valid, writable pointer to a c_float. It is written on both success and failure, and any buffers it receives are owned by the caller.

kjarni_reranker_rerank

enum KjarniErrorCode kjarni_reranker_rerank(struct KjarniReranker *reranker, const char *query, const char *const *documents, uintptr_t num_docs, struct KjarniRerankResults *out);

Rerank documents by relevance to query

Safety

  • reranker must be null, or a live handle returned by kjarni_reranker_new that has not been freed.
  • query must be null, or a valid pointer to a nul-terminated C string.
  • documents must point to num_docs readable pointers, each null or a valid nul-terminated C string that stays valid for the call.
  • out must be a valid, writable pointer to a KjarniRerankResults. On KJARNI_OK it receives a value the caller owns and must release with the matching *_free; on failure it is either cleared or left unmodified, and must not be read.

kjarni_reranker_rerank_top_k

enum KjarniErrorCode kjarni_reranker_rerank_top_k(struct KjarniReranker *reranker, const char *query, const char *const *documents, uintptr_t num_docs, uintptr_t top_k, struct KjarniRerankResults *out);

Rerank and return top-k results

Safety

  • reranker must be null, or a live handle returned by kjarni_reranker_new that has not been freed.
  • query must be null, or a valid pointer to a nul-terminated C string.
  • documents must point to num_docs readable pointers, each null or a valid nul-terminated C string that stays valid for the call.
  • out must be a valid, writable pointer to a KjarniRerankResults. On KJARNI_OK it receives a value the caller owns and must release with the matching *_free; on failure it is either cleared or left unmodified, and must not be read.

Kjarni runs the same engine on every platform: