Handle emb correctly

This commit is contained in:
Nicolas Mowen
2026-03-08 07:23:28 -06:00
parent 471bef3984
commit ced2e31857
2 changed files with 9 additions and 1 deletions
+5 -1
View File
@@ -70,7 +70,11 @@ class GenAIEmbedding:
result = [] result = []
for emb in embeddings: 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:
if arr.size > EMBEDDING_DIM: if arr.size > EMBEDDING_DIM:
arr = arr[:EMBEDDING_DIM] arr = arr[:EMBEDDING_DIM]
+4
View File
@@ -254,6 +254,10 @@ class LlamaCppClient(GenAIClient):
logger.warning("llama.cpp embeddings item missing embedding field") logger.warning("llama.cpp embeddings item missing embedding field")
continue continue
arr = np.array(emb, dtype=np.float32) 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 orig_dim = arr.size
if orig_dim != EMBEDDING_DIM: if orig_dim != EMBEDDING_DIM:
if orig_dim > EMBEDDING_DIM: if orig_dim > EMBEDDING_DIM: