From cd91917216b1b273c8c5fc879a63cacb2d1b6ff8 Mon Sep 17 00:00:00 2001 From: zzstoatzz Date: Sat, 21 Dec 2024 18:22:50 -0600 Subject: [PATCH] fix vector dimensions --- src/raggy/vectorstores/tpuf.py | 16 ++++++++++------ uv.lock | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/raggy/vectorstores/tpuf.py b/src/raggy/vectorstores/tpuf.py index d9d4206..26bee60 100644 --- a/src/raggy/vectorstores/tpuf.py +++ b/src/raggy/vectorstores/tpuf.py @@ -79,25 +79,29 @@ def upsert( attributes: dict[str, list[str | int | None]] | None = None, ): attributes = attributes or {} - _vectors = vectors or [] if documents is None and vectors is None: raise ValueError("Either `documents` or `vectors` must be provided.") if documents: ids = [document.id for document in documents] - _vectors: list[list[float]] = run_coro_as_sync( - create_openai_embeddings([document.text for document in documents]) + texts = [document.text for document in documents] + embeddings = run_coro_as_sync(create_openai_embeddings(texts)) + assert embeddings is not None and isinstance( + embeddings, list + ), "embeddings cannot be none" + vectors = ( + [embeddings] if not isinstance(embeddings[0], list) else embeddings ) - assert _vectors is not None if attributes.get("text"): raise ValueError( "The `text` attribute is reserved and cannot be used as a custom attribute." ) - attributes |= {"text": [document.text for document in documents]} + attributes |= {"text": [str(t) for t in texts]} assert ids is not None, "ids cannot be none" - self.ns.upsert(ids=ids, vectors=_vectors, attributes=attributes) # type: ignore + assert vectors is not None, "vectors cannot be none" + self.ns.upsert(ids=ids, vectors=vectors, attributes=attributes) # type: ignore def query( self, diff --git a/uv.lock b/uv.lock index 115307d..2f40d14 100644 --- a/uv.lock +++ b/uv.lock @@ -3161,7 +3161,7 @@ wheels = [ [[package]] name = "raggy" -version = "0.2.5.dev10+g7391dc2.d20241221" +version = "0.2.5.dev11+g607db51" source = { editable = "." } dependencies = [ { name = "aiofiles" },