aboutsummaryrefslogtreecommitdiff
path: root/pplx_embed.c
diff options
context:
space:
mode:
authorOnur Gündüz <ogunduz@gmail.com>2026-06-03 11:52:09 +0200
committerOnur Gündüz <ogunduz@gmail.com>2026-06-14 08:27:03 +0200
commitcb6ae157a09b6794f5d6da27dbc97e0ad791a146 (patch)
tree6085cef187a3f326a257394517bf76192c742c2d /pplx_embed.c
parent7cc87daedf764da43c338ba1cba739bd6af6e950 (diff)
downloadffwd-cb6ae157a09b6794f5d6da27dbc97e0ad791a146.tar.gz
ffwd-cb6ae157a09b6794f5d6da27dbc97e0ad791a146.zip
late: add packed maxsim scoring
Diffstat (limited to 'pplx_embed.c')
-rw-r--r--pplx_embed.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/pplx_embed.c b/pplx_embed.c
index c4e92a0..35bd739 100644
--- a/pplx_embed.c
+++ b/pplx_embed.c
@@ -945,9 +945,7 @@ float pplx_late_maxsim(const float *query_vectors, int query_tokens,
float best = -FLT_MAX;
for (int di = 0; di < doc_tokens; di++) {
const float *d = doc_vectors + (size_t)di * dim;
- float dot = 0.0f;
- for (int k = 0; k < dim; k++)
- dot += q[k] * d[k];
+ float dot = qwen_dot_f32(q, d, dim);
if (dot > best) best = dot;
}
score += best;
@@ -955,6 +953,27 @@ float pplx_late_maxsim(const float *query_vectors, int query_tokens,
return score;
}
+int pplx_late_maxsim_batch(const float *query_vectors, int query_tokens,
+ const float *doc_vectors,
+ const int *doc_offsets, int docs,
+ int dim, float *scores)
+{
+ if (!query_vectors || !doc_vectors || !doc_offsets || !scores ||
+ query_tokens <= 0 || docs <= 0 || dim <= 0 || doc_offsets[0] != 0)
+ return -1;
+
+ for (int i = 0; i < docs; i++) {
+ int start = doc_offsets[i];
+ int end = doc_offsets[i + 1];
+ if (start < 0 || end <= start)
+ return -1;
+ scores[i] = pplx_late_maxsim(query_vectors, query_tokens,
+ doc_vectors + (size_t)start * dim,
+ end - start, dim);
+ }
+ return 0;
+}
+
size_t pplx_workspace_nbytes(const pplx_workspace_t *ws)
{
if (!ws) return 0;