Skip to content
Snippets Groups Projects
Commit 1141d73b authored by James Briggs's avatar James Briggs
Browse files

fix: pinecone delays

parent c30652d7
No related branches found
No related tags found
No related merge requests found
...@@ -13,10 +13,12 @@ from semantic_router.index.qdrant import QdrantIndex ...@@ -13,10 +13,12 @@ from semantic_router.index.qdrant import QdrantIndex
from semantic_router.routers import RouterConfig, SemanticRouter, HybridRouter from semantic_router.routers import RouterConfig, SemanticRouter, HybridRouter
from semantic_router.llms import BaseLLM, OpenAILLM from semantic_router.llms import BaseLLM, OpenAILLM
from semantic_router.route import Route from semantic_router.route import Route
from semantic_router.utils.logger import logger
from platform import python_version from platform import python_version
PINECONE_SLEEP = 12 PINECONE_SLEEP = 8
RETRY_COUNT = 5
def mock_encoder_call(utterances): def mock_encoder_call(utterances):
...@@ -266,9 +268,6 @@ class TestIndexEncoders: ...@@ -266,9 +268,6 @@ class TestIndexEncoders:
auto_sync="local", auto_sync="local",
top_k=10, top_k=10,
) )
if index_cls is PineconeIndex:
time.sleep(PINECONE_SLEEP * 2) # allow for index to be populated
if isinstance(route_layer, HybridRouter): if isinstance(route_layer, HybridRouter):
assert ( assert (
route_layer.score_threshold route_layer.score_threshold
...@@ -277,7 +276,16 @@ class TestIndexEncoders: ...@@ -277,7 +276,16 @@ class TestIndexEncoders:
else: else:
assert route_layer.score_threshold == encoder.score_threshold assert route_layer.score_threshold == encoder.score_threshold
assert route_layer.top_k == 10 assert route_layer.top_k == 10
assert len(route_layer.index) == 5 # allow for 5 retries in case of index not being populated
count = 0
while count < RETRY_COUNT:
try:
assert len(route_layer.index) == 5
break
except AssertionError:
logger.warning(f"Index not populated, waiting for retry (try {count})")
time.sleep(PINECONE_SLEEP)
count += 1
assert ( assert (
len(set(route_layer._get_route_names())) len(set(route_layer._get_route_names()))
if route_layer._get_route_names() is not None if route_layer._get_route_names() is not None
...@@ -718,10 +726,20 @@ class TestSemanticRouter: ...@@ -718,10 +726,20 @@ class TestSemanticRouter:
index=index, index=index,
auto_sync="local", auto_sync="local",
) )
if index_cls is PineconeIndex: count = 0
time.sleep(PINECONE_SLEEP * 2) # allow for index to be populated # we allow for 5 retries to allow for index to be populated
query_result = route_layer(text="Hello").name while count < RETRY_COUNT:
assert query_result in ["Route 1", "Route 2"] query_result = route_layer(text="Hello").name
try:
assert query_result in ["Route 1", "Route 2"]
break
except AssertionError:
logger.warning(
f"Query result not in expected routes, waiting for retry (try {count})"
)
if index_cls is PineconeIndex:
time.sleep(PINECONE_SLEEP) # allow for index to be populated
count += 1
def test_query_filter(self, routes, index_cls, encoder_cls, router_cls): def test_query_filter(self, routes, index_cls, encoder_cls, router_cls):
encoder = encoder_cls() encoder = encoder_cls()
...@@ -781,15 +799,23 @@ class TestSemanticRouter: ...@@ -781,15 +799,23 @@ class TestSemanticRouter:
index=pineconeindex, index=pineconeindex,
auto_sync="local", auto_sync="local",
) )
time.sleep(PINECONE_SLEEP * 2) # allow for index to be populated count = 0
query_result = route_layer(text="Hello", route_filter=["Route 1"]).name while count < RETRY_COUNT:
try:
try: query_result = route_layer(
route_layer(text="Hello", route_filter=["Route 8"]).name text="Hello", route_filter=["Route 1"]
except ValueError: ).name
assert True assert query_result in ["Route 1"]
break
assert query_result in ["Route 1"] except AssertionError:
logger.warning(
f"Query result not in expected routes, waiting for retry (try {count})"
)
if index_cls is PineconeIndex:
time.sleep(
PINECONE_SLEEP * 2
) # allow for index to be populated
count += 1
route_layer.index.index.delete(namespace="test", delete_all=True) route_layer.index.index.delete(namespace="test", delete_all=True)
def test_query_with_no_index(self, index_cls, encoder_cls, router_cls): def test_query_with_no_index(self, index_cls, encoder_cls, router_cls):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment