aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pplx_embed.c26
-rw-r--r--pplx_embed_mlx.c23
2 files changed, 48 insertions, 1 deletions
diff --git a/pplx_embed.c b/pplx_embed.c
index 1acd06f..c06d35d 100644
--- a/pplx_embed.c
+++ b/pplx_embed.c
@@ -135,6 +135,23 @@ static float *malloc_floats(size_t count)
return (float *)malloc(bytes);
}
+static int model_dir_has_file(const char *model_dir, const char *rel)
+{
+ char path[1024];
+ int n = snprintf(path, sizeof(path), "%s/%s", model_dir, rel);
+ if (n < 0 || (size_t)n >= sizeof(path)) return 0;
+ FILE *f = fopen(path, "rb");
+ if (!f) return 0;
+ fclose(f);
+ return 1;
+}
+
+static int model_dir_has_late_projection(const char *model_dir)
+{
+ return model_dir_has_file(model_dir, "1_Dense/config.json") &&
+ model_dir_has_file(model_dir, "1_Dense/model.safetensors");
+}
+
static int realloc_floats_2d(float **ptr, int rows, int cols)
{
if (rows < 0 || cols < 0) return -1;
@@ -574,8 +591,15 @@ static int ensure_offsets(pplx_workspace_t *ws, int batch)
* ======================================================================== */
static pplx_model_t *model_load_range(const char *model_dir,
- int layer_start, int layer_end)
+ int layer_start, int layer_end)
{
+ if (model_dir_has_late_projection(model_dir)) {
+ fprintf(stderr, "pplx_model_load: late-interaction models require "
+ "token-level MaxSim support and are not valid pooled "
+ "embedding models yet\n");
+ return NULL;
+ }
+
pplx_model_t *model = (pplx_model_t *)calloc(1, sizeof(pplx_model_t));
if (!model) return NULL;
diff --git a/pplx_embed_mlx.c b/pplx_embed_mlx.c
index 7bda478..85cf75e 100644
--- a/pplx_embed_mlx.c
+++ b/pplx_embed_mlx.c
@@ -341,6 +341,23 @@ static int mlx_parse_config(pplx_config_t *cfg, const char *model_dir)
return 0;
}
+static int mlx_model_dir_has_file(const char *model_dir, const char *rel)
+{
+ char path[1024];
+ int n = snprintf(path, sizeof(path), "%s/%s", model_dir, rel);
+ if (n < 0 || (size_t)n >= sizeof(path)) return 0;
+ FILE *f = fopen(path, "rb");
+ if (!f) return 0;
+ fclose(f);
+ return 1;
+}
+
+static int mlx_model_dir_has_late_projection(const char *model_dir)
+{
+ return mlx_model_dir_has_file(model_dir, "1_Dense/config.json") &&
+ mlx_model_dir_has_file(model_dir, "1_Dense/model.safetensors");
+}
+
static pplx_mlx_options_t normalize_mlx_options(const pplx_mlx_options_t *opts)
{
pplx_mlx_options_t out = {0};
@@ -374,6 +391,12 @@ static pplx_mlx_ctx_t *mlx_load_range(const char *model_dir,
{
pplx_mlx_options_t options = normalize_mlx_options(opts);
if (options.quantize_bits < 0) return NULL;
+ if (mlx_model_dir_has_late_projection(model_dir)) {
+ fprintf(stderr, "mlx: late-interaction models require token-level "
+ "MaxSim support and are not valid pooled embedding models "
+ "yet\n");
+ return NULL;
+ }
pplx_mlx_ctx_t *ctx = calloc(1, sizeof(pplx_mlx_ctx_t));
if (!ctx) return NULL;