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

feat: many new docs

parent 9a573f3c
Branches
Tags
No related merge requests found
Showing
with 251 additions and 30 deletions
semantic\_router.schema.EncoderInfo semantic\_router.schema.EncoderInfo
=================================== ===================================
.. currentmodule:: semantic_router.schema .. currentmodule:: semantic_router.schema
......
semantic\_router.schema.EncoderType semantic\_router.schema.EncoderType
=================================== ===================================
.. currentmodule:: semantic_router.schema .. currentmodule:: semantic_router.schema
......
semantic\_router.schema.Message semantic\_router.schema.Message
=============================== ===============================
.. currentmodule:: semantic_router.schema .. currentmodule:: semantic_router.schema
......
semantic\_router.schema.Metric semantic\_router.schema.Metric
============================== ==============================
.. currentmodule:: semantic_router.schema .. currentmodule:: semantic_router.schema
......
semantic\_router.schema.RouteChoice semantic\_router.schema.RouteChoice
=================================== ===================================
.. currentmodule:: semantic_router.schema .. currentmodule:: semantic_router.schema
......
semantic\_router.splitters.base.BaseSplitter semantic\_router.splitters.base.BaseSplitter
============================================ ============================================
.. currentmodule:: semantic_router.splitters.base .. currentmodule:: semantic_router.splitters.base
......
semantic\_router.splitters.consecutive\_sim.ConsecutiveSimSplitter semantic\_router.splitters.consecutive\_sim.ConsecutiveSimSplitter
================================================================== ==================================================================
.. currentmodule:: semantic_router.splitters.consecutive_sim .. currentmodule:: semantic_router.splitters.consecutive_sim
......
semantic\_router.splitters.cumulative\_sim.CumulativeSimSplitter semantic\_router.splitters.cumulative\_sim.CumulativeSimSplitter
================================================================ ================================================================
.. currentmodule:: semantic_router.splitters.cumulative_sim .. currentmodule:: semantic_router.splitters.cumulative_sim
......
semantic\_router.splitters.rolling\_window.RollingWindowSplitter semantic\_router.splitters.rolling\_window.RollingWindowSplitter
================================================================ ================================================================
.. currentmodule:: semantic_router.splitters.rolling_window .. currentmodule:: semantic_router.splitters.rolling_window
......
semantic\_router.splitters.rolling\_window.SplitStatistics semantic\_router.splitters.rolling\_window.SplitStatistics
========================================================== ==========================================================
.. currentmodule:: semantic_router.splitters.rolling_window .. currentmodule:: semantic_router.splitters.rolling_window
......
semantic\_router.text.Conversation semantic\_router.text.Conversation
================================== ==================================
.. currentmodule:: semantic_router.text .. currentmodule:: semantic_router.text
......
semantic\_router.utils.defaults.EncoderDefault semantic\_router.utils.defaults.EncoderDefault
============================================== ==============================================
.. currentmodule:: semantic_router.utils.defaults .. currentmodule:: semantic_router.utils.defaults
......
semantic\_router.utils.function\_call.FunctionSchema
====================================================
.. currentmodule:: semantic_router.utils.function_call
.. autoclass:: FunctionSchema
:members:
:show-inheritance:
:inherited-members:
.. automethod:: __init__
.. rubric:: Methods
.. autosummary::
~FunctionSchema.__init__
~FunctionSchema.to_ollama
.. rubric:: Attributes
.. autosummary::
~FunctionSchema.description
~FunctionSchema.name
~FunctionSchema.output
~FunctionSchema.parameters
~FunctionSchema.signature
\ No newline at end of file
semantic\_router.utils.function\_call.Parameter
===============================================
.. currentmodule:: semantic_router.utils.function_call
.. autoclass:: Parameter
:members:
:show-inheritance:
:inherited-members:
.. automethod:: __init__
.. rubric:: Methods
.. autosummary::
~Parameter.__init__
~Parameter.construct
~Parameter.copy
~Parameter.dict
~Parameter.from_orm
~Parameter.json
~Parameter.parse_file
~Parameter.parse_obj
~Parameter.parse_raw
~Parameter.schema
~Parameter.schema_json
~Parameter.to_ollama
~Parameter.update_forward_refs
~Parameter.validate
.. rubric:: Attributes
.. autosummary::
~Parameter.name
~Parameter.description
~Parameter.type
~Parameter.default
~Parameter.required
\ No newline at end of file
semantic\_router.utils.function\_call semantic\_router.utils.function\_call
===================================== =====================================
.. automodule:: semantic_router.utils.function_call .. automodule:: semantic_router.utils.function_call
...@@ -23,6 +23,15 @@ semantic\_router.utils.function\_call ...@@ -23,6 +23,15 @@ semantic\_router.utils.function\_call
.. rubric:: Classes
.. autosummary::
:toctree:
:template: custom-class-template.rst
FunctionSchema
Parameter
......
semantic\_router.utils.logger.CustomFormatter semantic\_router.utils.logger.CustomFormatter
============================================= =============================================
.. currentmodule:: semantic_router.utils.logger .. currentmodule:: semantic_router.utils.logger
......
API
===
.. autosummary::
:toctree: _autosummary
:template: custom-module-template.rst
:recursive:
semantic_router
\ No newline at end of file
Semantic Router documentation Semantic Router documentation
============================= =============================
.. toctree::
:hidden:
:maxdepth: 2
Home page <self>
Quickstart <quickstart>
Route Layer <route_layer>
API reference <_autosummary/semantic_router>
Semantic Router is a superfast decision-making layer for your LLMs and agents. Rather than waiting for slow LLM generations to make tool-use decisions, we use the magic of semantic vector space to make those decisions — *routing* our requests using *semantic* meaning. Semantic Router is a superfast decision-making layer for your LLMs and agents. Rather than waiting for slow LLM generations to make tool-use decisions, we use the magic of semantic vector space to make those decisions — *routing* our requests using *semantic* meaning.
Integrations Integrations
...@@ -10,10 +19,3 @@ The *encoders* of semantic router include easy-to-use integrations with `Cohere ...@@ -10,10 +19,3 @@ The *encoders* of semantic router include easy-to-use integrations with `Cohere
Our utterance vector space also integrates with `Pinecone <https://github.com/aurelio-labs/semantic-router/blob/main/docs/indexes/pinecone.ipynb>`_ and `Qdrant <https://github.com/aurelio-labs/semantic-router/blob/main/docs/indexes/qdrant.ipynb>`_! Our utterance vector space also integrates with `Pinecone <https://github.com/aurelio-labs/semantic-router/blob/main/docs/indexes/pinecone.ipynb>`_ and `Qdrant <https://github.com/aurelio-labs/semantic-router/blob/main/docs/indexes/qdrant.ipynb>`_!
.. toctree::
:hidden:
Home page <self>
Quickstart <quickstart>
Jupyter tutorials <tutorials>
API reference <_autosummary/semantic_router>
Route Layer
===========
The `RouteLayer` is the main class of the semantic router. It is responsible
for making decisions about which route to take based on an input utterance.
A `RouteLayer` consists of an `encoder`, an `index`, and a list of `routes`.
Route layers that include dynamic routes (i.e. routes that can generate dynamic
decision outputs) also include an `llm`.
.. toctree::
:hidden:
:maxdepth: 2
:glob:
route_layer/*
To use a `RouteLayer` we first need some `routes`. We can initialize them like
so:
.. code-block:: python
from semantic_router import Route
politics = Route(
name="politics",
utterances=[
"isn't politics the best thing ever",
"why don't you tell me about your political opinions",
"don't you just love the president",
"don't you just hate the president",
"they're going to destroy this country!",
"they will save the country!",
],
)
chitchat = Route(
name="chitchat",
utterances=[
"how's the weather today?",
"how are things going?",
"lovely weather today",
"the weather is horrendous",
"let's go to the chippy",
],
)
We initialize an encoder — there are many options available here, from local
to API-based. For now we'll use the `OpenAIEncoder`.
.. code-block:: python
import os
from semantic_router.encoders import OpenAIEncoder
os.environ["OPENAI_API_KEY"] = "<YOUR_API_KEY>"
encoder = OpenAIEncoder()
Now we define the `RouteLayer`. When called, the route layer will consume text
(a query) and output the category (`Route`) it belongs to — to initialize a
`RouteLayer` we need our `encoder` model and a list of `routes`.
.. code-block:: python
from semantic_router.layer import RouteLayer
rl = RouteLayer(encoder=encoder, routes=routes)
Now we can call the `RouteLayer` with an input query:
.. code-block:: python
rl("don't you love politics?")
.. code-block:: none
[Out]: RouteChoice(name='politics', function_call=None, similarity_score=None)
The output is a `RouteChoice` object, which contains the name of the route,
the function call (if any), and the similarity score that triggered the route
choice.
We can try another query:
.. code-block:: python
rl("how's the weather today?")
.. code-block:: none
[Out]: RouteChoice(name='chitchat', function_call=None, similarity_score=None)
Both are classified accurately, what if we send a query that is unrelated to
our existing Route objects?
.. code-block:: python
rl("I'm interested in learning about llama 3")
.. code-block:: none
[Out]: RouteChoice(name=None, function_call=None, similarity_score=None)
In this case, the `RouteLayer` is unable to find a route that matches the
input query and so returns a `RouteChoice` with `name=None`.
We can also retrieve multiple routes with their associated score using
`retrieve_multiple_routes`:
.. code-block:: python
rl.retrieve_multiple_routes("Hi! How are you doing in politics??")
.. code-block:: none
[Out]: [RouteChoice(name='politics', function_call=None, similarity_score=0.859),
RouteChoice(name='chitchat', function_call=None, similarity_score=0.835)]
If `retrieve_multiple_routes` is called with a query that does not match any
routes, it will return an empty list:
.. code-block:: python
rl.retrieve_multiple_routes("I'm interested in learning about llama 3")
.. code-block:: none
[Out]: []
You can find an introductory notebook for the [route layer here](https://github.com/aurelio-labs/semantic-router/blob/main/docs/00-introduction.ipynb).
Calling the Route Layer
=======================
You can use the `route_filter` parameter with a list of route names to filter
the routes that will be considered.
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment