fix: align HF embeddings provider with batch embeddings interface

The batch embeddings refactor (PR #668) changed the EmbeddingsRequest
schema from `text: str` to `texts: list[str]` and updated the base
class to call `on_embeddings(request.texts, model=model)`.

The Ollama and FastEmbed providers were updated to match, but the
HuggingFace provider was missed:

- Parameter was still named `text` (singular) instead of `texts`
- `embed_documents([text])` wrapped the already-list input in another
  list, causing `embed_documents([["text1", "text2"]])` — a list
  containing a list instead of a list of strings

This produces:
  AttributeError: 'list' object has no attribute 'replace'

Fix aligns the HF provider with Ollama/FastEmbed:
- Rename param `text` → `texts`
- Remove redundant `[text]` wrapping
- Add empty-list guard (consistent with other providers)
This commit is contained in:
Azizultra32 2026-03-24 16:26:04 -07:00
parent d30857b5c3
commit b9a0bc4bf2

View file

@ -45,14 +45,17 @@ class Processor(EmbeddingsService):
else:
logger.debug(f"Using cached model: {model_name}")
async def on_embeddings(self, text, model=None):
async def on_embeddings(self, texts, model=None):
if not texts:
return []
use_model = model or self.default_model
# Reload model if it has changed
self._load_model(use_model)
embeds = self.embeddings.embed_documents([text])
embeds = self.embeddings.embed_documents(texts)
logger.debug("Embeddings generation complete")
return embeds