Return an empty array when request en empty embedding
This commit is contained in:
parent
57e86d00fd
commit
55dc4bbdd2
4 changed files with 8 additions and 0 deletions
|
|
@ -7,6 +7,8 @@ from haiku.rag.embeddings.base import EmbedderBase
|
||||||
class Embedder(EmbedderBase):
|
class Embedder(EmbedderBase):
|
||||||
async def embed(self, text: str | list[str]) -> list[float] | list[list[float]]:
|
async def embed(self, text: str | list[str]) -> list[float] | list[list[float]]:
|
||||||
client = AsyncOpenAI(base_url=f"{Config.OLLAMA_BASE_URL}/v1", api_key="dummy")
|
client = AsyncOpenAI(base_url=f"{Config.OLLAMA_BASE_URL}/v1", api_key="dummy")
|
||||||
|
if not text:
|
||||||
|
return []
|
||||||
response = await client.embeddings.create(
|
response = await client.embeddings.create(
|
||||||
model=self._model,
|
model=self._model,
|
||||||
input=text,
|
input=text,
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ from haiku.rag.embeddings.base import EmbedderBase
|
||||||
class Embedder(EmbedderBase):
|
class Embedder(EmbedderBase):
|
||||||
async def embed(self, text: str | list[str]) -> list[float] | list[list[float]]:
|
async def embed(self, text: str | list[str]) -> list[float] | list[list[float]]:
|
||||||
client = AsyncOpenAI()
|
client = AsyncOpenAI()
|
||||||
|
if not text:
|
||||||
|
return []
|
||||||
response = await client.embeddings.create(
|
response = await client.embeddings.create(
|
||||||
model=self._model,
|
model=self._model,
|
||||||
input=text,
|
input=text,
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ class Embedder(EmbedderBase):
|
||||||
client = AsyncOpenAI(
|
client = AsyncOpenAI(
|
||||||
base_url=f"{Config.VLLM_EMBEDDINGS_BASE_URL}/v1", api_key="dummy"
|
base_url=f"{Config.VLLM_EMBEDDINGS_BASE_URL}/v1", api_key="dummy"
|
||||||
)
|
)
|
||||||
|
if not text:
|
||||||
|
return []
|
||||||
response = await client.embeddings.create(
|
response = await client.embeddings.create(
|
||||||
model=self._model,
|
model=self._model,
|
||||||
input=text,
|
input=text,
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ try:
|
||||||
class Embedder(EmbedderBase):
|
class Embedder(EmbedderBase):
|
||||||
async def embed(self, text: str | list[str]) -> list[float] | list[list[float]]:
|
async def embed(self, text: str | list[str]) -> list[float] | list[list[float]]:
|
||||||
client = Client()
|
client = Client()
|
||||||
|
if not text:
|
||||||
|
return []
|
||||||
if isinstance(text, str):
|
if isinstance(text, str):
|
||||||
res = client.embed([text], model=self._model, output_dtype="float")
|
res = client.embed([text], model=self._model, output_dtype="float")
|
||||||
return res.embeddings[0] # type: ignore[return-value]
|
return res.embeddings[0] # type: ignore[return-value]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue