EmbeddingHandler
EmbeddingHandler is an abstract base class (abc) to handle batch
embeddings. This abstract class lays out the structure and expected
methods for any derived class that is to handle batch embeddings.
Overview
EmbeddingHandler provides a structured interface with four abstract
methods to be implemented by any derived class. These methods provide a
mechanism to get embeddings for a list of symbols, get all the
embeddings in a sorted order, process the embeddings for a list of
symbols, as well as perform any remaining updates following completion
of full batch processing.
Example
As EmbeddingHandler is an abstract base class, it cannot be
instantiated directly and doesn’t provide any functionality on its own.
The following code sample is a mock example of how a subclass may look
like when EmbeddingHandler is extended:
from typing import Any, List
from automata.common.symbol import Symbol
from automata.embedding.embedding_base import EmbeddingHandler
class MyEmbeddingHandler(EmbeddingHandler):
def get_embeddings(self, symbols: List[Symbol]) -> List[Any]:
# Implement method to return embeddings for a list of symbols
pass
def get_all_ordered_embeddings(self) -> List[Any]:
# Implement method to return all embeddings in a sorted order
pass
def process_embedding(self, symbols: Symbol) -> None:
# Implement method to process embeddings for a list of symbols
pass
def flush(self) -> None:
# Implement method to perform any remaining updates
pass
Limitations
The primary limitations of the EmbeddingHandler are tied to specific
implementations in derived classes. Since EmbeddingHandler is an
abstract base class, it doesn’t pose limitations on its own but it gives
a layout to be followed, meaning that the limitations of its
implementations are up to the specific subclass.
Follow-up Questions
Are there more specific templates or guidelines for each of the abstract methods to be implemented for better consistency across different implementations?
Could type hints be provided for the return types of the methods of
EmbeddingHandlerto enhance usage clarity of the respective methods?How are errors and exceptions handled across derived classes of
EmbeddingHandlerconsidering it doesn’t define any error handling procedures in its interface?