Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Semantic Router
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
aurelio-labs
Semantic Router
Commits
1141d73b
Commit
1141d73b
authored
3 months ago
by
James Briggs
Browse files
Options
Downloads
Patches
Plain Diff
fix: pinecone delays
parent
c30652d7
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/unit/test_router.py
+44
-18
44 additions, 18 deletions
tests/unit/test_router.py
with
44 additions
and
18 deletions
tests/unit/test_router.py
+
44
−
18
View file @
1141d73b
...
@@ -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
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment