semantic-router
semantic-router copied to clipboard
feat: Add GigaChat Encoder
Summary
This pull request introduces the GigaChatEncoder class, a new encoder for generating embeddings using the GigaChat API. The implementation includes initialization, embedding generation, and error handling functionalities.
Changes
- Added GigaChatEncoder class to the project.
- The encoder class initializes with GigaChat client credentials, name, scope.
- The call method generates embeddings for a list of documents.
- Includes error handling and validation for required attributes.
- Add unit tests and docs
Implementation Details
Initialization:
- The init method initializes the encoder with optional parameters: name, auth_data, scope, and score_threshold.
- The method sets default values using EncoderDefault.GIGACHAT if name is not provided.
- It validates the auth_data and scope parameters, raising ValueError if they are None.
- Initializes the GigaChat client with provided credentials and scope.
Embedding Generation:
- The call method takes a list of documents and generates embeddings.
- Validates that the GigaChat client is initialized.
- Calls the embeddings method of the GigaChat client to generate embeddings.
- Extracts and returns the embeddings as a list of lists.
- Raises a ValueError if the client is not initialized or if the GigaChat call fails.