📖Advanced Usage
Create your own Custom Memory Component
Each stack component has three Base Interfaces.
Base Interfaces for the Memory component
1. Creating a Custom Memory Component: Create a new class that extends the BaseMemory class. Here's an example of how to create a custom memory.
2. Customizing Memory Logic: In the CustomMemory class, users need to implement the methods defined in the BaseMemory interface. These methods include:
get_user_text(): Implement this method to retrieve the user's query.
get_model_text(): Implement this method to retrieve the model's response.
get_text(): Implement this method to return both the user's query and the model's response, typically as a dictionary or a structured data format.
add_text(user_text, model_text): Implement this method to store both the user's query and the model's response in your custom memory component.
get_chat_history(): Implement this method to retrieve the complete chat conversation history.
3. Custom Configuration data model: Users can also provide the data model for the configurations which will be specific to their custom memory class. create a new custom memory config model class that extends the base memory config model class and specify the configuration fields and their types.
4. Custom Configuration: If you are creating a custom memory config model which contains specific configurations for the custom memory component, then you also need a custom configuration class that extends BaseMemoryConfig to define their own configuration class specific to their custom memory component. For example:
5. Using Custom Configuration: To use the custom configuration class, users can modify their custom memory class to specify the custom configuration class
Last updated