aboutsummaryrefslogtreecommitdiff
path: root/pplx_embed.h
diff options
context:
space:
mode:
authorOnur Gündüz <ogunduz@gmail.com>2026-06-03 11:32:31 +0200
committerOnur Gündüz <ogunduz@gmail.com>2026-06-14 08:27:03 +0200
commit87e3a31403015138b2a4eb02e6ee00453357001d (patch)
tree0d40f50c9e934c12718bdc6d31ced1bedc4fb7a0 /pplx_embed.h
parent9e27ca3b8632b69cf0d8d587cf5fb840b9ff863e (diff)
downloadffwd-87e3a31403015138b2a4eb02e6ee00453357001d.tar.gz
ffwd-87e3a31403015138b2a4eb02e6ee00453357001d.zip
late: add CPU token vectors and maxsim
Diffstat (limited to 'pplx_embed.h')
-rw-r--r--pplx_embed.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/pplx_embed.h b/pplx_embed.h
index 1137df5..294508f 100644
--- a/pplx_embed.h
+++ b/pplx_embed.h
@@ -43,6 +43,8 @@ typedef struct {
typedef struct pplx_model pplx_model_t;
typedef struct pplx_workspace pplx_workspace_t;
+typedef struct pplx_late_model pplx_late_model_t;
+typedef struct pplx_late_workspace pplx_late_workspace_t;
typedef struct {
const int *ids;
@@ -239,6 +241,39 @@ int pplx_l2_normalize(float *vec, int dim);
*/
float pplx_cosine_similarity(const float *a, const float *b, int dim);
+/*
+ * Late-interaction model API.
+ *
+ * A late model produces one 128D vector per retained token. The vectors are
+ * projected by the snapshot's 1_Dense head and L2-normalized per token by
+ * default, matching ColBERT/MaxSim scoring semantics.
+ */
+pplx_late_model_t *pplx_late_model_load(const char *model_dir);
+void pplx_late_model_free(pplx_late_model_t *model);
+
+pplx_late_workspace_t *pplx_late_workspace_new(const pplx_late_model_t *model);
+void pplx_late_workspace_free(pplx_late_workspace_t *ws);
+
+const pplx_config_t *pplx_late_model_config(const pplx_late_model_t *model);
+int pplx_late_model_token_dim(const pplx_late_model_t *model);
+
+/*
+ * Encode token_ids into out_vectors[n_tokens, token_dim].
+ *
+ * If normalize is non-zero, every non-zero token vector is L2-normalized.
+ */
+int pplx_late_model_encode_tokens(const pplx_late_model_t *model,
+ pplx_late_workspace_t *ws,
+ const int *token_ids, int n_tokens,
+ int normalize, float *out_vectors);
+
+/*
+ * Sum over query tokens of max dot product against document tokens.
+ */
+float pplx_late_maxsim(const float *query_vectors, int query_tokens,
+ const float *doc_vectors, int doc_tokens,
+ int dim);
+
/* Verbose level: 0=quiet, 1=info, 2=debug */
extern int pplx_verbose;
extern int qwen_verbose;