gllm-pipeline-binary 0.4.19__cp312-cp312-win_amd64.whl → 0.4.21__cp312-cp312-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. gllm_pipeline/alias.pyi +4 -2
  2. gllm_pipeline/pipeline/pipeline.pyi +10 -5
  3. gllm_pipeline/router/__init__.pyi +6 -0
  4. gllm_pipeline/router/aurelio_semantic_router/__init__.pyi +3 -0
  5. gllm_pipeline/router/aurelio_semantic_router/aurelio_semantic_router.pyi +86 -0
  6. gllm_pipeline/router/aurelio_semantic_router/bytes_compat_route.pyi +40 -0
  7. gllm_pipeline/router/aurelio_semantic_router/encoders/__init__.pyi +5 -0
  8. gllm_pipeline/router/aurelio_semantic_router/encoders/em_invoker_encoder.pyi +46 -0
  9. gllm_pipeline/router/aurelio_semantic_router/encoders/langchain_encoder.pyi +50 -0
  10. gllm_pipeline/router/aurelio_semantic_router/encoders/tei_encoder.pyi +49 -0
  11. gllm_pipeline/router/aurelio_semantic_router/index/__init__.pyi +4 -0
  12. gllm_pipeline/router/aurelio_semantic_router/index/aurelio_index.pyi +65 -0
  13. gllm_pipeline/router/aurelio_semantic_router/index/azure_ai_search_aurelio_index.pyi +71 -0
  14. gllm_pipeline/router/aurelio_semantic_router/index/vector_store_adapter_index.pyi +119 -0
  15. gllm_pipeline/router/lm_based_router.pyi +60 -0
  16. gllm_pipeline/router/preset/__init__.pyi +0 -0
  17. gllm_pipeline/router/preset/aurelio/__init__.pyi +0 -0
  18. gllm_pipeline/router/preset/aurelio/router_image_domain_specific.pyi +21 -0
  19. gllm_pipeline/router/preset/lm_based/__init__.pyi +0 -0
  20. gllm_pipeline/router/preset/lm_based/router_image_domain_specific.pyi +14 -0
  21. gllm_pipeline/router/preset/preset_loader.pyi +24 -0
  22. gllm_pipeline/router/router.pyi +46 -0
  23. gllm_pipeline/router/rule_based_router.pyi +80 -0
  24. gllm_pipeline/router/similarity_based_router.pyi +72 -0
  25. gllm_pipeline/router/utils.pyi +26 -0
  26. gllm_pipeline/steps/component_step.pyi +5 -5
  27. gllm_pipeline/steps/conditional_step.pyi +9 -9
  28. gllm_pipeline/steps/log_step.pyi +5 -4
  29. gllm_pipeline/steps/map_reduce_step.pyi +4 -3
  30. gllm_pipeline/steps/no_op_step.pyi +4 -3
  31. gllm_pipeline/steps/parallel_step.pyi +5 -3
  32. gllm_pipeline/steps/pipeline_step.pyi +7 -6
  33. gllm_pipeline/steps/state_operator_step.pyi +5 -5
  34. gllm_pipeline/steps/step_error_handler/empty_step_error_handler.pyi +2 -0
  35. gllm_pipeline/steps/step_error_handler/fallback_step_error_handler.pyi +7 -5
  36. gllm_pipeline/steps/step_error_handler/keep_step_error_handler.pyi +2 -0
  37. gllm_pipeline/steps/step_error_handler/raise_step_error_handler.pyi +2 -0
  38. gllm_pipeline/steps/step_error_handler/step_error_handler.pyi +4 -2
  39. gllm_pipeline/steps/subgraph_step.pyi +5 -5
  40. gllm_pipeline/steps/terminator_step.pyi +5 -4
  41. gllm_pipeline/utils/copy.pyi +11 -0
  42. gllm_pipeline/utils/error_handling.pyi +3 -2
  43. gllm_pipeline/utils/has_inputs_mixin.pyi +2 -1
  44. gllm_pipeline/utils/input_map.pyi +3 -3
  45. gllm_pipeline/utils/step_execution.pyi +4 -3
  46. gllm_pipeline.cp312-win_amd64.pyd +0 -0
  47. gllm_pipeline.pyi +45 -8
  48. {gllm_pipeline_binary-0.4.19.dist-info → gllm_pipeline_binary-0.4.21.dist-info}/METADATA +40 -14
  49. gllm_pipeline_binary-0.4.21.dist-info/RECORD +77 -0
  50. gllm_pipeline_binary-0.4.19.dist-info/RECORD +0 -53
  51. {gllm_pipeline_binary-0.4.19.dist-info → gllm_pipeline_binary-0.4.21.dist-info}/WHEEL +0 -0
  52. {gllm_pipeline_binary-0.4.19.dist-info → gllm_pipeline_binary-0.4.21.dist-info}/top_level.txt +0 -0
gllm_pipeline/alias.pyi CHANGED
@@ -1,5 +1,7 @@
1
1
  from gllm_pipeline.steps.pipeline_step import BasePipelineStep as BasePipelineStep
2
2
  from gllm_pipeline.types import Val as Val
3
+ from typing import TypeAlias
3
4
 
4
- PipelineSteps = BasePipelineStep | list[BasePipelineStep]
5
- InputMapSpec = dict[str, str | Val] | list[str | dict[str, str] | dict[str, Val]]
5
+ PipelineSteps: TypeAlias
6
+ PipelineState: TypeAlias
7
+ InputMapSpec: TypeAlias
@@ -1,12 +1,15 @@
1
1
  from _typeshed import Incomplete
2
2
  from gllm_datastore.cache.cache import BaseCache as BaseCache
3
+ from gllm_pipeline.alias import PipelineState as PipelineState
3
4
  from gllm_pipeline.exclusions import ExclusionManager as ExclusionManager, ExclusionSet as ExclusionSet
5
+ from gllm_pipeline.pipeline.composer import Composer as Composer
4
6
  from gllm_pipeline.pipeline.states import RAGState as RAGState
5
7
  from gllm_pipeline.steps.pipeline_step import BasePipelineStep as BasePipelineStep
6
8
  from gllm_pipeline.steps.terminator_step import TerminatorStep as TerminatorStep
7
9
  from gllm_pipeline.utils.graph import create_edge as create_edge
8
10
  from gllm_pipeline.utils.mermaid import MERMAID_HEADER as MERMAID_HEADER, combine_mermaid_diagrams as combine_mermaid_diagrams, extract_step_diagrams as extract_step_diagrams
9
11
  from langgraph.graph import StateGraph
12
+ from langgraph.graph.state import CompiledStateGraph as CompiledStateGraph
10
13
  from pydantic import BaseModel
11
14
  from typing import Any, TypedDict
12
15
 
@@ -102,10 +105,10 @@ class Pipeline:
102
105
  pipeline.exclusions.exclude("parallel_step.retrieval_b") # Skip retrieval_b step
103
106
  ```
104
107
  '''
108
+ name: Incomplete
105
109
  steps: Incomplete
106
110
  recursion_limit: Incomplete
107
- name: Incomplete
108
- def __init__(self, steps: list[BasePipelineStep] | None = None, state_type: TypedDict | type[BaseModel] = ..., input_type: TypedDict | type[BaseModel] | None = None, output_type: TypedDict | type[BaseModel] | None = None, recursion_limit: int = 30, name: str | None = None, cache_store: BaseCache | None = None, cache_config: dict[str, Any] | None = None) -> None:
111
+ def __init__(self, steps: list[BasePipelineStep] | None = None, state_type: TypedDict | type[BaseModel] = ..., input_type: TypedDict | type[BaseModel] | None = None, output_type: TypedDict | type[BaseModel] | None = None, context_schema: TypedDict | type[BaseModel] | None = None, recursion_limit: int = 30, name: str | None = None, cache_store: BaseCache | None = None, cache_config: dict[str, Any] | None = None) -> None:
109
112
  '''Initializes the Pipeline with the given steps and state type.
110
113
 
111
114
  Args:
@@ -121,6 +124,8 @@ class Pipeline:
121
124
  This state should be compatible with the pipeline\'s `state_type`.
122
125
  Could be a TypedDict or a Pydantic BaseModel. Defaults to None, in which case the output state type
123
126
  will be the same as the pipeline\'s `state_type`.
127
+ context_schema (TypedDict | type[BaseModel] | None, optional): The type of pipeline\'s runtime context.
128
+ Defaults to None, in which case no context schema will be used.
124
129
  recursion_limit (int, optional): The maximum number of steps allowed. Defaults to 30.
125
130
  name (str | None, optional): A name for this pipeline. Used when this pipeline is included as a subgraph.
126
131
  Defaults to None, in which case the name will be "Subgraph" followed by a unique identifier.
@@ -194,17 +199,17 @@ class Pipeline:
194
199
  invalidating any built graph or compiled app. Useful for reusing a pipeline
195
200
  instance with different configurations.
196
201
  """
197
- async def invoke(self, initial_state: dict[str, Any] | BaseModel, config: dict[str, Any] | None = None) -> dict[str, Any]:
202
+ async def invoke(self, initial_state: PipelineState, config: dict[str, Any] | None = None) -> dict[str, Any]:
198
203
  '''Runs the pipeline asynchronously with the given initial state and configuration.
199
204
 
200
205
  Args:
201
- initial_state (dict[str, Any] | BaseModel): The initial state to start the pipeline with.
206
+ initial_state (PipelineState): The initial state to start the pipeline with.
202
207
  This initial state should comply with the state type of the pipeline.
203
208
  config (dict[str, Any], optional): Additional configuration for the pipeline. User-defined config should not
204
209
  have "langraph_" prefix as it should be reserved for internal use. Defaults to None.
205
210
 
206
211
  Returns:
207
- dict[str, Any] | BaseModel: The final state after the pipeline execution.
212
+ dict[str, Any]: The final state after the pipeline execution.
208
213
  If \'debug_state\' is set to True in the config, the state logs will be included
209
214
  in the final state with the key \'__state_logs__\'.
210
215
 
@@ -0,0 +1,6 @@
1
+ from gllm_pipeline.router.aurelio_semantic_router import AurelioSemanticRouter as AurelioSemanticRouter
2
+ from gllm_pipeline.router.lm_based_router import LMBasedRouter as LMBasedRouter
3
+ from gllm_pipeline.router.rule_based_router import RuleBasedRouter as RuleBasedRouter
4
+ from gllm_pipeline.router.similarity_based_router import SimilarityBasedRouter as SimilarityBasedRouter
5
+
6
+ __all__ = ['AurelioSemanticRouter', 'LMBasedRouter', 'RuleBasedRouter', 'SimilarityBasedRouter']
@@ -0,0 +1,3 @@
1
+ from gllm_pipeline.router.aurelio_semantic_router.aurelio_semantic_router import AurelioSemanticRouter as AurelioSemanticRouter
2
+
3
+ __all__ = ['AurelioSemanticRouter']
@@ -0,0 +1,86 @@
1
+ from _typeshed import Incomplete
2
+ from gllm_pipeline.router.aurelio_semantic_router.bytes_compat_route import BytesCompatRoute as BytesCompatRoute
3
+ from gllm_pipeline.router.aurelio_semantic_router.index.aurelio_index import BaseAurelioIndex as BaseAurelioIndex
4
+ from gllm_pipeline.router.preset.preset_loader import get_preset as get_preset
5
+ from gllm_pipeline.router.router import BaseRouter as BaseRouter
6
+ from semantic_router import Route
7
+ from semantic_router.encoders.base import DenseEncoder as DenseEncoder
8
+ from typing import Any
9
+
10
+ manager: Incomplete
11
+ logger: Incomplete
12
+ semantic_router_logger: Incomplete
13
+
14
+ class AurelioSemanticRouter(BaseRouter):
15
+ """A router that utilizes the Aurelio Labs library to route the input source to the appropriate path.
16
+
17
+ The `AurelioSemanticRouter` utilizes the Aurelio Labs library to route a given input source to an appropriate path
18
+ based on the similarity with existing samples. If the determined route is not valid, it defaults to a predefined
19
+ route.
20
+
21
+ Attributes:
22
+ route_layer (RouteLayer): The Aurelio Labs route layer that handles the routing logic.
23
+ default_route (str): The default route to be used if the input source is not similar to any of the routes.
24
+ valid_routes (set[str]): A set of valid routes for the router.
25
+
26
+ Notes:
27
+ For more information about the Aurelio Labs library, please refer to
28
+ https://github.com/aurelio-labs/semantic-router
29
+ """
30
+ route_layer: Incomplete
31
+ def __init__(self, default_route: str, valid_routes: set[str], encoder: DenseEncoder, routes: list[Route] | dict[str, list[str | bytes]] | None = None, index: BaseAurelioIndex | None = None, auto_sync: str = ..., **kwargs: Any) -> None:
32
+ '''Initializes a new instance of the AurelioSemanticRouter class.
33
+
34
+ To define the routes, at least one of the `routes` or `index` parameters must be provided.
35
+ When both parameters are provided, the `routes` parameter is ignored.
36
+
37
+ Args:
38
+ default_route (str): The default route to be used if the input source is not similar to any of the routes.
39
+ valid_routes (set[str]): A set of valid routes for the router.
40
+ encoder (DenseEncoder): An Aurelio Labs dense encoder to encode the input source and the samples.
41
+ The encoded vectors are used to calculate the similarity between the input source and the samples.
42
+ routes (list[Route] | dict[str, list[str | bytes]] | None, optional): A list of Aurelio Labs Routes
43
+ or a dictionary mapping route names to the list of samples. Ignored if `index` is provided.
44
+ Defaults to None.
45
+ index (BaseAurelioIndex | None, optional): A router index to retrieve the routes.
46
+ If provided, it is prioritized over `routes`. Defaults to None.
47
+ auto_sync (str, optional): The auto-sync mode for the router. Defaults to "local".
48
+ kwargs (Any): Additional keyword arguments to be passed to the Aurelio Labs Route Layer.
49
+
50
+ Raises:
51
+ ValueError:
52
+ 1. If neither `routes` nor `index` is provided.
53
+ 2. If the parsed routes contains routes that are not in the set of valid routes.
54
+ 3. If the provided default route is not in the set of valid routes.
55
+ '''
56
+ @classmethod
57
+ def from_preset(cls, modality: str, preset_name: str, preset_kwargs: dict | None = None, **kwargs) -> AurelioSemanticRouter:
58
+ """Initialize the Aurelio semantic based router component using preset model configurations.
59
+
60
+ Args:
61
+ modality (str): type of modality input.
62
+ preset_name (str): Name of the preset to use.
63
+ preset_kwargs (dict | None): placeholder for preset additional arguments.
64
+ **kwargs (Any): Additional arguments to pass for this class.
65
+
66
+ Returns:
67
+ AurelioSemanticRouter: Initialized aurelio semantic based router component using preset model.
68
+ """
69
+ @classmethod
70
+ def from_file(cls, default_route: str, valid_routes: set[str], file_path: str) -> AurelioSemanticRouter:
71
+ '''Creates a new instance of the AurelioSemanticRouter class from a file.
72
+
73
+ This method creates a new instance of the AurelioSemanticRouter class from a file. It supports JSON and YAML
74
+ file extensions.
75
+
76
+ Args:
77
+ default_route (str): The default route to be used if the input source is not similar to any of the routes.
78
+ valid_routes (set[str]): A set of valid routes for the router.
79
+ file_path (str): The path to the file containing the routes. The file extension must be either JSON or YAML.
80
+
81
+ Returns:
82
+ AurelioSemanticRouter: A new instance of the AurelioSemanticRouter class.
83
+
84
+ Raises:
85
+ ValueError: If the file extension is not ".json" or ".yaml".
86
+ '''
@@ -0,0 +1,40 @@
1
+ from gllm_pipeline.router.utils import encode_bytes as encode_bytes
2
+ from semantic_router.route import Route
3
+ from typing import Any
4
+
5
+ class BytesCompatRoute(Route):
6
+ """A subclass of `Route` that provides JSON-serializable support for `bytes` in utterances.
7
+
8
+ The primary motivation for this override is to prevent errors when `bytes`-based utterances are hashed
9
+ during `semantic_router.routers.base.BaseRouter._write_hash`.
10
+
11
+ `ByteCompatRoute` extends the standard `Route` class from the `semantic-router` library by ensuring that
12
+ all `bytes` values in the `utterances` field are safely encoded using base64 when converting to a dictionary.
13
+ This is essential for serializing routes containing binary data to formats like JSON, which does not
14
+ support raw bytes.
15
+
16
+ Use this class as a drop-in replacement when dealing with routes that include `bytes`-based utterances but still
17
+ need to be serialized (e.g., for configuration exports or caching).
18
+ """
19
+ def to_dict(self) -> dict[str, Any]:
20
+ '''Convert the route instance to a dictionary with all `bytes` in the `utterances`.
21
+
22
+ This overrides the default `Route.to_dict()` to handle nested `bytes` inside lists or dictionaries.
23
+
24
+ Returns:
25
+ dict[str, Any]: A dictionary representation of the route, with all `bytes` values in `utterances`
26
+ converted to base64-encoded UTF-8 strings.
27
+
28
+ Example:
29
+ >>> route = ByteCompatRoute(name="example", utterances=[b"binary1", "text"])
30
+ >>> route.to_dict()
31
+ {
32
+ "name": "example",
33
+ "utterances": ["YmluYXJ5MQ==", "text"],
34
+ ...
35
+ }
36
+
37
+ Notes:
38
+ - Only the `utterances` field is altered for byte safety; other fields remain untouched.
39
+ - If the utterances contain nested lists or dicts with bytes, they will be recursively encoded.
40
+ '''
@@ -0,0 +1,5 @@
1
+ from gllm_pipeline.router.aurelio_semantic_router.encoders.em_invoker_encoder import EMInvokerEncoder as EMInvokerEncoder
2
+ from gllm_pipeline.router.aurelio_semantic_router.encoders.langchain_encoder import LangchainEmbeddingsEncoder as LangchainEmbeddingsEncoder
3
+ from gllm_pipeline.router.aurelio_semantic_router.encoders.tei_encoder import TEIEncoder as TEIEncoder
4
+
5
+ __all__ = ['TEIEncoder', 'LangchainEmbeddingsEncoder', 'EMInvokerEncoder']
@@ -0,0 +1,46 @@
1
+ from gllm_inference.em_invoker.em_invoker import BaseEMInvoker as BaseEMInvoker
2
+ from semantic_router.encoders.base import DenseEncoder
3
+ from typing import Any
4
+
5
+ class EMInvokerEncoder(DenseEncoder):
6
+ """The gllm-inference EM Invoker-compatible Encoder.
7
+
8
+ This encoder is for use with gllm-inference's EM Invokers.
9
+ Includes handling of synchronous cases, since gllm-inference's EM Invokers are asynchronous.
10
+
11
+ Attributes:
12
+ name (str): The name of the encoder.
13
+ score_threshold (float): The score threshold for the encoder.
14
+ """
15
+ def __init__(self, em_invoker: BaseEMInvoker, name: str = 'em-invoker-encoder', score_threshold: float = 0.0) -> None:
16
+ '''Initialize the EM Invoker Encoder.
17
+
18
+ Args:
19
+ em_invoker (BaseEMInvoker): The EM Invoker to use.
20
+ name (str, optional): The name of the encoder. Defaults to "em-invoker-encoder".
21
+ score_threshold (float, optional): The score threshold for the encoder. Defaults to 0.0.
22
+ '''
23
+ def __call__(self, docs: list[Any]) -> list[list[float]]:
24
+ """Call the EM Invoker.
25
+
26
+ Handles both async and sync contexts by checking for existing event loop.
27
+ If an event loop is not found, we run the invoke method in the current thread.
28
+ If an event loop is found, we run the invoke method in a thread pool.
29
+ In the case of a RuntimeError, we run the invoke method in the current thread.
30
+
31
+ Args:
32
+ docs (list[Any]): List of documents to be embedded.
33
+
34
+ Returns:
35
+ list[list[float]]: List of embeddings for each document.
36
+ """
37
+ async def acall(self, docs: list[Any], **kwargs: Any) -> list[list[float]]:
38
+ """Call the EM Invoker, which is already an async function.
39
+
40
+ Args:
41
+ docs (list[Any]): List of documents to be embedded.
42
+ **kwargs (Any): Additional keyword arguments. Not used, but required by the DenseEncoder interface.
43
+
44
+ Returns:
45
+ list[list[float]]: List of embeddings for each document.
46
+ """
@@ -0,0 +1,50 @@
1
+ from langchain_core.embeddings import Embeddings as Embeddings
2
+ from semantic_router.encoders.base import DenseEncoder
3
+ from typing import Any
4
+
5
+ class LangchainEmbeddingsEncoder(DenseEncoder):
6
+ """A wrapper encoder for LangChain-compatible embedding models.
7
+
8
+ This encoder adapts any LangChain-compatible Embeddings instance to the
9
+ Semantic Router interface by wrapping its `embed_documents` and `aembed_documents` methods.
10
+
11
+ It supports both synchronous and asynchronous embedding calls and is useful
12
+ when integrating LangChain embeddings with a semantic router pipeline.
13
+
14
+ Attributes:
15
+ name (str): The name of the encoder.
16
+ score_threshold (float): Threshold for similarity scoring.
17
+ """
18
+ def __init__(self, embeddings: Embeddings, name: str = 'langchain-embeddings-encoder', score_threshold: float = 0.5) -> None:
19
+ '''Initialize the LangchainEmbeddingsEncoder.
20
+
21
+ Args:
22
+ embeddings (Embeddings): A LangChain-compatible Embeddings instance.
23
+ name (str, optional): Identifier for the encoder. Defaults to "langchain-embeddings-encoder".
24
+ score_threshold (float, optional): Minimum similarity score to consider matches. Defaults to 0.5.
25
+ '''
26
+ def __call__(self, docs: list[Any]) -> list[list[float]]:
27
+ """Synchronously embed a list of documents.
28
+
29
+ Automatically handles execution context:
30
+ 1. If called inside an active asyncio loop, it runs the embedding call in a background thread.
31
+ 2. If no active loop is present, it runs the embedding call normally.
32
+ 3. If an event loop cannot be retrieved, falls back to `asyncio.run`.
33
+
34
+ Args:
35
+ docs (list[Any]): The documents to embed.
36
+
37
+ Returns:
38
+ list[list[float]]: A list of vector embeddings for each document.
39
+ """
40
+ async def acall(self, docs: list[Any]) -> list[list[float]]:
41
+ """Asynchronously embed a list of documents.
42
+
43
+ Calls the `aembed_documents` method of the underlying LangChain embeddings.
44
+
45
+ Args:
46
+ docs (list[Any]): The documents to embed.
47
+
48
+ Returns:
49
+ list[list[float]]: A list of vector embeddings for each document.
50
+ """
@@ -0,0 +1,49 @@
1
+ from semantic_router.encoders.huggingface import HFEndpointEncoder
2
+ from typing import Any
3
+
4
+ class TEIEncoder(HFEndpointEncoder):
5
+ """TEI Endpoint Encoder.
6
+
7
+ This encoder is used to encode documents into embeddings using the TEI endpoint.
8
+
9
+ Attributes:
10
+ name (str): The name of the encoder.
11
+ huggingface_url (str): The base URL of the TEI endpoint, which is a HuggingFace endpoint.
12
+ huggingface_api_key (str): The API key for the TEI endpoint.
13
+ score_threshold (float): The score threshold for the encoder.
14
+ """
15
+ def __init__(self, base_url: str, name: str = 'tei-encoder', api_key: str = '<empty>', score_threshold: float = 0.0) -> None:
16
+ '''Initialize the TEI Endpoint Encoder.
17
+
18
+ Args:
19
+ base_url (str): The base URL of the TEI endpoint, which is a HuggingFace endpoint.
20
+ name (str, optional): The name of the encoder. Defaults to "tei-encoder".
21
+ api_key (str, optional): The API key for the TEI endpoint. Defaults to "<empty>".
22
+ Only do this if the endpoint does not require an API key.
23
+ score_threshold (float, optional): The score threshold for the encoder. Defaults to 0.0.
24
+ '''
25
+ async def acall(self, docs: list[str], **kwargs: Any) -> list[list[float]]:
26
+ """Asynchronously encodes a list of documents into embeddings.
27
+
28
+ Args:
29
+ docs (list[str]): A list of documents to encode.
30
+ **kwargs (Any): Additional keyword arguments. Not used, but required by the BaseEncoder interface.
31
+
32
+ Returns:
33
+ list[list[float]]: A list of embeddings for the given documents.
34
+
35
+ Raises:
36
+ ValueError: If no embeddings are returned for a document.
37
+ """
38
+ def __call__(self, docs: list[str]) -> list[list[float]]:
39
+ """Encodes a list of documents into embeddings using the Hugging Face API.
40
+
41
+ Args:
42
+ docs (list[str]): A list of documents to encode.
43
+
44
+ Returns:
45
+ list[list[float]]: A list of embeddings for the given documents.
46
+
47
+ Raises:
48
+ ValueError: If no embeddings are returned for a document.
49
+ """
@@ -0,0 +1,4 @@
1
+ from gllm_pipeline.router.aurelio_semantic_router.index.azure_ai_search_aurelio_index import AzureAISearchAurelioIndex as AzureAISearchAurelioIndex
2
+ from gllm_pipeline.router.aurelio_semantic_router.index.vector_store_adapter_index import VectorStoreAdapterIndex as VectorStoreAdapterIndex
3
+
4
+ __all__ = ['AzureAISearchAurelioIndex', 'VectorStoreAdapterIndex']
@@ -0,0 +1,65 @@
1
+ import abc
2
+ import numpy as np
3
+ from abc import ABC, abstractmethod
4
+ from semantic_router.index import BaseIndex
5
+ from typing import Any
6
+
7
+ class BaseAurelioIndex(BaseIndex, ABC, metaclass=abc.ABCMeta):
8
+ """An abstract base class for the router index to be loaded by the AurelioSemanticRouter.
9
+
10
+ The `BaseAurelioIndex` extends the `BaseIndex` class from the semantic router library.
11
+ It can be used as a base class for a router index implementation that can be used with the assumption that
12
+ the routes are already in the index. Therefore, the index will solely be used for retrieval purposes.
13
+
14
+ Attributes:
15
+ sync (bool): Flag to indicate that the index should be synchronized with the routes mapping.
16
+ In this implementation, it's set to `True` by default to make sure that the RouteLayer object initialized
17
+ with this index will perform the syncing process instead of blindly adding the routes to the index.
18
+
19
+ Notes:
20
+ To use this class, you need to implement the `get_routes` and `query` methods:
21
+ 1. `get_routes`: Retrieve a list of routes and their associated utterances from the index.
22
+ 2. `query`: Search the index for the query_vector and return top_k results.
23
+ """
24
+ sync: bool
25
+ @abstractmethod
26
+ def get_routes(self) -> dict[str, list[str]]:
27
+ """Retrieves a dictionary of routes and their associated utterances from the index.
28
+
29
+ Returns:
30
+ dict[str, list[str]]: A dictionary where the key is the route name and the value is a list of utterances.
31
+
32
+ Raises:
33
+ NotImplementedError: If the method is not implemented by the subclass.
34
+ """
35
+ @abstractmethod
36
+ def query(self, vector: np.ndarray, top_k: int = 5, route_filter: list[str] | None = None) -> tuple[np.ndarray, list[str]]:
37
+ """Search the index with the input query vector and return top_k results.
38
+
39
+ Args:
40
+ vector (np.ndarray): The input vector to query.
41
+ top_k (int, optional): The number of results to return. Defaults to 5.
42
+ route_filter (list[str] | None, optional): The list of routes to filter the results by. Defaults to None.
43
+
44
+ Returns:
45
+ tuple[np.ndarray, list[str]]: A tuple containing the query vector and the list of results.
46
+
47
+ Raises:
48
+ NotImplementedError: If the method is not implemented by the subclass.
49
+ """
50
+ def add(self, embeddings: list[list[float]], routes: list[str], utterances: list[Any], function_schemas: list[dict[str, Any]] | None = None, metadata_list: list[dict[str, Any]] | None = None) -> None:
51
+ """Add embeddings to the index.
52
+
53
+ This method doesn't need to add any routes to the index since it's assumed that the routes are already in
54
+ the index. Therefore, this method is left empty intentionally.
55
+
56
+ Args:
57
+ embeddings (list[list[float]]): A list of embedded vectors for the documents.
58
+ routes (list[str]): A list of route names for the documents.
59
+ utterances (list[Any]): A list of utterances for the documents.
60
+ function_schemas (list[dict[str, Any]]): List of function schemas to add to the index.
61
+ metadata_list (list[dict[str, Any]]): List of metadata to add to the index.
62
+
63
+ Returns:
64
+ None
65
+ """
@@ -0,0 +1,71 @@
1
+ import numpy as np
2
+ from azure.search.documents import SearchClient
3
+ from gllm_pipeline.router.aurelio_semantic_router.index.aurelio_index import BaseAurelioIndex as BaseAurelioIndex
4
+
5
+ class AzureAISearchAurelioIndexConstants:
6
+ """Defines Azure AI Search Aurelio index related constants."""
7
+ CONTENT_FIELD: str
8
+ SCORE_FIELD: str
9
+ VECTOR_FIELD: str
10
+ VECTOR_SEARCH_TYPE: str
11
+
12
+ class AzureAISearchAurelioIndexDefaults:
13
+ """Defines default values for the AzureAISearchAurelioIndex class."""
14
+ ROUTE_FIELD_NAME: str
15
+ MAX_TOP_K: int
16
+ MAX_SEARCH_ITERATIONS: int
17
+
18
+ class AzureAISearchAurelioIndex(BaseAurelioIndex):
19
+ """A router index implementation for Azure AI Search to be used by the AurelioSemanticRouter.
20
+
21
+ The `AzureAISearchAurelioIndex` class extends the `BaseAurelioIndex` class. It allows an Azure AI Search index to be
22
+ used as a router index by the `AurelioSemanticRouter` class. Just like the `BaseAurelioIndex` class, this class also
23
+ assumes that the routes are already in the index. Therefore, the index will solely be used for retrieval purposes.
24
+
25
+ Attributes:
26
+ client (SearchClient | None): The client to interact with the Azure AI Search index.
27
+ route_field_name (str): The name of the field that contains the route name.
28
+ max_top_k (int): The maximum number of results to return.
29
+ max_search_iterations (int): The maximum number of search iterations to perform.
30
+ sync (bool): Flag to indicate that the index should be synchronized with the routes mapping.
31
+ In this implementation, it's set to `True` by default to make sure that the RouteLayer object initialized
32
+ with this index will perform the syncing process instead of blindly adding the routes to the index.
33
+ """
34
+ client: SearchClient | None
35
+ route_field_name: str
36
+ max_top_k: int
37
+ max_search_iterations: int
38
+ def __init__(self, endpoint: str, index_name: str, api_key: str, route_field_name: str = ..., max_top_k: int = ..., max_search_iterations: int = ...) -> None:
39
+ """Initialize the AzureAISearchIndex with the given service endpoint, index name, and API key.
40
+
41
+ Args:
42
+ endpoint (str): The endpoint of the Azure AI Search service.
43
+ index_name (str): The name of the Azure AI Search index.
44
+ api_key (str): The API key for the Azure AI Search service.
45
+ route_field_name (str, optional): The name of the field that contains the route name.
46
+ Defaults to AzureAISearchAurelioIndexDefaults.ROUTE_FIELD_NAME.
47
+ max_top_k (int, optional): The maximum number of results to return.
48
+ Defaults to AzureAISearchAurelioIndexDefaults.MAX_TOP_K.
49
+ max_search_iterations (int, optional): The maximum number of search iterations to perform.
50
+ Defaults to AzureAISearchAurelioIndexDefaults.MAX_SEARCH_ITERATIONS.
51
+
52
+ Returns:
53
+ None
54
+ """
55
+ def get_routes(self) -> dict[str, list[str]]:
56
+ """Retrieves a dictionary of routes and their associated utterances from the Azure AI Search index.
57
+
58
+ Returns:
59
+ dict[str, list[str]]: A dictionary where the key is the route name and the value is a list of utterances.
60
+ """
61
+ def query(self, vector: np.ndarray, top_k: int = 5, route_filter: list[str] | None = None) -> tuple[np.ndarray, list[str]]:
62
+ """Search the Azure AI Search index with the input query vector and return top_k results.
63
+
64
+ Args:
65
+ vector (np.ndarray): The input vector to query.
66
+ top_k (int, optional): The number of results to return. Defaults to 5.
67
+ route_filter (list[str] | None, optional): The list of routes to filter the results by. Defaults to None.
68
+
69
+ Returns:
70
+ tuple[np.ndarray, list[str]]: A tuple containing the query vector and the list of results.
71
+ """
@@ -0,0 +1,119 @@
1
+ import numpy as np
2
+ from gllm_datastore.vector_data_store.vector_data_store import BaseVectorDataStore as BaseVectorDataStore
3
+ from gllm_pipeline.router.aurelio_semantic_router.index.aurelio_index import BaseAurelioIndex as BaseAurelioIndex
4
+ from gllm_pipeline.router.utils import encode_bytes as encode_bytes
5
+ from semantic_router import Route
6
+ from typing import Any, Callable, TypeVar
7
+
8
+ ROUTE_PAYLOAD_KEY: str
9
+ UTTERANCE_PAYLOAD_KEY: str
10
+ T = TypeVar('T')
11
+
12
+ class VectorStoreAdapterIndex(BaseAurelioIndex):
13
+ """A vector store-backed implementation of BaseAurelioIndex for use with AurelioSemanticRouter.
14
+
15
+ This index performs similarity search over a backend vector store to retrieve relevant
16
+ route payloads. The vector store must implement the BaseVectorDataStore interface and support
17
+ async methods for querying by vector and filtering by metadata.
18
+ """
19
+ index: BaseVectorDataStore
20
+ def __init__(self, index: BaseVectorDataStore, **kwargs: Any) -> None:
21
+ """Initialize the VectorStoreAdapterIndex.
22
+
23
+ Args:
24
+ index (BaseVectorDataStore): The vector store instance used for retrieval.
25
+ **kwargs: Additional keyword arguments forwarded to the BaseAurelioIndex.
26
+ """
27
+ def __len__(self) -> int:
28
+ """Returns the total number of vectors in the index.
29
+
30
+ If the index is not initialized returns 0.
31
+
32
+ Returns:
33
+ int: The total number of vectors.
34
+ """
35
+ def add(self, routes: list[str], utterances: list[str | bytes], **_):
36
+ """Add route-utterance pairs into the vector store.
37
+
38
+ Each utterance is associated with its route and encoded as a Chunk. Binary strings
39
+ are automatically base64-encoded for safe storage.
40
+
41
+ Args:
42
+ routes (list[str]): List of route identifiers.
43
+ utterances (list[str | bytes]): List of utterance strings or bytes.
44
+ **_: Ignored. Included for interface compatibility.
45
+
46
+ Raises:
47
+ AssertionError: If `routes` and `utterances` have different lengths.
48
+ """
49
+ def get_routes(self) -> dict[str, list]:
50
+ """Retrieve all routes and their corresponding utterances from the vector store.
51
+
52
+ Returns:
53
+ dict[str, list]: A dictionary where each key is a route and the value is a
54
+ list of associated utterance strings.
55
+ """
56
+ def query(self, vector: np.ndarray, top_k: int = 5, route_filter: list[str] | None = None, retrieval_params: dict | None = None) -> tuple[np.ndarray, list[str]]:
57
+ """Perform a similarity query using the provided vector, optionally filtering by route.
58
+
59
+ Args:
60
+ vector (np.ndarray): Query vector to search against stored vectors.
61
+ top_k (int, optional): Maximum number of top matching results to return. Defaults to 5.
62
+ route_filter (list[str] | None, optional): Optional list of route names to filter
63
+ the search results by. If None, all routes are considered.
64
+ retrieval_params (dict | None, optional): Filter parameters to narrow the search. Defaults to None.
65
+
66
+ Returns:
67
+ tuple[np.ndarray, list[str]]: A tuple containing:
68
+ - A NumPy array of similarity scores.
69
+ - A list of corresponding route names for each match.
70
+ """
71
+ def is_ready(self):
72
+ """Checks if the index is ready to be used.
73
+
74
+ This is a mandatory method to be implemented from `BaseIndex`.
75
+
76
+ Returns:
77
+ bool: True if the index has one or more vectors; False otherwise.
78
+ """
79
+ async def ais_ready(self) -> None:
80
+ """Checks if the index is ready to be used in async.
81
+
82
+ Returns:
83
+ bool: True if the index has one or more vectors; False otherwise.
84
+ """
85
+ def load_routes_from_json(self, file_path: str, transform_utterance: Callable[[str], str | bytes] | None = None):
86
+ """Load route-utterance pairs from a JSON file and insert them into the vector store.
87
+
88
+ The JSON file must contain a dictionary mapping route names to lists of utterances.
89
+ Each utterance can optionally be transformed before storage.
90
+
91
+ Args:
92
+ file_path (str): Path to a `.json` file containing routes and utterances.
93
+ transform_utterance (Callable[[str], str | bytes] | None): Optional function to
94
+ preprocess each utterance before storage. Must return `str` or `bytes`.
95
+
96
+ Raises:
97
+ ValueError: If the provided file is not a JSON file.
98
+ """
99
+ def load_routes_from_dict(self, routes: list[Route] | dict[str, list[str | bytes]], transform_utterance: Callable[[str], str | bytes] | None = None):
100
+ """Load route-utterance pairs from a list of `Route` or a dictionary and insert into the vector store.
101
+
102
+ This method supports two input formats:
103
+ 1. A list of `Route` objects from `semantic_router`, where each route has a `name` and `utterances`.
104
+ 2. A dictionary mapping route names (str) to lists of utterances (list[str]).
105
+
106
+ Optionally, a `transform_utterance` function can be provided to process each utterance before storage.
107
+ Utterances can be any type; use `transform_utterance` to ensure the final result is str or bytes.
108
+
109
+ Args:
110
+ routes (list[Route] | dict[str, list]): Route data in either list or dictionary format.
111
+ transform_utterance (Callable[[str], str | bytes] | None): Optional function to transform
112
+ each utterance before storage. Must return `str` or `bytes`.
113
+
114
+ Raises:
115
+ ValueError: If `routes` is not a list of `Route` objects or a dictionary,
116
+ if route names are invalid,
117
+ if utterances are not lists of non-empty strings,
118
+ or if transformed utterances are not `str` or `bytes`.
119
+ """