-
Notifications
You must be signed in to change notification settings - Fork 45
Enable semantic router reference updates #322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 0.6.0
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like some of the cells in the 08_semantic_router notebook are returning no routes. Can we double check this
56c9168
to
5f69f3b
Compare
if reference_ids: | ||
queries = cls._make_filter_queries(reference_ids) | ||
else: | ||
_, keys = index.client.scan( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Open to suggestions if there is a better way to get all keys within a prefix.
@@ -41,13 +41,14 @@ def routes(): | |||
@pytest.fixture | |||
def semantic_router(client, routes): | |||
router = SemanticRouter( | |||
name="test-router", | |||
name=f"test-router-{str(ULID())}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding this here to help prevent collisions within test execution.
Generally to improve our test consistency I think it would be good practice to make all function level fixtures (the default) as idempotent as possible. Given we execute tests with multiple workers in an async fashion that might help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Left a question for ya
reference_vectors = vectorizer.embed_many(references, as_buffer=True) | ||
|
||
# set route references | ||
for i, reference in enumerate(references): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this implementing the same or similar logic as _add_routes(...)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. The gotcha here is the route reference one takes advantage of self.
and this one is based on cls.
I decided against "functionizing" since there wasn't a 3rd case. This is an example of where the code becomes cleaner if we drop the class method idea (like we had talked about at one point).
# reference methods | ||
|
||
@classmethod | ||
def add_route_references( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only question is an ergonomic one.. what would be the benefit of using add_route_references(...)
on a non-instantiated router class, wherein you will still end up passing through the args here to essentially init the class? Isn't it effectively the same as calling router = SemanticRouter(...); router.add_route_references(...)
?
I know this is/was one of the tricky and sticky points, so just curious to hear what you're thinking! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The key difference here is that to you don't need to pass a list of routes when using the class method. You would have to provide the router name and redis_url but theoretically if you were unaware of the initial routes it wouldn't matter. I think there is some value in not having to know the previous routes.
That said, I'm open to removing because it makes the code more direct. A better way to handle could be to relax the requirement on passing routes in the init.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh yeah, I see what you mean!
Core issue is that class init is pretty rigid and expects certain inputs. It was probably a gap in the initial interface design for sure on my part.
This pr add methods so that you can easily get/add/delete route references.