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

fix: pinecone delays

parent 1141d73b
No related branches found
No related tags found
No related merge requests found
......@@ -752,37 +752,30 @@ class TestSemanticRouter:
)
if index_cls is PineconeIndex:
time.sleep(PINECONE_SLEEP) # allow for index to be populated
query_result = route_layer(text="Hello", route_filter=["Route 1"]).name
# with pytest.raises(ValueError):
# # Route 8 does not exist so should raise ValueError
# route_layer(text="Hello", route_filter=["Route 8"]).name
try:
# TODO JB: currently LocalIndex raises ValueError but others don't
# they should all behave in the same way
route_layer(text="Hello", route_filter=["Route 8"]).name
except ValueError:
assert True
assert query_result in ["Route 1"]
@pytest.mark.skipif(
os.environ.get("PINECONE_API_KEY") is None, reason="Pinecone API key required"
)
def test_query_filter_pinecone(self, routes, index_cls, encoder_cls, router_cls):
if index_cls is PineconeIndex:
encoder = encoder_cls()
pineconeindex = init_index(index_cls, index_name=encoder.__class__.__name__)
route_layer = router_cls(
encoder=encoder,
routes=routes,
index=pineconeindex,
auto_sync="local",
)
time.sleep(PINECONE_SLEEP) # allow for index to be populated
count = 0
# we allow for 5 retries to allow for index to be populated
while count < RETRY_COUNT:
query_result = route_layer(text="Hello", route_filter=["Route 1"]).name
try:
route_layer(text="Hello", route_filter=["Route 8"]).name
except ValueError:
assert True
assert query_result in ["Route 1"]
assert query_result in ["Route 1"]
break
except AssertionError:
logger.warning(
f"Query result not in expected routes, waiting for retry (try {count})"
)
count += 1
time.sleep(PINECONE_SLEEP) # allow for index to be populated
@pytest.mark.skipif(
os.environ.get("PINECONE_API_KEY") is None, reason="Pinecone API key required"
......
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