aboutsummaryrefslogtreecommitdiff
path: root/pplx_embed.c
diff options
context:
space:
mode:
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;