Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonauner committed Jan 30, 2024
1 parent cff1e1e commit 0d7e14c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
4 changes: 2 additions & 2 deletions libs/community/langchain_community/vectorstores/pinecone.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ def add_texts(
metadata[self._text_key] = text

if async_req:
# For loops to avoid memory issues and optimize when using HTTP based embeddings
# The first loop runs the embeddings, it benefits when using OpenAI embeddings
# For loops to avoid memory issues when using HTTP-based embeddings
# First loop runs embeddings, benefits when using OpenAI embeddings
# The second loops runs the pinecone upsert asynchronously.
for i in range(0, len(texts), embedding_chunk_size):
chunk_texts = texts[i : i + embedding_chunk_size]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import time
import uuid
from typing import TYPE_CHECKING, List, Generator
from typing import TYPE_CHECKING, Generator, List

import numpy as np
import pytest
Expand Down Expand Up @@ -36,13 +36,18 @@ def texts() -> Generator[List[str], None, None]:

yield [doc.page_content for doc in documents]


@pytest.fixture
def mock_pool_not_supported(mocker):
"""
This is the error thrown when multiprocessing is not supported.
See https://github.com/langchain-ai/langchain/issues/11168
"""
mocker.patch('multiprocessing.synchronize.SemLock.__init__', side_effect=OSError('OSError: [Errno 38] Function not implemented'))
mocker.patch(
"multiprocessing.synchronize.SemLock.__init__",
side_effect=OSError("OSError: [Errno 38] Function not implemented"),
)


def reset_pinecone() -> None:
assert os.environ.get("PINECONE_API_KEY") is not None
Expand Down Expand Up @@ -311,22 +316,25 @@ def test_from_texts_with_metadatas_benchmark(
query = "What did the president say about Ketanji Brown Jackson"
_ = docsearch.similarity_search(query, k=1, namespace=namespace_name)


@pytest.mark.usefixtures('mock_pool_not_supported')
def test_that_async_freq_uses_multiprocessing(self, embedding_openai: OpenAIEmbeddings) -> None:
@pytest.mark.usefixtures("mock_pool_not_supported")
def test_that_async_freq_uses_multiprocessing(
self, embedding_openai: OpenAIEmbeddings
) -> None:
with pytest.raises(OSError):
Pinecone.from_texts(
texts=["foo", "bar", "baz"] * 32,
embedding=embedding_openai,
index_name=index_name,
async_req=True,
)

@pytest.mark.usefixtures('mock_pool_not_supported')
def test_that_async_freq_false_enabled_singlethreading(self, embedding_openai: OpenAIEmbeddings) -> None:

@pytest.mark.usefixtures("mock_pool_not_supported")
def test_that_async_freq_false_enabled_singlethreading(
self, embedding_openai: OpenAIEmbeddings
) -> None:
Pinecone.from_texts(
texts=["foo", "bar", "baz"],
embedding=embedding_openai,
index_name=index_name,
async_req=False
)
async_req=False,
)

0 comments on commit 0d7e14c

Please sign in to comment.