aboutsummaryrefslogtreecommitdiff
path: root/pplx_embed_mlx.h
diff options
context:
space:
mode:
authorOnur Gündüz <ogunduz@gmail.com>2026-06-03 11:45:40 +0200
committerOnur Gündüz <ogunduz@gmail.com>2026-06-14 08:27:03 +0200
commit7cc87daedf764da43c338ba1cba739bd6af6e950 (patch)
tree3a91568fc15f98cdcbfa60156019f52cb19667c9 /pplx_embed_mlx.h
parent87e3a31403015138b2a4eb02e6ee00453357001d (diff)
downloadffwd-7cc87daedf764da43c338ba1cba739bd6af6e950.tar.gz
ffwd-7cc87daedf764da43c338ba1cba739bd6af6e950.zip
late: add mlx token vector support
Diffstat (limited to 'pplx_embed_mlx.h')
-rw-r--r--pplx_embed_mlx.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/pplx_embed_mlx.h b/pplx_embed_mlx.h
index 9b341e0..a7cb749 100644
--- a/pplx_embed_mlx.h
+++ b/pplx_embed_mlx.h
@@ -13,6 +13,7 @@
/* Opaque MLX model context */
typedef struct pplx_mlx_ctx pplx_mlx_ctx_t;
+typedef struct pplx_mlx_late_ctx pplx_mlx_late_ctx_t;
typedef struct {
int quantize_bits; /* 0 disables; currently 8 */
@@ -41,6 +42,29 @@ pplx_mlx_ctx_t *pplx_mlx_load_slice_with_options(
void pplx_mlx_free(pplx_mlx_ctx_t *ctx);
/*
+ * Late-interaction MLX path. This is separate from pooled embeddings because
+ * late snapshots produce one projected token vector per input token for MaxSim
+ * scoring, not one pooled document vector.
+ */
+pplx_mlx_late_ctx_t *pplx_mlx_late_load(const char *model_dir);
+pplx_mlx_late_ctx_t *pplx_mlx_late_load_with_options(
+ const char *model_dir, const pplx_mlx_options_t *opts);
+void pplx_mlx_late_free(pplx_mlx_late_ctx_t *ctx);
+
+const pplx_config_t *pplx_mlx_late_config(const pplx_mlx_late_ctx_t *ctx);
+int pplx_mlx_late_token_dim(const pplx_mlx_late_ctx_t *ctx);
+
+/*
+ * Encode token_ids into out_vectors[n_tokens, token_dim].
+ *
+ * If normalize is non-zero, every token vector is L2-normalized on device
+ * before copying back to CPU memory.
+ */
+int pplx_mlx_late_encode_tokens(pplx_mlx_late_ctx_t *ctx,
+ const int *token_ids, int n_tokens,
+ int normalize, float *out_vectors);
+
+/*
* Compute embedding for token_ids[0..n_tokens-1].
* Returns malloc'd float[hidden_size] (caller frees). NULL on error.
*/