Skip to content
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

Support for setting top_k for HybridRouteLayer? #198

Closed
andreped opened this issue Mar 13, 2024 · 1 comment · Fixed by #197
Closed

Support for setting top_k for HybridRouteLayer? #198

andreped opened this issue Mar 13, 2024 · 1 comment · Fixed by #197

Comments

@andreped
Copy link
Contributor

I see that top_k=5 is hardcoded for the HybridRouteLayer class:

results = self._query(text)

Which is possible to set through the _query method:

def _query(self, text: str, top_k: int = 5):

I believe being able to set top_k would be of value to achieve better performance in some use cases.

@andreped
Copy link
Contributor Author

The feature has been merged but has yet to be part of a release. For now, install from source to get feature.

Below is an example on how to set top_k:

from semantic_router.encoders import AzureOpenAIEncoder, TfidfEncoder
from semantic_router.hybrid_layer import HybridRouteLayer

model = HybridRouteLayer(
    encoder=AzureOpenAIEncoder(...),
    sparse_encoder=TfidfEncoder(),
    routes=routes,
    alpha=0.3,  # default = 0.3
    top_k=3,  # default = 5
)

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

Successfully merging a pull request may close this issue.

1 participant