Handle emb correctly

This commit is contained in:
Nicolas Mowen 2026-03-02 14:31:04 -07:00
parent ac63be9ea7
commit 334399a260
2 changed files with 9 additions and 1 deletions

View File

@ -70,7 +70,11 @@ class GenAIEmbedding:
result = []
for emb in embeddings:
arr = np.asarray(emb, dtype=np.float32).flatten()
arr = np.asarray(emb, dtype=np.float32)
if arr.ndim > 1:
# Some providers return token-level embeddings; pool to one vector.
arr = arr.mean(axis=0)
arr = arr.flatten()
if arr.size != EMBEDDING_DIM:
if arr.size > EMBEDDING_DIM:
arr = arr[:EMBEDDING_DIM]

View File

@ -254,6 +254,10 @@ class LlamaCppClient(GenAIClient):
logger.warning("llama.cpp embeddings item missing embedding field")
continue
arr = np.array(emb, dtype=np.float32)
if arr.ndim > 1:
# llama.cpp can return token-level embeddings; pool per item
arr = arr.mean(axis=0)
arr = arr.flatten()
orig_dim = arr.size
if orig_dim != EMBEDDING_DIM:
if orig_dim > EMBEDDING_DIM: