Skip to content

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

Open
wants to merge 4 commits into
base: 0.6.0
Choose a base branch
from

Conversation

rbs333
Copy link
Collaborator

@rbs333 rbs333 commented Apr 17, 2025

This pr add methods so that you can easily get/add/delete route references.

Copy link
Collaborator

@justin-cechmanek justin-cechmanek left a 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

@rbs333 rbs333 changed the base branch from main to 0.6.0 April 21, 2025 19:53
@rbs333 rbs333 force-pushed the feat/RAAE-337/router-reference-crud branch from 56c9168 to 5f69f3b Compare April 21, 2025 19:57
if reference_ids:
queries = cls._make_filter_queries(reference_ids)
else:
_, keys = index.client.scan(
Copy link
Collaborator Author

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())}",
Copy link
Collaborator Author

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.

@tylerhutcherson tylerhutcherson changed the title Route reference methods Enable semantic router reference updates Apr 22, 2025
@tylerhutcherson tylerhutcherson added the enhancement New feature or request label Apr 22, 2025
Copy link
Collaborator

@tylerhutcherson tylerhutcherson left a 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):
Copy link
Collaborator

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(...)?

Copy link
Collaborator Author

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(
Copy link
Collaborator

@tylerhutcherson tylerhutcherson Apr 22, 2025

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! :)

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants