Skip to content

Commit

Permalink
Converting add_texts_and_embeddings to async (#778)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
Co-authored-by: James Braza <[email protected]>
  • Loading branch information
3 people authored Dec 30, 2024
1 parent 4f4d8e3 commit 525bb32
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion paperqa/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ async def _build_texts_index(self, embedding_model: EmbeddingModel) -> None:
strict=True,
):
t.embedding = t_embedding
self.texts_index.add_texts_and_embeddings(texts)
await self.texts_index.add_texts_and_embeddings(texts)

async def retrieve_texts(
self,
Expand Down
11 changes: 6 additions & 5 deletions paperqa/llms.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def __len__(self) -> int:
return len(self.texts_hashes)

@abstractmethod
def add_texts_and_embeddings(self, texts: Iterable[Embeddable]) -> None:
async def add_texts_and_embeddings(self, texts: Iterable[Embeddable]) -> None:
"""Add texts and their embeddings to the store."""
self.texts_hashes.update(hash(t) for t in texts)

@abstractmethod
Expand Down Expand Up @@ -198,8 +199,8 @@ def clear(self) -> None:
self._embeddings_matrix = None
self._texts_filter = None

def add_texts_and_embeddings(self, texts: Iterable[Embeddable]) -> None:
super().add_texts_and_embeddings(texts)
async def add_texts_and_embeddings(self, texts: Iterable[Embeddable]) -> None:
await super().add_texts_and_embeddings(texts)
self.texts.extend(texts)
self._embeddings_matrix = np.array([t.embedding for t in self.texts])

Expand Down Expand Up @@ -328,8 +329,8 @@ def clear(self) -> None:
)
self._point_ids = None

def add_texts_and_embeddings(self, texts: Iterable[Embeddable]) -> None:
super().add_texts_and_embeddings(texts)
async def add_texts_and_embeddings(self, texts: Iterable[Embeddable]) -> None:
await super().add_texts_and_embeddings(texts)

texts_list = list(texts)

Expand Down

0 comments on commit 525bb32

Please sign in to comment.