Reference
This part of the project documentation focuses on
an information-oriented approach. Use it as a
reference for the technical implementation of the
Aeiva
project code.
Aeiva API references
action
action
Action
Bases: Step
Represents an action that can be executed, extending from the Step class. An action is a tool with states and state management methods. It can execute functionality.
Source code in src/aeiva/action/action.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
reset()
Resets the step status, making it ready for re-execution.
Source code in src/aeiva/action/action.py
24 25 26 27 28 29 |
|
action_system
ActionSystem
A concrete Action System responsible for translating Plans into executable Skills and managing the execution of Skills.
Source code in src/aeiva/action/action_system.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
experience
Experience
Bases: Procedure
Represents an experience, which is a structured composition of actions. Unlike a skill, an experience cannot be executed until it is validated and transformed into a skill.
Attributes:
Name | Type | Description |
---|---|---|
owner |
str
|
The person or agent who owns the experience. |
reliable |
bool
|
A flag indicating whether the experience is reliable enough to be transformed into a skill. |
Source code in src/aeiva/action/experience.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
|
is_reliable: bool
property
Checks if the experience is reliable enough to be transformed into a skill.
__init__(name, steps, owner=None, reliable=False, id=None, dependent_ids=None, type=None, description=None, metadata=None)
Initializes a Skill by extending Procedure.
Source code in src/aeiva/action/experience.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
mark_reliable()
Marks the experience as reliable, allowing it to be transformed into a skill.
Source code in src/aeiva/action/experience.py
41 42 43 44 45 |
|
to_dict()
Returns a dictionary representation of the object.
Source code in src/aeiva/action/experience.py
69 70 71 72 73 74 75 76 77 78 |
|
to_skill()
Converts this experience into a skill, but only if the experience is marked as reliable. If the experience is not reliable, raises a ValueError.
Returns:
Name | Type | Description |
---|---|---|
Skill |
Skill
|
A new Skill object that is based on the actions from this experience. |
Source code in src/aeiva/action/experience.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
plan
Plan
Bases: Procedure
Represents a plan, which is a structured roadmap for achieving a goal by executing tasks and sub-plans. Inherits common functionality from Procedure.
Source code in src/aeiva/action/plan.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
__init__(name, steps, id=None, dependent_ids=None, type=None, description=None, metadata=None)
Initializes a Skill by extending Procedure.
Source code in src/aeiva/action/plan.py
11 12 13 14 15 16 17 18 19 20 21 22 |
|
procedure
Procedure
Abstract base class for composite structures like Plan and Skill. Contains shared attributes and methods for organizing and managing steps (e.g., tasks, sub-procedures) in a directed acyclic graph (DAG).
Source code in src/aeiva/action/procedure.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
end(success)
Marks the procedure as completed. Raises an error if it hasn't started yet.
Source code in src/aeiva/action/procedure.py
69 70 71 72 73 74 75 |
|
get_topological_sort()
Returns the steps in topologically sorted order based on the dependency graph. Ensures that all prerequisite steps are executed before the dependent ones.
Source code in src/aeiva/action/procedure.py
43 44 45 46 47 48 49 50 51 |
|
reset()
Resets the status of the procedure and all its steps.
Source code in src/aeiva/action/procedure.py
53 54 55 56 57 58 59 |
|
start()
Marks the procedure as in progress. Raises an error if it's already in progress or finished.
Source code in src/aeiva/action/procedure.py
61 62 63 64 65 66 67 |
|
visualize(save_path=None)
Visualizes the procedure's structure using networkx and matplotlib.
Source code in src/aeiva/action/procedure.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|
skill
Skill
Bases: Procedure
Represents a skill, which is a structured roadmap for executing actions. Skills are composed of actions and can be executed. Inherits common functionality from Procedure.
Source code in src/aeiva/action/skill.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
__init__(name, steps, id=None, dependent_ids=None, type=None, description=None, metadata=None)
Initializes a Skill by extending Procedure.
Source code in src/aeiva/action/skill.py
15 16 17 18 19 20 21 22 23 24 25 26 |
|
execute()
async
Executes all actions in the skill based on the dependencies defined in the graph. This will run the actions asynchronously, respecting their dependencies.
Source code in src/aeiva/action/skill.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
get_topological_sort()
Returns the steps in topologically sorted order based on the dependency graph. Ensures that all prerequisite steps are executed before the dependent ones.
Source code in src/aeiva/action/skill.py
28 29 30 31 32 33 |
|
status
Status
A class to hold status constants.
Source code in src/aeiva/action/status.py
1 2 3 4 5 6 7 8 |
|
step
Step
Abstract base class for atomic units like Task and Action. Contains shared attributes and methods for managing their execution and dependencies.
Source code in src/aeiva/action/step.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
is_failed: bool
property
Returns True if the step has finished but failed.
is_finished: bool
property
Returns True if the step has finished execution, either successfully or failed.
is_in_progress: bool
property
Returns True if the step is in progress (executing but not finished).
is_not_started: bool
property
Returns True if the step has not started yet.
is_successful: bool
property
Returns True if the step was completed successfully.
end(success)
Marks the step as finished and indicates whether it was successful. Can only be called if the step is in progress.
Source code in src/aeiva/action/step.py
38 39 40 41 42 43 44 45 |
|
reset()
Resets the step status, making it ready for re-execution.
Source code in src/aeiva/action/step.py
24 25 26 27 28 |
|
start()
Marks the step as in progress. Raises an error if the step is already started or finished.
Source code in src/aeiva/action/step.py
30 31 32 33 34 35 36 |
|
to_dict()
Converts the step into a dictionary representation.
Source code in src/aeiva/action/step.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
task
Task
Bases: Step
Represents the fundamental unit of work, extending from the Step class. Inherits shared attributes and methods from Step and adds task-specific functionality.
Source code in src/aeiva/action/task.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
agent
agent
Agent
Represents the agent that integrates perception, cognition, and action systems.
Source code in src/aeiva/agent/agent.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
|
process_input(input_text)
async
Process input text and return the agent's response.
Source code in src/aeiva/agent/agent.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
run()
async
Run the agent by connecting perception, cognition, and action systems using the event bus.
Source code in src/aeiva/agent/agent.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
setup()
Set up all systems.
Source code in src/aeiva/agent/agent.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|
setup_event_handlers()
Set up event handlers for perception, cognition, and action events.
Source code in src/aeiva/agent/agent.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
|
base_agent
BaseAgent
Bases: ABC
Abstract base class for autonomous agents with perception, cognition, and action capabilities.
Source code in src/aeiva/agent/base_agent.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|
__init__(config)
Initialize the agent with configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Any
|
Configuration settings for the agent. |
required |
Source code in src/aeiva/agent/base_agent.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
cycle()
abstractmethod
async
Execute one cycle of perception, cognition, and action. This method should be overridden to define the agent's behavior per cycle.
Source code in src/aeiva/agent/base_agent.py
51 52 53 54 55 56 57 |
|
handle_error(error)
Handle errors that occur during cycle execution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
error
|
Exception
|
The exception that was raised. |
required |
Source code in src/aeiva/agent/base_agent.py
78 79 80 81 82 83 84 85 86 |
|
initialize_state()
abstractmethod
Initialize the agent's state.
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The initial state of the agent. |
Source code in src/aeiva/agent/base_agent.py
33 34 35 36 37 38 39 40 41 |
|
run()
async
Run the agent, continuously executing cycles until stopped.
Source code in src/aeiva/agent/base_agent.py
59 60 61 62 63 64 65 66 67 68 69 70 |
|
setup()
abstractmethod
Set up the agent's components (perception, cognition, action, etc.). Perform any asynchronous initialization if necessary.
Source code in src/aeiva/agent/base_agent.py
43 44 45 46 47 48 49 |
|
stop()
Signal the agent to stop running.
Source code in src/aeiva/agent/base_agent.py
72 73 74 75 76 |
|
cognition
brain
brain
Brain
Bases: ABC
Abstract base class representing the cognitive processing unit.
The Brain is responsible for processing input stimuli to generate cognitive states that the CognitionSystem will translate into actions.
Attributes:
Name | Type | Description |
---|---|---|
config |
Any
|
Configuration settings for the Brain. |
state |
Any
|
The internal state of the Brain. |
Source code in src/aeiva/cognition/brain/brain.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
__init__(config)
Initialize the Brain with the provided configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Any
|
Configuration settings for the Brain. |
required |
Source code in src/aeiva/cognition/brain/brain.py
19 20 21 22 23 24 25 26 27 |
|
handle_error(error)
Handle errors that occur during cognitive processing.
This method can be overridden to implement custom error handling logic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
error
|
Exception
|
The exception that was raised. |
required |
Source code in src/aeiva/cognition/brain/brain.py
70 71 72 73 74 75 76 77 78 79 80 |
|
init_state()
abstractmethod
Initialize the internal state of the Brain.
This method should set up the initial state required for the Brain's operations.
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The initial state of the Brain. |
Source code in src/aeiva/cognition/brain/brain.py
29 30 31 32 33 34 35 36 37 38 39 |
|
setup()
abstractmethod
Asynchronously set up the Brain's components.
This method should initialize any necessary components or resources based on the provided configuration.
Raises:
Type | Description |
---|---|
ConfigurationError
|
If the configuration is invalid or incomplete. |
Source code in src/aeiva/cognition/brain/brain.py
41 42 43 44 45 46 47 48 49 50 51 52 |
|
think(stimuli, *args, **kwargs)
abstractmethod
async
Asynchronously process input stimuli to update the cognitive state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stimuli
|
Any
|
The input stimuli to process. |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The updated cognitive state. |
Raises:
Type | Description |
---|---|
ProcessingError
|
If processing the stimuli fails. |
Source code in src/aeiva/cognition/brain/brain.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
llm_brain
LLMBrain
Bases: Brain
Concrete implementation of the Brain, using an LLM to process stimuli and generate cognitive states.
This brain uses the LLMClient to communicate with a language model to process input stimuli and produce outputs.
Source code in src/aeiva/cognition/brain/llm_brain.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
__init__(config)
Initialize the LLMBrain with the provided LLM configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
LLMGatewayConfig
|
Configuration settings for the LLMBrain. |
required |
Source code in src/aeiva/cognition/brain/llm_brain.py
18 19 20 21 22 23 24 25 26 27 28 |
|
handle_error(error)
Handle errors that occur during cognitive processing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
error
|
Exception
|
The exception that was raised. |
required |
Source code in src/aeiva/cognition/brain/llm_brain.py
116 117 118 119 120 121 122 123 124 125 |
|
init_state()
Initialize the internal state of the Brain.
The state can track the ongoing conversation or task context.
Returns:
Name | Type | Description |
---|---|---|
dict |
Any
|
Initial empty state. |
Source code in src/aeiva/cognition/brain/llm_brain.py
30 31 32 33 34 35 36 37 38 39 |
|
setup()
Set up the Brain's components.
For the LLMBrain, this might involve validating the LLM configuration and ensuring that all necessary resources are in place.
Source code in src/aeiva/cognition/brain/llm_brain.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
think(stimuli, tools=None, stream=False, use_async=False)
async
Asynchronously process input stimuli to update the cognitive state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stimuli
|
Any
|
The input stimuli to process. |
required |
stream
|
bool
|
Whether to use streaming mode. Default is False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
str |
AsyncGenerator[str, None]
|
The full response in both streaming and non-streaming modes. |
Source code in src/aeiva/cognition/brain/llm_brain.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
|
cognition_system
CognitionSystem
Processes Stimuli into Observations, uses the Brain to generate Thoughts, and orchestrates output into Plans.
Source code in src/aeiva/cognition/cognition_system.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
setup()
Set up the cognition system's components.
Source code in src/aeiva/cognition/cognition_system.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
think(stimuli, tools=None, stream=False, use_async=False)
async
Processes stimuli and produces a thought or plan.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stimuli
|
Stimuli
|
The input stimuli. |
required |
stream
|
bool
|
Whether to use streaming mode. |
False
|
tools
|
List[Dict[str, Any]]
|
Optional tools for function calls. |
None
|
Yields:
Name | Type | Description |
---|---|---|
str |
AsyncGenerator[str, None]
|
Chunks of the assistant's response. |
Source code in src/aeiva/cognition/cognition_system.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
emotion
emotion
ConfigurationError
Bases: Exception
Exception raised for errors in the configuration.
Source code in src/aeiva/cognition/emotion/emotion.py
12 13 14 |
|
Emotion
Bases: ABC
, Generic[T]
Abstract base class representing the Emotion system of an agent with generic state type.
The Emotion system manages the agent's emotional states, allowing it to respond to various stimuli in an emotionally coherent manner.
Attributes:
Name | Type | Description |
---|---|---|
config |
Dict[str, Any]
|
Configuration settings for the Emotion system. |
state |
T
|
The internal emotional state of the agent, defined by subclasses. |
Source code in src/aeiva/cognition/emotion/emotion.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
__init__(config)
Initialize the Emotion system with the provided configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Dict[str, Any]
|
Configuration settings for the Emotion system. |
required |
Source code in src/aeiva/cognition/emotion/emotion.py
38 39 40 41 42 43 44 45 46 |
|
deserialize(data)
abstractmethod
Deserialize the emotional state from a string format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
str
|
Serialized emotional state. |
required |
Source code in src/aeiva/cognition/emotion/emotion.py
120 121 122 123 124 125 126 127 128 |
|
express()
abstractmethod
Generate a representation of the current emotional state.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A string describing the current emotion (e.g., "I feel happy!"). |
Source code in src/aeiva/cognition/emotion/emotion.py
100 101 102 103 104 105 106 107 108 |
|
get_current_state()
Retrieve the current emotional state of the agent.
Returns:
Name | Type | Description |
---|---|---|
T |
T
|
The current emotional state. |
Source code in src/aeiva/cognition/emotion/emotion.py
130 131 132 133 134 135 136 137 |
|
handle_error(error)
Handle errors that occur during emotional processing.
This method can be overridden to implement custom error handling logic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
error
|
Exception
|
The exception that was raised. |
required |
Source code in src/aeiva/cognition/emotion/emotion.py
139 140 141 142 143 144 145 146 147 148 |
|
init_state()
abstractmethod
Initialize the internal emotional state of the Emotion system.
This method should set up the initial emotional state required for the Emotion system's operations.
Returns:
Name | Type | Description |
---|---|---|
T |
T
|
The initial emotional state of the agent. |
Source code in src/aeiva/cognition/emotion/emotion.py
48 49 50 51 52 53 54 55 56 57 58 59 |
|
regulate(strategy)
abstractmethod
Regulate the emotional state using a specified strategy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
strategy
|
str
|
The regulation strategy to apply (e.g., 'suppression', 'amplification'). |
required |
Raises:
Type | Description |
---|---|
RegulationError
|
If the regulation strategy is invalid or fails. |
Source code in src/aeiva/cognition/emotion/emotion.py
87 88 89 90 91 92 93 94 95 96 97 98 |
|
serialize()
abstractmethod
Serialize the current emotional state into a string format.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Serialized emotional state. |
Source code in src/aeiva/cognition/emotion/emotion.py
110 111 112 113 114 115 116 117 118 |
|
setup()
abstractmethod
async
Asynchronously set up the Emotion system's components.
This method should initialize any necessary components or resources based on the provided configuration.
Raises:
Type | Description |
---|---|
ConfigurationError
|
If the configuration is invalid or incomplete. |
Source code in src/aeiva/cognition/emotion/emotion.py
61 62 63 64 65 66 67 68 69 70 71 72 |
|
update(input_data)
abstractmethod
async
Asynchronously update the emotional state based on input data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_data
|
Dict[str, Any]
|
The data or stimuli that influence the emotional state. |
required |
Raises:
Type | Description |
---|---|
UpdateError
|
If updating the emotional state fails. |
Source code in src/aeiva/cognition/emotion/emotion.py
74 75 76 77 78 79 80 81 82 83 84 85 |
|
RegulationError
Bases: Exception
Exception raised for errors during emotion regulation.
Source code in src/aeiva/cognition/emotion/emotion.py
20 21 22 |
|
UpdateError
Bases: Exception
Exception raised for errors during emotion state updates.
Source code in src/aeiva/cognition/emotion/emotion.py
16 17 18 |
|
emotion_categorical
CategoricalEmotionState
Represents the emotional state in a Categorical Model.
Source code in src/aeiva/cognition/emotion/emotion_categorical.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
emotion_category
CategoryEmotionState
dataclass
Represents the emotional state in a Category-Based Model with extensive categories.
Attributes:
Name | Type | Description |
---|---|---|
emotion_label |
str
|
The current emotion category. |
intensity |
float
|
The intensity of the current emotion (range: 0.0 to 1.0). |
Source code in src/aeiva/cognition/emotion/emotion_category.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
emotion_circumplex
CircumplexEmotionState
Represents the emotional state in the Circumplex Model.
Source code in src/aeiva/cognition/emotion/emotion_circumplex.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
emotion_componential
ComponentialEmotionState
dataclass
Represents the emotional state based on the Componential Model.
Attributes:
Name | Type | Description |
---|---|---|
emotion_label |
str
|
Current emotion category. |
intensity |
float
|
Intensity of the emotion (0.0 to 1.0). |
Source code in src/aeiva/cognition/emotion/emotion_componential.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
emotion_hybrid
HybridEmotionState
Represents the emotional state in the Hybrid Categorical-Dimensional Model.
Source code in src/aeiva/cognition/emotion/emotion_hybrid.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
emotion_occ
OCCEmotionState
Represents the emotional state in the OCC Appraisal-Based Model.
Source code in src/aeiva/cognition/emotion/emotion_occ.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
__init__(emotion_categories=None)
Initialize the OCC emotion state with emotion categories and their intensities.
Source code in src/aeiva/cognition/emotion/emotion_occ.py
9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
emotion_pad
PADEmotionState
Represents the emotional state in the PAD Model.
Source code in src/aeiva/cognition/emotion/emotion_pad.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
emotion_plutchik
PlutchikEmotionState
dataclass
Represents the emotional state in Plutchik's Wheel of Emotions.
Attributes:
Name | Type | Description |
---|---|---|
joy |
float
|
Intensity of Joy. |
trust |
float
|
Intensity of Trust. |
fear |
float
|
Intensity of Fear. |
surprise |
float
|
Intensity of Surprise. |
sadness |
float
|
Intensity of Sadness. |
disgust |
float
|
Intensity of Disgust. |
anger |
float
|
Intensity of Anger. |
anticipation |
float
|
Intensity of Anticipation. |
Source code in src/aeiva/cognition/emotion/emotion_plutchik.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
exceptions
ConfigurationError
Bases: Exception
Exception raised for errors in the configuration.
Source code in src/aeiva/cognition/emotion/exceptions.py
3 4 5 |
|
RegulationError
Bases: Exception
Exception raised for errors during emotion regulation.
Source code in src/aeiva/cognition/emotion/exceptions.py
11 12 13 |
|
UpdateError
Bases: Exception
Exception raised for errors during emotion state updates.
Source code in src/aeiva/cognition/emotion/exceptions.py
7 8 9 |
|
memory
memory
Memory
Bases: ABC
Abstract base class for memory operations in the intelligent agent.
This class defines methods corresponding to different layers of memory processing, such as creating, filtering, grouping, deriving, structuring, skillizing, embedding, and parameterizing memory units.
Source code in src/aeiva/cognition/memory/memory.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
|
__init__(config)
Initialize the Memory system with the provided configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Any
|
Configuration settings for the Memory system. |
required |
Source code in src/aeiva/cognition/memory/memory.py
16 17 18 19 20 21 22 23 |
|
create(content, **kwargs)
abstractmethod
Creates a new memory unit with the given content and metadata.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content
|
Any
|
The core content of the memory unit. |
required |
**kwargs
|
Additional metadata for the memory unit. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
MemoryUnit |
MemoryUnit
|
The created memory unit. |
Source code in src/aeiva/cognition/memory/memory.py
37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
delete(unit_id)
abstractmethod
Deletes a memory unit by its unique identifier.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unit_id
|
str
|
The unique identifier of the memory unit. |
required |
Source code in src/aeiva/cognition/memory/memory.py
75 76 77 78 79 80 81 82 83 |
|
delete_all()
abstractmethod
Deletes all memory units.
Source code in src/aeiva/cognition/memory/memory.py
95 96 97 98 99 100 |
|
embed(unit_id)
abstractmethod
Generates an embedding for a memory unit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unit_id
|
str
|
The unique identifier of the memory unit. |
required |
Source code in src/aeiva/cognition/memory/memory.py
186 187 188 189 190 191 192 193 194 |
|
filter(criteria)
abstractmethod
Filters memory units based on the given criteria.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria
|
Dict[str, Any]
|
A dictionary of filter conditions. |
required |
Returns:
Type | Description |
---|---|
List[MemoryUnit]
|
List[MemoryUnit]: A list of memory units matching the criteria. |
Source code in src/aeiva/cognition/memory/memory.py
116 117 118 119 120 121 122 123 124 125 126 127 |
|
get(unit_id)
abstractmethod
Retrieves a memory unit by its unique identifier.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unit_id
|
str
|
The unique identifier of the memory unit. |
required |
Returns:
Name | Type | Description |
---|---|---|
MemoryUnit |
MemoryUnit
|
The retrieved memory unit. |
Source code in src/aeiva/cognition/memory/memory.py
51 52 53 54 55 56 57 58 59 60 61 62 |
|
get_all()
abstractmethod
Retrieves all memory units.
Returns:
Type | Description |
---|---|
List[MemoryUnit]
|
List[MemoryUnit]: A list of all memory units. |
Source code in src/aeiva/cognition/memory/memory.py
85 86 87 88 89 90 91 92 93 |
|
handle_error(error)
Handle errors that occur during memory operations.
This method can be overridden to implement custom error handling logic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
error
|
Exception
|
The exception that was raised. |
required |
Source code in src/aeiva/cognition/memory/memory.py
224 225 226 227 228 229 230 231 232 233 234 |
|
load()
abstractmethod
Loads the memory from file. The path is specified in config.
Source code in src/aeiva/cognition/memory/memory.py
102 103 104 105 106 107 |
|
organize(unit_ids, organize_type, metadata=None)
abstractmethod
Groups memory units into a meaningful group.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unit_ids
|
List[str]
|
A list of memory unit IDs to group. |
required |
organize_type
|
str
|
The type of group (e.g., 'dialogue_session', 'procedure'). |
required |
metadata
|
Optional[Dict[str, Any]]
|
Additional metadata for the group. |
None
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A unique identifier for the created group. |
Source code in src/aeiva/cognition/memory/memory.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
|
parameterize(**kwargs)
abstractmethod
Trains a parametric model using the memory data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Additional parameters for the training process. |
{}
|
Source code in src/aeiva/cognition/memory/memory.py
196 197 198 199 200 201 202 203 204 |
|
retrieve(query, retrieve_type, **kwargs)
abstractmethod
Asynchronously retrieve data from memory based on a query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
Any
|
The query or criteria to retrieve specific memory data. |
required |
retrieve_type
|
str
|
The type of retrieval (e.g., 'retrieve_related', 'retrieve_similar'). |
required |
**kwargs
|
Additional parameters for the structuring process. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Any |
List[MemoryUnit]
|
The retrieved memory data. |
Raises:
Type | Description |
---|---|
RetrievalError
|
If the retrieval process fails. |
Source code in src/aeiva/cognition/memory/memory.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
|
save()
abstractmethod
Save the memory to database or file. The path is specified in config.
Source code in src/aeiva/cognition/memory/memory.py
109 110 111 112 113 114 |
|
setup()
abstractmethod
Asynchronously set up the Memory system's components.
This method should initialize any necessary components or resources based on the provided configuration.
Raises:
Type | Description |
---|---|
ConfigurationError
|
If the configuration is invalid or incomplete. |
Source code in src/aeiva/cognition/memory/memory.py
25 26 27 28 29 30 31 32 33 34 35 |
|
skillize(unit_ids, skill_name, **kwargs)
abstractmethod
Converts memory units into a reusable skill.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unit_ids
|
List[str]
|
A list of memory unit IDs to skillize. |
required |
skill_name
|
str
|
The name of the skill to create. |
required |
**kwargs
|
Additional parameters for skill creation. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The unique identifier of the created skill. |
Source code in src/aeiva/cognition/memory/memory.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
|
structurize(unit_ids, structure_type, **kwargs)
abstractmethod
Structures memory units into a knowledge graph or other structures.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unit_ids
|
List[str]
|
A list of memory unit IDs to structurize. |
required |
structure_type
|
str
|
The type of structure (e.g., 'knowledge_graph'). |
required |
**kwargs
|
Additional parameters for the structuring process. |
{}
|
Source code in src/aeiva/cognition/memory/memory.py
159 160 161 162 163 164 165 166 167 168 169 |
|
update(unit_id, updates)
abstractmethod
Updates a memory unit with the given updates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unit_id
|
str
|
The unique identifier of the memory unit. |
required |
updates
|
Dict[str, Any]
|
A dictionary of fields to update. |
required |
Source code in src/aeiva/cognition/memory/memory.py
64 65 66 67 68 69 70 71 72 73 |
|
memory_cleaner
MemoryCleaner
A class to clean memory units based on various filtering algorithms.
Supported filter types
- 'time': Removes memory units older than a specified threshold.
- 'modality': Keeps only memory units matching specified modalities.
- 'type': Keeps only memory units matching specified types.
Source code in src/aeiva/cognition/memory/memory_cleaner.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
|
__init__()
Initializes the MemoryCleaner.
Currently, no initialization parameters are required.
Source code in src/aeiva/cognition/memory/memory_cleaner.py
26 27 28 29 30 31 32 33 |
|
filter(memory_units, filter_type, **kwargs)
Filters the provided memory units based on the specified filter type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
memory_units
|
List[MemoryUnit]
|
The list of memory units to be filtered. |
required |
filter_type
|
str
|
The type of filtering algorithm to use ('time', 'modality', 'type'). |
required |
**kwargs
|
Additional parameters required for specific filters. For 'time' filter: - threshold_days (int): Number of days beyond which memory units are removed. For 'modality' filter: - modalities (List[str]): List of modalities to retain (e.g., ['text', 'image']). For 'type' filter: - types (List[str]): List of types to retain (e.g., ['dialogue', 'summary']). |
{}
|
Returns:
Type | Description |
---|---|
List[MemoryUnit]
|
List[MemoryUnit]: The list of memory units after filtering. |
Raises:
Type | Description |
---|---|
MemoryCleanerError
|
If an unknown filter_type is provided or if required parameters are missing. |
Source code in src/aeiva/cognition/memory/memory_cleaner.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
filter_by_modality(memory_units, modalities)
Keeps only memory units that match the specified modalities.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
memory_units
|
List[MemoryUnit]
|
The list of memory units to be filtered. |
required |
modalities
|
List[str]
|
List of modalities to retain (e.g., ['text', 'image']). |
required |
Returns:
Type | Description |
---|---|
List[MemoryUnit]
|
List[MemoryUnit]: The list of memory units after modality-based filtering. |
Raises:
Type | Description |
---|---|
MemoryCleanerError
|
If filtering fails. |
Source code in src/aeiva/cognition/memory/memory_cleaner.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
filter_by_time(memory_units, threshold_days)
Removes memory units older than the specified threshold_days.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
memory_units
|
List[MemoryUnit]
|
The list of memory units to be filtered. |
required |
threshold_days
|
int
|
Number of days beyond which memory units are removed. |
required |
Returns:
Type | Description |
---|---|
List[MemoryUnit]
|
List[MemoryUnit]: The list of memory units after time-based filtering. |
Raises:
Type | Description |
---|---|
MemoryCleanerError
|
If filtering fails. |
Source code in src/aeiva/cognition/memory/memory_cleaner.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
filter_by_type(memory_units, types)
Keeps only memory units that match the specified types.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
memory_units
|
List[MemoryUnit]
|
The list of memory units to be filtered. |
required |
types
|
List[str]
|
List of types to retain (e.g., ['dialogue', 'summary']). |
required |
Returns:
Type | Description |
---|---|
List[MemoryUnit]
|
List[MemoryUnit]: The list of memory units after type-based filtering. |
Raises:
Type | Description |
---|---|
MemoryCleanerError
|
If filtering fails. |
Source code in src/aeiva/cognition/memory/memory_cleaner.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
|
MemoryCleanerError
Bases: Exception
Exception raised when an error occurs in the MemoryCleaner.
Source code in src/aeiva/cognition/memory/memory_cleaner.py
11 12 13 |
|
memory_config
MemoryConfig
dataclass
Bases: BaseConfig
Configuration class for the Memory system.
Attributes:
Name | Type | Description |
---|---|---|
embedder_config |
EmbedderConfig
|
Configuration for the embedding model. |
storage_config |
StorageConfig
|
Configuration for the storage system. |
Source code in src/aeiva/cognition/memory/memory_config.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
memory_link
MemoryLink
Bases: BaseModel
MemoryLink represents a relationship between two memory units, allowing complex structures to be built by linking individual memory units.
Attributes:
Name | Type | Description |
---|---|---|
id |
str
|
Unique identifier for the edge, generated as a UUID string by default. |
source_id |
str
|
Unique identifier of the source memory unit. |
target_id |
str
|
Unique identifier of the target memory unit. |
relationship |
str
|
Type of relationship between memory units, such as 'causal' or 'association'. |
metadata |
Optional[Dict[str, Any]]
|
Additional metadata for the edge. |
Source code in src/aeiva/cognition/memory/memory_link.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
from_dict(data)
classmethod
Creates a MemoryLink instance from a dictionary.
Source code in src/aeiva/cognition/memory/memory_link.py
27 28 29 30 |
|
to_dict()
Converts the MemoryLink instance to a dictionary format for serialization.
Source code in src/aeiva/cognition/memory/memory_link.py
23 24 25 |
|
memory_organizer
MemoryOrganizer
A class to organize memory units based on various organizing algorithms.
Supported organize types
- 'dialogue': Groups memory units by 'dialogue_session_id'.
Future organize types can be added here.
Source code in src/aeiva/cognition/memory/memory_organizer.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
|
__init__()
Initializes the MemoryOrganizer.
Currently, no initialization parameters are required.
Source code in src/aeiva/cognition/memory/memory_organizer.py
26 27 28 29 30 31 32 33 |
|
derive_reflection(memory_units)
Derives a reflection from the given memory units.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
memory_units
|
List[MemoryUnit]
|
The list of memory units to reflect upon. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A reflection string. |
Source code in src/aeiva/cognition/memory/memory_organizer.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
|
derive_summary(memory_units)
Derives a summary from the given memory units.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
memory_units
|
List[MemoryUnit]
|
The list of memory units to summarize. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A summary string. |
Source code in src/aeiva/cognition/memory/memory_organizer.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
|
organize(memory_units, organize_type, **kwargs)
Organizes the provided memory units based on the specified organize type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
memory_units
|
List[MemoryUnit]
|
The list of memory units to be organized. |
required |
organize_type
|
str
|
The type of organizing algorithm to use ('dialogue'). |
required |
**kwargs
|
Additional parameters required for specific organizers. For 'dialogue' organize: - group_field (str): The metadata field to group by (default: 'dialogue_session_id'). - derive_content (bool): Whether to derive content for the group (default: True). - derivation_type (str): The type of derivation to perform ('summary', etc.). |
{}
|
Returns:
Type | Description |
---|---|
List[MemoryUnit]
|
List[MemoryUnit]: The list of memory units after organizing. |
Raises:
Type | Description |
---|---|
MemoryOrganizerError
|
If an unknown organize_type is provided or if required parameters are missing. |
Source code in src/aeiva/cognition/memory/memory_organizer.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
|
organize_by_dialogue(memory_units, group_field='dialogue_session_id', derive_content=False, derivation_type='summary')
Organizes memory units into dialogue sessions based on a common 'dialogue_session_id'.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
memory_units
|
List[MemoryUnit]
|
The list of memory units to be organized. |
required |
group_field
|
str
|
The metadata field to group by (default: 'dialogue_session_id'). |
'dialogue_session_id'
|
derive_content
|
bool
|
Whether to derive content for the group (default: True). |
False
|
derivation_type
|
str
|
The type of derivation to perform ('summary', etc.). |
'summary'
|
Returns:
Type | Description |
---|---|
List[MemoryUnit]
|
List[MemoryUnit]: The list of memory units after organizing, including new dialogue groups. |
Raises:
Type | Description |
---|---|
MemoryOrganizerError
|
If organizing fails. |
Source code in src/aeiva/cognition/memory/memory_organizer.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
|
MemoryOrganizerError
Bases: Exception
Exception raised when an error occurs in the MemoryOrganizer.
Source code in src/aeiva/cognition/memory/memory_organizer.py
12 13 14 |
|
memory_palace
MemoryPalace
Bases: Memory
Concrete implementation of the Memory abstract base class.
This class provides methods to manage memory units, including creation, retrieval, updating, deletion, filtering, grouping, structurizing, skillizing, parameterizing, and more. It delegates specific operations to specialized components like MemoryCleaner, MemoryOrganizer, MemoryRetriever, MemoryStructurer, MemorySkillizer, and MemoryParameterizer.
Source code in src/aeiva/cognition/memory/memory_palace.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 |
|
__init__(config)
Initialize the MemoryPalace with the provided configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
MemoryConfig
|
Configuration settings for the MemoryPalace. |
required |
Source code in src/aeiva/cognition/memory/memory_palace.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
create(content, **kwargs)
Creates a new memory unit with the given content and metadata.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content
|
Any
|
The core content of the memory unit. |
required |
**kwargs
|
Additional metadata for the memory unit. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
MemoryUnit |
MemoryUnit
|
The created memory unit. |
Source code in src/aeiva/cognition/memory/memory_palace.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
delete(unit_id)
Deletes a memory unit by its unique identifier.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unit_id
|
str
|
The unique identifier of the memory unit. |
required |
Source code in src/aeiva/cognition/memory/memory_palace.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
delete_all()
Deletes all memory units.
Source code in src/aeiva/cognition/memory/memory_palace.py
197 198 199 200 201 202 203 204 205 206 207 |
|
embed(unit_id)
Generates an embedding for a memory unit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unit_id
|
str
|
The unique identifier of the memory unit. |
required |
Source code in src/aeiva/cognition/memory/memory_palace.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
|
filter(criteria)
Filters memory units based on the given criteria.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria
|
Dict[str, Any]
|
A dictionary of filter conditions. |
required |
Returns:
Type | Description |
---|---|
List[MemoryUnit]
|
List[MemoryUnit]: A list of memory units matching the criteria. |
Source code in src/aeiva/cognition/memory/memory_palace.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
|
get(unit_id)
Retrieves a memory unit by its unique identifier.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unit_id
|
str
|
The unique identifier of the memory unit. |
required |
Returns:
Name | Type | Description |
---|---|---|
MemoryUnit |
MemoryUnit
|
The retrieved memory unit. |
Source code in src/aeiva/cognition/memory/memory_palace.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
|
get_all()
Retrieves all memory units.
Returns:
Type | Description |
---|---|
List[MemoryUnit]
|
List[MemoryUnit]: A list of all memory units. |
Source code in src/aeiva/cognition/memory/memory_palace.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
get_api_key(config_section, key_field, env_var_field)
staticmethod
Retrieve an API key from the configuration section.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_section
|
Dict[str, Any]
|
The configuration section (e.g., embedder_config). |
required |
key_field
|
str
|
The key in the config_section that may contain the API key directly. |
required |
env_var_field
|
str
|
The key in the config_section that specifies the environment variable name. |
required |
Returns:
Type | Description |
---|---|
Optional[str]
|
Optional[str]: The API key if found, else None. |
Raises:
Type | Description |
---|---|
EnvironmentError
|
If the environment variable is specified but not set. |
Source code in src/aeiva/cognition/memory/memory_palace.py
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 |
|
handle_error(error)
Handle errors that occur during memory operations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
error
|
Exception
|
The exception that was raised. |
required |
Source code in src/aeiva/cognition/memory/memory_palace.py
427 428 429 430 431 432 433 434 |
|
load()
Loads all memory units from the storage.
Returns:
Type | Description |
---|---|
List[MemoryUnit]
|
List[MemoryUnit]: A list of all loaded memory units. |
Source code in src/aeiva/cognition/memory/memory_palace.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
organize(unit_ids, organize_type, metadata=None)
Groups memory units into a meaningful group.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unit_ids
|
List[str]
|
A list of memory unit IDs to group. |
required |
organize_type
|
str
|
The type of group (e.g., 'dialogue_session', 'procedure'). |
required |
metadata
|
Optional[Dict[str, Any]]
|
Additional metadata for the group. |
None
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A unique identifier for the created group. |
Source code in src/aeiva/cognition/memory/memory_palace.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
|
parameterize(**kwargs)
Trains a parametric model using the memory data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Additional parameters for the training process. |
{}
|
Source code in src/aeiva/cognition/memory/memory_palace.py
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
|
retrieve(query, retrieve_type, **kwargs)
Retrieve data from memory based on a query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
Any
|
The query or criteria to retrieve specific memory data. |
required |
retrieve_type
|
str
|
The type of retrieval (e.g., 'similar', 'related'). |
required |
**kwargs
|
Additional parameters for the retrieval process. |
{}
|
Returns:
Type | Description |
---|---|
List[MemoryUnit]
|
List[MemoryUnit]: The retrieved memory data. |
Source code in src/aeiva/cognition/memory/memory_palace.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
|
save(export_path=None)
Saves all memory units to the storage or exports them to a specified path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
export_path
|
Optional[str]
|
The file path to export memory units as JSON. If None, saves are handled by MemoryStorage. |
None
|
Source code in src/aeiva/cognition/memory/memory_palace.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
|
setup()
Setup the MemoryPalace by initializing all components.
Source code in src/aeiva/cognition/memory/memory_palace.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
skillize(unit_ids, skill_name, **kwargs)
Converts memory units into a reusable skill.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unit_ids
|
List[str]
|
A list of memory unit IDs to skillize. |
required |
skill_name
|
str
|
The name of the skill to create. |
required |
**kwargs
|
Additional parameters for skill creation. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The unique identifier of the created skill. |
Source code in src/aeiva/cognition/memory/memory_palace.py
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
|
structurize(unit_ids, structure_type, **kwargs)
Structures memory units into a knowledge graph or other structures.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unit_ids
|
List[str]
|
A list of memory unit IDs to structurize. |
required |
structure_type
|
str
|
The type of structure (e.g., 'knowledge_graph'). |
required |
**kwargs
|
Additional parameters for the structuring process. |
{}
|
Source code in src/aeiva/cognition/memory/memory_palace.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
|
update(unit_id, updates)
Updates a memory unit with the given updates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unit_id
|
str
|
The unique identifier of the memory unit. |
required |
updates
|
Dict[str, Any]
|
A dictionary of fields to update. |
required |
Source code in src/aeiva/cognition/memory/memory_palace.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|
memory_parameterizer
MemoryParameterizer
A class to parameterize memory units based on various parameterizing algorithms.
Supported parameterize types
- 'parameterize_type_example': Placeholder for future parameterizing algorithms.
Source code in src/aeiva/cognition/memory/memory_parameterizer.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
__init__()
Initializes the MemoryParameterizer.
Currently, no initialization parameters are required.
Source code in src/aeiva/cognition/memory/memory_parameterizer.py
23 24 25 26 27 28 29 30 |
|
parameterize(memory_units, parameterize_type, **kwargs)
Parameterizes the provided memory units based on the specified parameterize type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
memory_units
|
List[MemoryUnit]
|
The list of memory units to be parameterized. |
required |
parameterize_type
|
str
|
The type of parameterizing algorithm to use ('parameterize_type_example'). |
required |
**kwargs
|
Additional parameters required for specific parameterizers. |
{}
|
Returns:
Type | Description |
---|---|
List[MemoryUnit]
|
List[MemoryUnit]: The list of memory units after parameterization. |
Raises:
Type | Description |
---|---|
MemoryParameterizerError
|
If an unknown parameterize_type is provided or if parameterizing fails. |
Source code in src/aeiva/cognition/memory/memory_parameterizer.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
parameterize_example(memory_units, **kwargs)
Example parameterizing method. Currently a placeholder that returns memory units unchanged.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
memory_units
|
List[MemoryUnit]
|
The list of memory units to be parameterized. |
required |
**kwargs
|
Additional parameters (currently unused). |
{}
|
Returns:
Type | Description |
---|---|
List[MemoryUnit]
|
List[MemoryUnit]: The original list of memory units, unchanged. |
Source code in src/aeiva/cognition/memory/memory_parameterizer.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
MemoryParameterizerError
Bases: Exception
Exception raised when an error occurs in the MemoryParameterizer.
Source code in src/aeiva/cognition/memory/memory_parameterizer.py
10 11 12 |
|
memory_retriever
MemoryRetriever
A class to retrieve memory units based on various retrieval algorithms.
Supported retrieval types
- 'similar': Retrieves memory units similar to a given query based on embeddings.
- 'related': Retrieves memory units related to a specified query based on relationships.
Source code in src/aeiva/cognition/memory/memory_retriever.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
|
__init__(embedder, storage)
Initializes the MemoryRetriever.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
embedder
|
Embedder
|
An instance responsible for generating embeddings. |
required |
storage
|
MemoryStorage
|
An instance managing data storage and retrieval. |
required |
Source code in src/aeiva/cognition/memory/memory_retriever.py
25 26 27 28 29 30 31 32 33 34 35 36 |
|
handle_error(error)
Handles errors by logging or performing other necessary actions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
error
|
Exception
|
The exception to handle. |
required |
Source code in src/aeiva/cognition/memory/memory_retriever.py
167 168 169 170 171 172 173 174 175 176 |
|
retrieve(query, retrieve_type, **kwargs)
Factory method to retrieve memory units based on the specified retrieval type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
Any
|
The query for retrieval. |
required |
retrieve_type
|
str
|
The type of retrieval ('similar' or 'related'). |
required |
**kwargs
|
Additional parameters required for specific retrieval types. For 'similar' retrieval: - top_k (int): The number of similar units to retrieve. For 'related' retrieval: - relationship (Optional[str]): The type of relationship to filter by. |
{}
|
Returns:
Type | Description |
---|---|
List[MemoryUnit]
|
List[MemoryUnit]: A list of retrieved memory units. |
Raises:
Type | Description |
---|---|
MemoryRetrieverError
|
If an unknown retrieval_type is provided or if retrieval fails. |
Source code in src/aeiva/cognition/memory/memory_retriever.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
retrieve_related(query, relationship=None)
Retrieves memory units related to the given query based on relationships.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
Any
|
The query for retrieval. Expected to be a MemoryUnit ID or similar identifier. |
required |
relationship
|
Optional[str]
|
The type of relationship to filter by. |
None
|
Returns:
Type | Description |
---|---|
List[MemoryUnit]
|
List[MemoryUnit]: A list of related memory units. |
Raises:
Type | Description |
---|---|
MemoryRetrieverError
|
If retrieval fails due to storage issues or invalid queries. |
Source code in src/aeiva/cognition/memory/memory_retriever.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
|
retrieve_similar(query, top_k=5)
Retrieves memory units similar to the given input based on embeddings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
Any
|
The query for retrieval. |
required |
top_k
|
int
|
The number of similar units to retrieve. |
5
|
Returns:
Type | Description |
---|---|
List[MemoryUnit]
|
List[MemoryUnit]: A list of similar memory units. |
Raises:
Type | Description |
---|---|
MemoryRetrieverError
|
If retrieval fails due to embedding generation or storage issues. |
Source code in src/aeiva/cognition/memory/memory_retriever.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
MemoryRetrieverError
Bases: Exception
Exception raised when an error occurs in the MemoryRetriever.
Source code in src/aeiva/cognition/memory/memory_retriever.py
11 12 13 |
|
memory_skillizer
MemorySkillizer
A class to skillize memory units based on various skillizing algorithms.
Supported skill types
- 'skill_type_example': Placeholder for future skillizing algorithms.
Source code in src/aeiva/cognition/memory/memory_skillizer.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
__init__()
Initializes the MemorySkillizer.
Currently, no initialization parameters are required.
Source code in src/aeiva/cognition/memory/memory_skillizer.py
23 24 25 26 27 28 29 30 |
|
skillize(memory_units, skill_type, **kwargs)
Skillizes the provided memory units based on the specified skill type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
memory_units
|
List[MemoryUnit]
|
The list of memory units to be skillized. |
required |
skill_type
|
str
|
The type of skillizing algorithm to use ('skill_type_example'). |
required |
**kwargs
|
Additional parameters required for specific skillizers. |
{}
|
Returns:
Type | Description |
---|---|
List[MemoryUnit]
|
List[MemoryUnit]: The list of memory units after skillizing. |
Raises:
Type | Description |
---|---|
MemorySkillizerError
|
If an unknown skill_type is provided or if skillizing fails. |
Source code in src/aeiva/cognition/memory/memory_skillizer.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
skillize_example(memory_units, **kwargs)
Example skillizing method. Currently a placeholder that returns memory units unchanged.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
memory_units
|
List[MemoryUnit]
|
The list of memory units to be skillized. |
required |
**kwargs
|
Additional parameters (currently unused). |
{}
|
Returns:
Type | Description |
---|---|
List[MemoryUnit]
|
List[MemoryUnit]: The original list of memory units, unchanged. |
Source code in src/aeiva/cognition/memory/memory_skillizer.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
MemorySkillizerError
Bases: Exception
Exception raised when an error occurs in the MemorySkillizer.
Source code in src/aeiva/cognition/memory/memory_skillizer.py
10 11 12 |
|
memory_storage
MemoryEventRepository
Repository for MemoryEvent to handle CRUD operations without SQLAlchemy.
Source code in src/aeiva/cognition/memory/memory_storage.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
|
__init__(db)
Initialize the repository with a DatabaseFactory instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db
|
Any
|
An instance of DatabaseFactory for relational databases. |
required |
Source code in src/aeiva/cognition/memory/memory_storage.py
198 199 200 201 202 203 204 205 206 207 |
|
add(event)
Adds a MemoryEvent to the relational database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event
|
Dict[str, Any]
|
The event data to add. |
required |
Source code in src/aeiva/cognition/memory/memory_storage.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
|
delete_all()
Deletes all MemoryEvents from the relational database.
Source code in src/aeiva/cognition/memory/memory_storage.py
263 264 265 266 267 268 |
|
get(event_id)
Retrieves a MemoryEvent by its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event_id
|
str
|
The unique identifier of the event. |
required |
Returns:
Type | Description |
---|---|
Optional[Dict[str, Any]]
|
Optional[Dict[str, Any]]: The event data or None if not found. |
Source code in src/aeiva/cognition/memory/memory_storage.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
|
list_all()
Retrieves all MemoryEvents from the relational database.
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of all events. |
Source code in src/aeiva/cognition/memory/memory_storage.py
270 271 272 273 274 275 276 277 278 279 |
|
MemoryStorage
Handles storage operations for MemoryPalace, including interactions with vector, graph, and relational databases.
Source code in src/aeiva/cognition/memory/memory_storage.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 |
|
__init__(config)
Initialize the MemoryStorage with the provided configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Any
|
Configuration settings for MemoryStorage. |
required |
Source code in src/aeiva/cognition/memory/memory_storage.py
307 308 309 310 311 312 313 314 315 316 |
|
add_memory_unit(memory_unit)
Adds a MemoryUnit to all configured databases.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
memory_unit
|
MemoryUnit
|
The memory unit to add. |
required |
Source code in src/aeiva/cognition/memory/memory_storage.py
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
|
delete_all_memory_units()
Deletes all MemoryUnits from all configured databases.
Source code in src/aeiva/cognition/memory/memory_storage.py
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 |
|
delete_memory_unit(unit_id)
Deletes a MemoryUnit from all configured databases.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unit_id
|
str
|
The unique identifier of the memory unit. |
required |
Source code in src/aeiva/cognition/memory/memory_storage.py
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 |
|
get_all_memory_units()
Retrieves all MemoryUnits from the relational database.
Returns:
Type | Description |
---|---|
List[MemoryUnit]
|
List[MemoryUnit]: A list of all memory units. |
Source code in src/aeiva/cognition/memory/memory_storage.py
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 |
|
get_memory_unit(unit_id)
Retrieves a MemoryUnit by its unique identifier from the relational database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unit_id
|
str
|
The unique identifier of the memory unit. |
required |
Returns:
Name | Type | Description |
---|---|---|
MemoryUnit |
MemoryUnit
|
The retrieved memory unit. |
Source code in src/aeiva/cognition/memory/memory_storage.py
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 |
|
handle_error(error)
Handle errors that occur during storage operations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
error
|
Exception
|
The exception that was raised. |
required |
Source code in src/aeiva/cognition/memory/memory_storage.py
398 399 400 401 402 403 404 405 |
|
retrieve_related_memory_units(unit_id, relationship=None)
Retrieves memory units related to the given one based on relationships.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unit_id
|
str
|
The unique identifier of the memory unit. |
required |
relationship
|
Optional[str]
|
Filter by relationship type. |
None
|
Returns:
Type | Description |
---|---|
List[MemoryUnit]
|
List[MemoryUnit]: A list of related memory units. |
Source code in src/aeiva/cognition/memory/memory_storage.py
873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 |
|
retrieve_similar_memory_units(query_embedding, top_k)
Retrieves memory units similar to the given embedding.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query_embedding
|
List[float]
|
The embedding vector of the query. |
required |
top_k
|
int
|
The number of similar units to retrieve. |
required |
Returns:
Type | Description |
---|---|
List[MemoryUnit]
|
List[MemoryUnit]: A list of similar memory units. |
Source code in src/aeiva/cognition/memory/memory_storage.py
841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 |
|
setup()
Set up the MemoryStorage's components based on the provided configuration.
Source code in src/aeiva/cognition/memory/memory_storage.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
|
update_memory_unit(unit_id, updates)
Updates a MemoryUnit in all configured databases.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unit_id
|
str
|
The unique identifier of the memory unit. |
required |
updates
|
Dict[str, Any]
|
The updates to apply. |
required |
Source code in src/aeiva/cognition/memory/memory_storage.py
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 |
|
MemoryUnitRepository
Repository for MemoryUnit to handle CRUD operations without SQLAlchemy.
Source code in src/aeiva/cognition/memory/memory_storage.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
|
__init__(db)
Initialize the repository with a DatabaseFactory instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db
|
Any
|
An instance of DatabaseFactory for relational databases. |
required |
Source code in src/aeiva/cognition/memory/memory_storage.py
24 25 26 27 28 29 30 31 32 33 |
|
add(memory_unit)
Adds a MemoryUnit to the relational database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
memory_unit
|
MemoryUnit
|
The memory unit to add. |
required |
Source code in src/aeiva/cognition/memory/memory_storage.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
delete(unit_id)
Deletes a MemoryUnit from the relational database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unit_id
|
str
|
The unique identifier of the memory unit to delete. |
required |
Source code in src/aeiva/cognition/memory/memory_storage.py
137 138 139 140 141 142 143 144 145 |
|
delete_all()
Deletes all MemoryUnits from the relational database.
Source code in src/aeiva/cognition/memory/memory_storage.py
158 159 160 161 162 163 |
|
get(unit_id)
Retrieves a MemoryUnit by its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unit_id
|
str
|
The unique identifier of the memory unit. |
required |
Returns:
Type | Description |
---|---|
Optional[MemoryUnit]
|
Optional[MemoryUnit]: The retrieved memory unit or None if not found. |
Source code in src/aeiva/cognition/memory/memory_storage.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
list_all()
Retrieves all MemoryUnits from the relational database.
Returns:
Type | Description |
---|---|
List[MemoryUnit]
|
List[MemoryUnit]: A list of all memory units. |
Source code in src/aeiva/cognition/memory/memory_storage.py
147 148 149 150 151 152 153 154 155 156 |
|
update(memory_unit)
Updates an existing MemoryUnit in the relational database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
memory_unit
|
MemoryUnit
|
The memory unit with updated data. |
required |
Source code in src/aeiva/cognition/memory/memory_storage.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|
memory_structurer
MemoryStructurer
A class to structure memory units based on various structuring algorithms.
Supported structure types
- 'structure_type_example': Placeholder for future structuring algorithms.
Source code in src/aeiva/cognition/memory/memory_structurer.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
__init__()
Initializes the MemoryStructurer.
Currently, no initialization parameters are required.
Source code in src/aeiva/cognition/memory/memory_structurer.py
23 24 25 26 27 28 29 30 |
|
structure(memory_units, structure_type, **kwargs)
Structures the provided memory units based on the specified structure type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
memory_units
|
List[MemoryUnit]
|
The list of memory units to be structured. |
required |
structure_type
|
str
|
The type of structuring algorithm to use ('structure_type_example'). |
required |
**kwargs
|
Additional parameters required for specific structurers. |
{}
|
Returns:
Type | Description |
---|---|
List[MemoryUnit]
|
List[MemoryUnit]: The list of memory units after structuring. |
Raises:
Type | Description |
---|---|
MemoryStructurerError
|
If an unknown structure_type is provided or if structuring fails. |
Source code in src/aeiva/cognition/memory/memory_structurer.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
structure_example(memory_units, **kwargs)
Example structuring method. Currently a placeholder that returns memory units unchanged.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
memory_units
|
List[MemoryUnit]
|
The list of memory units to be structured. |
required |
**kwargs
|
Additional parameters (currently unused). |
{}
|
Returns:
Type | Description |
---|---|
List[MemoryUnit]
|
List[MemoryUnit]: The original list of memory units, unchanged. |
Source code in src/aeiva/cognition/memory/memory_structurer.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
MemoryStructurerError
Bases: Exception
Exception raised when an error occurs in the MemoryStructurer.
Source code in src/aeiva/cognition/memory/memory_structurer.py
10 11 12 |
|
memory_unit
MemoryUnit
Bases: BaseModel
MemoryUnit represents a single unit of memory with core content and rich metadata. It includes fields for tracking information about the memory’s source, modality, temporal and spatial attributes, and its connections to other memory units.
Essential Fields
id (str): Unique identifier for the memory unit, generated as a UUID string by default. content (Any): Core content of the memory, which is convertible to a string.
Source Information
source_role (Optional[str]): Role of the source, e.g., 'user', 'agent'. source_name (Optional[str]): Descriptive name of the source. source_id (Optional[str]): Unique identifier for the memory source, generated as a UUID string.
Connections
edges (List[MemoryLink]): List of edges connecting this memory unit to others.
Source code in src/aeiva/cognition/memory/memory_unit.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
from_dict(data)
classmethod
Creates a MemoryUnit instance from a dictionary. Each field is handled explicitly to ensure proper deserialization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
dict
|
A dictionary containing MemoryUnit data. |
required |
Returns:
Name | Type | Description |
---|---|---|
MemoryUnit |
MemoryUnit
|
The created MemoryUnit instance. |
Source code in src/aeiva/cognition/memory/memory_unit.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
to_dict()
Converts the MemoryUnit instance to a dictionary format for serialization. Each field is handled explicitly to ensure proper serialization.
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary representation of the MemoryUnit. |
Source code in src/aeiva/cognition/memory/memory_unit.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
memory_utils
derive_content(derivation_type, data)
You are a creative assistant capable of deriving new content based on specified types. Your task is to derive a {derivation_type} from the provided combined content.
Source code in src/aeiva/cognition/memory/memory_utils.py
15 16 17 18 19 20 21 22 |
|
extract_entities_relationships(data)
You are an intelligent assistant skilled in natural language processing. Your task is to extract entities and the relationships between them from the provided content.
Source code in src/aeiva/cognition/memory/memory_utils.py
6 7 8 9 10 11 12 13 |
|
storage_config
StorageConfig
dataclass
Bases: BaseConfig
Configuration class for the Memory storage.
Attributes:
Name | Type | Description |
---|---|---|
vector_db_config |
DatabaseConfig
|
Configuration for the vector database. |
graph_db_config |
Optional[DatabaseConfig]
|
Configuration for the graph database. |
relational_db_config |
Optional[DatabaseConfig]
|
Configuration for the relational database. |
Source code in src/aeiva/cognition/memory/storage_config.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
observation
Observation
Represents a processed input from the PerceptionSystem.
Source code in src/aeiva/cognition/observation.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
thought
Thought
Represents the output from the Brain after processing an Observation.
Source code in src/aeiva/cognition/thought.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
world_model
world_model
WorldModel
Bases: ABC
Abstract base class representing the World Model system of an agent.
The World Model maintains an internal representation of the environment, enabling the agent to understand, predict, and interact with its surroundings effectively.
Attributes:
Name | Type | Description |
---|---|---|
config |
Any
|
Configuration settings for the World Model system. |
state |
Any
|
The internal state of the World Model system. |
Source code in src/aeiva/cognition/world_model/world_model.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
|
__init__(config)
Initialize the World Model system with the provided configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Any
|
Configuration settings for the World Model system. |
required |
Source code in src/aeiva/cognition/world_model/world_model.py
19 20 21 22 23 24 25 26 27 |
|
get_current_state()
Retrieve the current internal state of the World Model system.
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The current internal state. |
Source code in src/aeiva/cognition/world_model/world_model.py
82 83 84 85 86 87 88 89 |
|
handle_error(error)
Handle errors that occur during world model operations.
This method can be overridden to implement custom error handling logic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
error
|
Exception
|
The exception that was raised. |
required |
Source code in src/aeiva/cognition/world_model/world_model.py
91 92 93 94 95 96 97 98 99 100 101 |
|
init_state()
abstractmethod
Initialize the internal state of the World Model system.
This method should set up the initial state required for the World Model system's operations.
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The initial state of the World Model system. |
Source code in src/aeiva/cognition/world_model/world_model.py
29 30 31 32 33 34 35 36 37 38 39 |
|
query(query)
abstractmethod
async
Asynchronously query the world model for specific information.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
Any
|
The query or criteria to retrieve specific information from the world model. |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The information retrieved from the world model. |
Raises:
Type | Description |
---|---|
QueryError
|
If the query process fails. |
Source code in src/aeiva/cognition/world_model/world_model.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
setup()
abstractmethod
Asynchronously set up the World Model system's components.
This method should initialize any necessary components or resources based on the provided configuration.
Raises:
Type | Description |
---|---|
ConfigurationError
|
If the configuration is invalid or incomplete. |
Source code in src/aeiva/cognition/world_model/world_model.py
41 42 43 44 45 46 47 48 49 50 51 |
|
update(observation)
abstractmethod
async
Asynchronously update the world model based on new observations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observation
|
Any
|
The new observation to incorporate into the world model. |
required |
Raises:
Type | Description |
---|---|
UpdateError
|
If updating the world model fails. |
Source code in src/aeiva/cognition/world_model/world_model.py
53 54 55 56 57 58 59 60 61 62 63 64 |
|
command
aeiva_chat_gradio
We can run the command like below: (specify your own config file path)
aeiva-chat-gradio --config configs/agent_config.yaml
run(config, verbose)
Starts the Aeiva chat Gradio interface with the provided configuration.
Source code in src/aeiva/command/aeiva_chat_gradio.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 |
|
aeiva_chat_terminal
We can run the command like below: (specify your own config file path)
aeiva-chat-terminal --config configs/agent_config.yaml
run(config, verbose)
Starts the Aeiva chat terminal with the provided configuration.
Source code in src/aeiva/command/aeiva_chat_terminal.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
aeiva_server
run(config, host, port, verbose)
Starts the Aeiva Agent Server using FastAPI.
Source code in src/aeiva/command/aeiva_server.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
|
command_utils
Here we put util functions related to database, logging and so on for different aeiva commands execution.
get_log_dir()
Determines a suitable path for the log file. Logs are stored in the user's home directory under '.aeiva/logs/'.
Source code in src/aeiva/command/command_utils.py
24 25 26 27 28 29 30 31 32 |
|
get_package_root()
Determines the root path of the 'aeiva' package.
Source code in src/aeiva/command/command_utils.py
16 17 18 19 20 21 22 |
|
handle_exit(signum, frame, logger, neo4j_process)
Handles termination signals to ensure Neo4j is stopped gracefully.
Source code in src/aeiva/command/command_utils.py
134 135 136 137 138 139 140 141 |
|
setup_logging(log_file, verbose=False)
Sets up logging to both file and console.
Source code in src/aeiva/command/command_utils.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
start_neo4j(logger, neo4j_home)
Starts the Neo4j database as a subprocess.
Source code in src/aeiva/command/command_utils.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
stop_neo4j(logger, neo4j_process)
Stops the Neo4j database subprocess gracefully.
Source code in src/aeiva/command/command_utils.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
validate_neo4j_home(logger, neo4j_home)
Validates that the NEO4J_HOME path exists and contains the Neo4j executable.
Source code in src/aeiva/command/command_utils.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|
maid_chat
run(config, host, port, verbose)
Starts the Aeiva Agent Server and launches the Unity application.
Source code in src/aeiva/command/maid_chat.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
|
start_unity_app(maid_home, logger)
Starts the Unity application.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
maid_home
|
str
|
Path to the Unity application executable. |
required |
logger
|
Logger
|
Logger instance. |
required |
Returns:
Type | Description |
---|---|
Optional[Popen]
|
Optional[subprocess.Popen]: The subprocess running the Unity application, or None if failed. |
Source code in src/aeiva/command/maid_chat.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
stop_unity_app(unity_process, logger)
Stops the Unity application gracefully.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unity_process
|
Popen
|
The subprocess running the Unity application. |
required |
logger
|
Logger
|
Logger instance. |
required |
Source code in src/aeiva/command/maid_chat.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
common
decorators
import_submodules(package, recursive=True)
Import all submodules of a module, recursively, including subpackages
Source code in src/aeiva/common/decorators.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
id_generator
IDGenerator
A simple class to generate unique IDs for distinct names.
Attributes:
Name | Type | Description |
---|---|---|
name_to_id |
dict
|
A dictionary to map names to IDs. |
next_id |
int
|
The next ID to be assigned. |
Source code in src/aeiva/common/id_generator.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
__init__()
Constructs all the necessary attributes for the IDGenerator object.
Attributes:
Name | Type | Description |
---|---|---|
name_to_id |
dict
|
Initializes an empty dictionary to map names to IDs. |
next_id |
int
|
Initializes the next ID to be assigned as 0. |
Source code in src/aeiva/common/id_generator.py
10 11 12 13 14 15 16 17 18 19 |
|
get_id(name)
Returns the ID of the 'name'. If 'name' does not exist, assigns a new ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name for which the ID is required. |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
The ID associated with the 'name'. |
Source code in src/aeiva/common/id_generator.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
pipeline
Pipeline
This class is used to rurn a list of functions into a pipeline.
Source code in src/aeiva/common/pipeline.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
types
DataBatch
Bases: TypedDict
DataBatch is a batch of data items created by a dataloader.
Source code in src/aeiva/common/types.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|
DataItem
Bases: TypedDict
DataItem is a dictionary that contains all the information for a single data item.
Source code in src/aeiva/common/types.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
DataSet
Bases: TypedDict
DataSet is a dictionary that contains data items and meta information.
Source code in src/aeiva/common/types.py
25 26 27 28 29 |
|
ModelInput
Bases: TypedDict
ModelInput is a dictionary that contains all the information for a model input. We use it to construct LEGO style models.
Source code in src/aeiva/common/types.py
63 64 65 66 67 |
|
ModelOutput
Bases: TypedDict
ModelOutput is a dictionary that contains all the information for a model output. We use it to construct LEGO style models.
Source code in src/aeiva/common/types.py
70 71 72 73 74 |
|
TaskContext
Bases: TypedDict
TaskContext is a dictionary that contains all the information for a task.
Source code in src/aeiva/common/types.py
49 50 51 52 53 54 55 56 57 58 59 60 |
|
config
DataConfig
dataclass
Bases: BaseConfig
This class contains the data configuration.
Source code in src/aeiva/config/general_configs.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
ExplicitEnum
Bases: str
, Enum
Enum with more explicit error message for missing values.
Source code in src/aeiva/config/general_configs.py
26 27 28 29 30 31 32 33 34 |
|
ModelConfig
dataclass
Bases: BaseConfig
Model configuration class.
Source code in src/aeiva/config/general_configs.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
|
OptimizerNames
Bases: ExplicitEnum
Stores the acceptable string identifiers for optimizers.
Source code in src/aeiva/config/general_configs.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
base_config
This module contains the base config classes.
We can define separate config classes for different modules, e.g., data, model, trainer, llm, etc. They will be automatically registered in the BaseConfig class.
Copyright (C) 2023 Bang Liu - All Rights Reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree.
BaseConfig
dataclass
Base class for all configuration classes.
Source code in src/aeiva/config/base_config.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
__init_subclass__(**kwargs)
This method is called when a subclass is created.
Source code in src/aeiva/config/base_config.py
28 29 30 31 32 33 |
|
__post_init__()
Empty post-init to allow subclasses to call super().post_init().
Source code in src/aeiva/config/base_config.py
35 36 37 38 39 |
|
__str__()
Return a string representation of the instance.
Source code in src/aeiva/config/base_config.py
103 104 105 106 107 |
|
from_dict(data)
classmethod
Create a new instance of the class from a dictionary.
Source code in src/aeiva/config/base_config.py
41 42 43 44 45 46 47 48 49 50 |
|
from_json(json_path)
classmethod
Create a new instance of the class from a JSON file.
Source code in src/aeiva/config/base_config.py
58 59 60 61 62 63 64 65 |
|
from_json_or_yaml(file_path)
classmethod
Create a new instance of the class from a JSON or YAML file.
Source code in src/aeiva/config/base_config.py
90 91 92 93 94 95 96 97 98 99 100 101 |
|
from_yaml(yaml_path)
classmethod
Create a new instance of the class from a YAML file.
Source code in src/aeiva/config/base_config.py
74 75 76 77 78 79 80 81 |
|
to_dict()
Convert the instance to a dictionary.
Source code in src/aeiva/config/base_config.py
52 53 54 55 56 |
|
to_json(filepath)
Convert the instance to a JSON file.
Source code in src/aeiva/config/base_config.py
67 68 69 70 71 72 |
|
to_yaml(filepath)
Convert the instance to a YAML file.
Source code in src/aeiva/config/base_config.py
83 84 85 86 87 88 |
|
custom_configs
macaw_config
This module contains the config for macaw model.
We can define separate config classes for different specific models/datasets/tasks.
Copyright (C) 2023 Bang Liu - All Rights Reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree.
MacawConfig
dataclass
Bases: BaseConfig
Define user-customized config here.
Source code in src/aeiva/config/custom_configs/macaw_config.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
general_configs
This module contains some general config classes that can be used in deep learning projects.
E.g., data config, model config, trainer config, etc.
Copyright (C) 2023 Bang Liu - All Rights Reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree.
DataConfig
dataclass
Bases: BaseConfig
This class contains the data configuration.
Source code in src/aeiva/config/general_configs.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
ExplicitEnum
Bases: str
, Enum
Enum with more explicit error message for missing values.
Source code in src/aeiva/config/general_configs.py
26 27 28 29 30 31 32 33 34 |
|
ModelConfig
dataclass
Bases: BaseConfig
Model configuration class.
Source code in src/aeiva/config/general_configs.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
|
OptimizerNames
Bases: ExplicitEnum
Stores the acceptable string identifiers for optimizers.
Source code in src/aeiva/config/general_configs.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
omni_config
This module contains the OmniConfig classes.
We can define separate config classes for different modules, e.g., data, model, trainer, etc. The OmniConfig class is the combination of all config classes. It can also accept command line arguments to update the config values.
Copyright (C) 2023 Bang Liu - All Rights Reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree.
OmniConfig
dataclass
Bases: BaseConfig
Source code in src/aeiva/config/omni_config.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
create_omni_config()
staticmethod
Initializes OmniConfig by aggregating all configuration classes.
Source code in src/aeiva/config/omni_config.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
get_argparse_parser()
Creates an argument parser that can handle complex types.
Source code in src/aeiva/config/omni_config.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
update_from_args(namespace_args)
Updates the configuration based on parsed command-line arguments.
Source code in src/aeiva/config/omni_config.py
50 51 52 53 54 55 56 |
|
data
processor
This module contains the data processor.
@Author: Bang Liu (chatsci.ai@gmail.com) @Date: 2023-07-11
Copyright (C) 2023 Bang Liu - All Rights Reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree.
process_dataset(formatted_dataset, pipeline, output_dir, dataset_name='')
Process a dataset with a pipeline of functions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
formatted_dataset
|
DataSet
|
the dataset to be processed. |
required |
pipeline
|
list[Callable]
|
a list of functions to be applied to the dataset. |
required |
output_dir
|
Optional[str]
|
the output directory to save the processed dataset. |
required |
dataset_name
|
Optional[str]
|
the name of the dataset. Defaults to "". |
''
|
Returns:
Name | Type | Description |
---|---|---|
DataSet |
DataSet
|
the processed dataset. |
Source code in src/aeiva/data/processor.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|
demo
chat_gradio
bot(user_input, history)
async
Handles chatbot logic by emitting perception.gradio events to the Agent and retrieving responses.
Source code in src/aeiva/demo/chat_gradio.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
|
clear_media()
Clears the uploaded media paths.
Source code in src/aeiva/demo/chat_gradio.py
136 137 138 139 140 141 142 |
|
handle_upload(file)
Handles file uploads and delegates to specific handlers based on file type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file
|
Uploaded file object. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Message indicating the upload status. |
Source code in src/aeiva/demo/chat_gradio.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
|
mm_chatbot
This module defines a multimodal chatbot demo with gradio.
@Author: Bang Liu (chatsci.ai@gmail.com) @Date: 2023-07-13
Copyright (C) 2023 Bang Liu - All Rights Reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree.
environment
environment
Environment
Bases: ABC
Abstract base class for an environment in which an intelligent agent operates.
Each environment provides context, defines interactions, and manages its own state. Subclasses should implement specific methods for different types of environments.
Attributes:
Name | Type | Description |
---|---|---|
config |
EnvironmentConfig
|
Configuration settings for the environment. |
state |
Any
|
Current state of the environment, initialized from the config. |
entities |
List[Any]
|
Entities present within the environment. |
constraints |
Dict[str, Any]
|
Rules or limitations for interactions in the environment. |
time |
Optional[int]
|
Time progression within the environment, if enabled. |
Source code in src/aeiva/environment/environment.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
__init__(config)
Initialize the environment with a given configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
EnvironmentConfig
|
Configuration settings for the environment. |
required |
Source code in src/aeiva/environment/environment.py
20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
act(action, target=None)
abstractmethod
Execute an action in the environment, potentially modifying its state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
action
|
Any
|
The action to be executed. |
required |
target
|
Optional[Any]
|
Target entity for the action, if applicable. |
None
|
Source code in src/aeiva/environment/environment.py
73 74 75 76 77 78 79 80 81 82 |
|
close()
Clean up any resources tied to the environment when it's no longer needed.
Source code in src/aeiva/environment/environment.py
99 100 101 102 103 |
|
get_context()
Retrieve relevant context information from the environment, useful for agent processing.
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
Contextual data or state relevant to the agent's tasks. |
Source code in src/aeiva/environment/environment.py
90 91 92 93 94 95 96 97 |
|
observe(agent)
abstractmethod
Provide observations to an agent based on the current state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent
|
Any
|
The agent requesting observation. |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
Observation data formatted according to the agent's perception capabilities. |
Source code in src/aeiva/environment/environment.py
60 61 62 63 64 65 66 67 68 69 70 71 |
|
render()
Visualize or output the environment's current state. Optional for subclasses.
Source code in src/aeiva/environment/environment.py
84 85 86 87 88 |
|
reset()
abstractmethod
Reset the environment to its initial state as defined by the configuration.
Source code in src/aeiva/environment/environment.py
42 43 44 45 46 47 48 |
|
setup()
abstractmethod
Set up the environment based on its configuration. Subclasses should define any initialization logic here.
Source code in src/aeiva/environment/environment.py
34 35 36 37 38 39 40 |
|
step(actions)
abstractmethod
Advance the environment by one step based on actions taken by agents.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
actions
|
Dict[Any, Any]
|
A dictionary of actions performed by agents. |
required |
Source code in src/aeiva/environment/environment.py
50 51 52 53 54 55 56 57 58 |
|
environment_config
EnvironmentConfig
dataclass
Bases: BaseConfig
Configuration class for initializing an environment.
Attributes:
Name | Type | Description |
---|---|---|
environment_type |
str
|
Type of the environment, see EnvironmentType class. |
initial_state |
Optional[Any]
|
Optional initial state of the environment. |
constraints |
Dict[str, Any]
|
Rules or constraints governing the environment. |
entities |
List[Any]
|
Entities present within the environment. |
time_enabled |
bool
|
Whether the environment tracks time progression. |
Source code in src/aeiva/environment/environment_config.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
environment_type
EnvironmentType
A class to hold constants for various environment types, organized by broad categories to maximize generality while supporting diverse use cases.
Categories
- Interaction-Based: Environments with user or agent interaction.
- Digital: Environments involving digital interfaces, applications, or software systems.
- Data-Based: Static or dynamic data collections or document repositories.
- Virtual/Simulated: Simulated, spatial, or immersive virtual environments.
- World-Level: Comprehensive real or virtual world environments.
Source code in src/aeiva/environment/environment_type.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
event
event
Event
dataclass
Represents an event in the event bus system.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the event. |
payload |
Any
|
The data associated with the event. |
timestamp |
datetime
|
The time the event was created. |
priority |
int
|
The priority of the event. |
Source code in src/aeiva/event/event.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
event_bus
EventBus
An asynchronous event bus for publishing and subscribing to events.
Features: - Subscribers can use wildcard patterns to subscribe to multiple events. - Subscribers can cancel event propagation. - Subscribers can be set to auto-unsubscribe after one call. - Event-level prioritization in the queue. - Customizable error handling. - Logging for key actions. - emit, emit_after, and emit_only methods for flexible event emission.
Source code in src/aeiva/event/event_bus.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
|
__init__()
Initializes the event bus.
Source code in src/aeiva/event/event_bus.py
32 33 34 35 36 37 38 39 40 |
|
emit(event_name, payload=None, priority=0)
async
Emits an event to all matching subscribers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event_name
|
str
|
The name of the event to emit. |
required |
payload
|
Any
|
The payload of the event. |
None
|
priority
|
int
|
The priority of the event. |
0
|
Source code in src/aeiva/event/event_bus.py
229 230 231 232 233 234 235 236 237 238 |
|
emit_after(event_name, priority=0)
Decorator that emits an event after the decorated function is called.
Usage
@event_bus.emit_after('event_name') def some_function(): ...
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event_name
|
str
|
The name of the event to emit after function execution. |
required |
priority
|
int
|
The priority of the event. |
0
|
Returns:
Name | Type | Description |
---|---|---|
Callable |
The decorator function. |
Source code in src/aeiva/event/event_bus.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
|
emit_only(event_name, subscriber_names, payload=None, priority=0)
async
Emits an event only to specified subscribers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event_name
|
str
|
The name of the event to emit. |
required |
subscriber_names
|
str or List[str]
|
The name(s) of subscribers to notify. |
required |
payload
|
Any
|
The payload of the event. |
None
|
priority
|
int
|
The priority of the event. |
0
|
Source code in src/aeiva/event/event_bus.py
240 241 242 243 244 245 246 247 248 249 250 |
|
on(event_pattern, priority=0, once=False)
Decorator for subscribing a function to events matching a pattern.
Usage
@event_bus.on('event.*', priority=10) async def handler(event): ...
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event_pattern
|
str
|
The event name or pattern to subscribe to. |
required |
priority
|
int
|
Priority of the callback. |
0
|
once
|
bool
|
If True, unsubscribe after one call. |
False
|
Returns:
Name | Type | Description |
---|---|---|
Callable |
The decorator function. |
Source code in src/aeiva/event/event_bus.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
|
publish(event, only=None)
async
Publishes an event to the event bus.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event
|
Event
|
The event to publish. |
required |
only
|
str or List[str]
|
Names of specific subscribers to notify. |
None
|
Source code in src/aeiva/event/event_bus.py
81 82 83 84 85 86 87 88 89 90 91 92 |
|
start()
Starts the event bus processing loop.
Source code in src/aeiva/event/event_bus.py
157 158 159 160 161 162 163 164 |
|
stop()
Stops the event bus processing loop.
Source code in src/aeiva/event/event_bus.py
166 167 168 169 170 171 172 |
|
subscribe(event_pattern, callback, *, priority=0, once=False)
Subscribes a callback function to events matching a pattern.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event_pattern
|
str
|
The event name or pattern to subscribe to. |
required |
callback
|
Callable[[Event], Any]
|
The callback function. |
required |
priority
|
int
|
Priority of the callback. |
0
|
once
|
bool
|
If True, unsubscribe after one call. |
False
|
Source code in src/aeiva/event/event_bus.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
unsubscribe(callback)
Unsubscribes a callback function from all events.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
callback
|
Callable[[Event], Any]
|
The callback function to remove. |
required |
Source code in src/aeiva/event/event_bus.py
68 69 70 71 72 73 74 75 76 77 78 79 |
|
wait_until_all_events_processed()
async
Waits until all events in the queue have been processed.
Source code in src/aeiva/event/event_bus.py
252 253 254 255 256 |
|
EventCancelled
Bases: Exception
Exception to indicate that an event has been cancelled.
Source code in src/aeiva/event/event_bus.py
14 15 16 |
|
hypergraph
exceptions
HypergraphError
Bases: Exception
Custom exception class for Hypergraph-related errors.
Source code in src/aeiva/hypergraph/exceptions.py
3 4 5 6 7 8 |
|
hyperedge
HyperEdge
Represents a hyperedge in the hypergraph, encapsulating its properties and connected nodes.
Source code in src/aeiva/hypergraph/hyperedge.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
|
__init__(id, nodes=None, properties=None)
Initializes a HyperEdge.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id
|
Any
|
Unique identifier for the hyperedge. |
required |
nodes
|
Optional[Iterable[Any]]
|
(Optional) Iterable of node identifiers connected by the hyperedge. |
None
|
properties
|
Optional[Dict[str, Any]]
|
(Optional) Dictionary of properties. |
None
|
Source code in src/aeiva/hypergraph/hyperedge.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
add_node(node_id)
Adds a node to the hyperedge.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
Any
|
Identifier of the node to add. |
required |
Source code in src/aeiva/hypergraph/hyperedge.py
30 31 32 33 34 35 36 37 |
|
add_property(key, value)
Adds or updates a property of the hyperedge.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
Property name. |
required |
value
|
Any
|
Property value. |
required |
Source code in src/aeiva/hypergraph/hyperedge.py
51 52 53 54 55 56 57 58 59 |
|
get_property(key)
Retrieves a property of the hyperedge.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
Property name. |
required |
Returns:
Type | Description |
---|---|
Any
|
The value of the property. |
Raises:
Type | Description |
---|---|
HypergraphError
|
If the property does not exist. |
Source code in src/aeiva/hypergraph/hyperedge.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|
remove_node(node_id)
Removes a node from the hyperedge.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
Any
|
Identifier of the node to remove. |
required |
Source code in src/aeiva/hypergraph/hyperedge.py
39 40 41 42 43 44 45 46 47 48 49 |
|
remove_property(key)
Removes a property from the hyperedge.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
Property name. |
required |
Raises:
Type | Description |
---|---|
HypergraphError
|
If the property does not exist. |
Source code in src/aeiva/hypergraph/hyperedge.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
hypergraph
Hypergraph
A simplified Hypergraph class using dictionaries and NetworkX for management.
Parameters
hyperedges : Dict[Any, Dict[str, Any]] A dictionary where keys are hyperedge identifiers and values are dictionaries containing: - 'nodes': Iterable of node identifiers connected by the hyperedge. - 'properties': (Optional) Dictionary of properties for the hyperedge.
Optional[Dict[Any, Dict[str, Any]]] = None
A dictionary where keys are node identifiers and values are dictionaries of node properties.
Optional[Dict[Any, Dict[str, Any]]] = None
A dictionary where keys are hyperedge identifiers and values are dictionaries of hyperedge properties.
Optional[str] = None
Name assigned to the hypergraph.
Source code in src/aeiva/hypergraph/hypergraph.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 |
|
__contains__(item)
Checks if a node is in the hypergraph.
Parameters
item : Any The node identifier to check.
Returns
bool True if the node exists in the hypergraph, False otherwise.
Source code in src/aeiva/hypergraph/hypergraph.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
|
__eq__(other)
Checks if two hypergraphs are equal based on their hyperedges and nodes.
Parameters
other : Any The other object to compare.
Returns
bool True if both hypergraphs have identical nodes and hyperedges with the same properties, False otherwise.
Source code in src/aeiva/hypergraph/hypergraph.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
|
__getitem__(node)
Retrieves the neighbors of a node in the hypergraph.
Neighbors are nodes that share at least one hyperedge with the given node.
Parameters
node : Any The node identifier.
Returns
Iterable[Any] An iterator over neighboring node identifiers.
Raises
HypergraphError If the node does not exist in the hypergraph.
Source code in src/aeiva/hypergraph/hypergraph.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
|
__iter__()
Allows iteration over the nodes of the hypergraph.
Yields
Any Node identifiers.
Source code in src/aeiva/hypergraph/hypergraph.py
188 189 190 191 192 193 194 195 196 197 |
|
__len__()
Returns the number of nodes in the hypergraph.
Returns
int Number of nodes.
Source code in src/aeiva/hypergraph/hypergraph.py
177 178 179 180 181 182 183 184 185 186 |
|
__repr__()
Official string representation of the hypergraph.
Returns
str A detailed string describing the hypergraph with its name, number of nodes, and hyperedges.
Source code in src/aeiva/hypergraph/hypergraph.py
163 164 165 166 167 168 169 170 171 172 173 174 175 |
|
__str__()
String representation of the hypergraph.
Returns
str A string describing the hypergraph with its name, number of nodes, and hyperedges.
Source code in src/aeiva/hypergraph/hypergraph.py
152 153 154 155 156 157 158 159 160 161 |
|
add_hyperedge(he_id, nodes, properties=None)
Adds a hyperedge to the hypergraph.
Parameters
he_id : Any Unique identifier for the hyperedge. nodes : Iterable[Any] Nodes connected by the hyperedge. properties : Optional[Dict[str, Any]] = None Properties of the hyperedge.
Raises
HypergraphError If the hyperedge ID already exists.
Source code in src/aeiva/hypergraph/hypergraph.py
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
|
add_hyperedges_from(hyperedges, inplace=True)
Adds multiple hyperedges with attributes to the hypergraph.
Parameters
hyperedges : Iterable[Union[Any, Tuple[Any, Dict[str, Any]]]] An iterable of hyperedge identifiers or tuples of (he_id, attributes). inplace : bool, default=True If True, modifies the existing Hypergraph. Otherwise, creates a new Hypergraph with the added hyperedges.
Returns
Hypergraph The updated or new Hypergraph instance.
Raises
HypergraphError If any hyperedge ID already exists. ValueError If any tuple does not contain exactly two elements or if attributes are not dictionaries.
Source code in src/aeiva/hypergraph/hypergraph.py
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 |
|
add_incidence(he_id, node_id, attributes=None, inplace=True)
Adds a single incidence with attributes to the hypergraph.
Parameters
he_id : Any Identifier of the hyperedge. node_id : Any Identifier of the node. attributes : Optional[Dict[str, Any]] = None Properties to add to the incidence as key-value pairs. inplace : bool, default=True If True, modifies the existing Hypergraph. Otherwise, creates a new Hypergraph with the added incidence.
Returns
Hypergraph The updated or new Hypergraph instance.
Raises
HypergraphError If the hyperedge or node does not exist, or if the incidence already exists.
Source code in src/aeiva/hypergraph/hypergraph.py
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 |
|
add_incidences_from(incidences, inplace=True)
Adds a collection of incidences to the hypergraph.
Parameters
incidences : Iterable[Union[Tuple[Any, Any], Tuple[Any, Any, Dict[str, Any]]]] Incidence tuples as: - (he_id, node_id) - (he_id, node_id, attributes)
bool, default=True
If True, modifies the existing Hypergraph. Otherwise, creates a new Hypergraph with the added incidences.
Returns
Hypergraph The updated or new Hypergraph instance.
Raises
HypergraphError If any hyperedge or node does not exist, or if any incidence already exists. ValueError If the structure of any incidence tuple is invalid.
Source code in src/aeiva/hypergraph/hypergraph.py
1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 |
|
add_node(node_id, properties=None, inplace=True)
Adds a node to the hypergraph.
Parameters
node_id : Any Identifier for the node. properties : Optional[Dict[str, Any]] = None Properties of the node. inplace : bool, default=True If True, modifies the existing Hypergraph. Otherwise, creates a new Hypergraph with the added node.
Returns
Hypergraph The updated or new Hypergraph instance.
Raises
HypergraphError If the node ID already exists.
Source code in src/aeiva/hypergraph/hypergraph.py
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 |
|
add_nodes_from(nodes, inplace=True)
Adds multiple nodes with attributes to the hypergraph.
Parameters
nodes : Iterable[Union[Any, Tuple[Any, Dict[str, Any]]]] An iterable of node identifiers or tuples of (node_id, attributes). inplace : bool, default=True If True, modifies the existing Hypergraph. Otherwise, creates a new Hypergraph with the added nodes.
Returns
Hypergraph The updated or new Hypergraph instance.
Raises
HypergraphError If any node ID already exists. ValueError If any tuple does not contain exactly two elements or if attributes are not dictionaries.
Source code in src/aeiva/hypergraph/hypergraph.py
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 |
|
adjacency_matrix(s=1, index=False)
Generates the adjacency matrix for nodes based on s-node connectivity.
Source code in src/aeiva/hypergraph/hypergraph.py
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 |
|
collapse_duplicate_hyperedges(name=None, use_uids=None, use_counts=False, return_counts=True, return_equivalence_classes=False, aggregate_properties_by=None)
Collapses duplicate hyperedges (hyperedges with identical node memberships) into single hyperedges.
Parameters
name : Optional[str], default=None The name assigned to the collapsed hypergraph. If None, defaults to the original name suffixed with '_collapsed_hyperedges'.
Optional[List[Any]] = None
Specifies the hyperedge identifiers to use as representatives for each equivalence class.
If two identifiers occur in the same equivalence class, the first one found in use_uids
is used.
If None, the first encountered hyperedge in each class is used as the representative.
bool, optional, default=False
If True, renames the equivalence class representatives by appending the size of the class (e.g., 'HE1:3').
bool, optional, default=True
If True, adds the size of each equivalence class to the properties of the representative hyperedge under the key 'equivalence_class_size'.
bool, optional, default=False
If True, returns a tuple containing the new collapsed hypergraph and a dictionary mapping representatives to their equivalence classes.
Optional[Dict[str, str]] = None
A dictionary specifying aggregation methods for hyperedge properties. Keys are property names, and values are aggregation functions (e.g., {'weight': 'sum'}). Properties not specified will use the 'first' aggregation.
Returns
Hypergraph or Tuple[Hypergraph, Dict[Any, Set[Any]]]
- If return_equivalence_classes=False
, returns the new collapsed hypergraph.
- If return_equivalence_classes=True
, returns a tuple containing the collapsed hypergraph and a dictionary of equivalence classes.
Raises
HypergraphError If the hypergraph is empty or improperly structured.
Source code in src/aeiva/hypergraph/hypergraph.py
1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 |
|
collapse_duplicate_nodes(name=None, use_uids=None, use_counts=False, return_counts=True, return_equivalence_classes=False, aggregate_properties_by=None)
Collapses duplicate nodes (nodes with identical hyperedge memberships) into single nodes.
Parameters
name : Optional[str], default=None The name assigned to the collapsed hypergraph. If None, defaults to the original name suffixed with '_collapsed_nodes'.
Optional[List[Any]] = None
Specifies the node identifiers to use as representatives for each equivalence class.
If two identifiers occur in the same equivalence class, the first one found in use_uids
is used.
If None, the first encountered node in each class is used as the representative.
bool, optional, default=False
If True, renames the equivalence class representatives by appending the size of the class (e.g., 'N1:3').
bool, optional, default=True
If True, adds the size of each equivalence class to the properties of the representative node under the key 'equivalence_class_size'.
bool, optional, default=False
If True, returns a tuple containing the new collapsed hypergraph and a dictionary mapping representatives to their equivalence classes.
Optional[Dict[str, str]] = None
A dictionary specifying aggregation methods for node properties. Keys are property names, and values are aggregation functions (e.g., {'weight': 'sum'}). Properties not specified will use the 'first' aggregation.
Returns
Hypergraph or Tuple[Hypergraph, Dict[Any, Set[Any]]]
- If return_equivalence_classes=False
, returns the new collapsed hypergraph.
- If return_equivalence_classes=True
, returns a tuple containing the collapsed hypergraph and a dictionary of equivalence classes.
Raises
HypergraphError If the hypergraph is empty or improperly structured.
Source code in src/aeiva/hypergraph/hypergraph.py
1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 |
|
compute_hyperedge_diameter(s=1)
Returns the diameter of the hypergraph based on s-hyperedge connectivity.
Parameters
s : int, optional, default=1 The number of shared nodes required for hyperedges to be considered adjacent.
Returns
int The diameter of the hypergraph based on hyperedge connectivity.
Raises
HypergraphError If the hypergraph is not s-hyperedge-connected or has no hyperedges.
Source code in src/aeiva/hypergraph/hypergraph.py
2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 |
|
compute_hyperedge_diameters(s=1)
Returns the hyperedge diameters of the s-hyperedge-connected component subgraphs in the hypergraph.
Parameters
s : int, optional, default=1 The number of shared nodes required for hyperedges to be considered adjacent.
Returns
Tuple[int, List[int], List[Set[Any]]] - Maximum diameter among all s-hyperedge-connected components. - List of diameters for each s-hyperedge connected component. - List of sets, each containing hyperedge IDs in an s-hyperedge connected component.
Raises
HypergraphError If the hypergraph is not s-hyperedge-connected or has no hyperedges.
Source code in src/aeiva/hypergraph/hypergraph.py
2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 |
|
compute_node_diameter(s=1)
Returns the diameter of the hypergraph based on s-node connectivity.
Parameters
s : int, optional, default=1 The number of shared hyperedges required for nodes to be considered adjacent.
Returns
int The diameter of the hypergraph.
Raises
HypergraphError If the hypergraph is not s-node-connected or has no nodes.
Source code in src/aeiva/hypergraph/hypergraph.py
2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 |
|
compute_node_diameters(s=1)
Returns the node diameters of the connected components in the hypergraph.
Parameters
s : int, optional, default=1 The number of shared hyperedges required for nodes to be considered adjacent.
Returns
Tuple[int, List[int], List[Set[Any]]] - Maximum diameter among all connected components. - List of diameters for each s-node connected component. - List of sets, each containing node IDs in an s-node connected component.
Raises
HypergraphError If the hypergraph is not s-connected or has no nodes.
Source code in src/aeiva/hypergraph/hypergraph.py
2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 |
|
copy(name=None)
Creates a deep copy of the hypergraph instance.
Parameters
name : Optional[str], default=None The name for the copied Hypergraph. If not provided, retains the original name.
Returns
Hypergraph A new Hypergraph instance that is a deep copy of the original.
Source code in src/aeiva/hypergraph/hypergraph.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
|
deepcopy(name=None)
Creates a deep copy of the hypergraph.
Parameters
name : Optional[str], default=None The name assigned to the cloned hypergraph. If None, defaults to the original hypergraph's name suffixed with '_clone'.
Returns
Hypergraph A deep copy of the hypergraph.
Source code in src/aeiva/hypergraph/hypergraph.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
|
difference(other, inplace=False, name=None)
Returns the difference of the current hypergraph with another hypergraph. The difference includes nodes and hyperedges present in the current hypergraph but not in the other.
Parameters
other : Hypergraph
The hypergraph to subtract.
inplace : bool, optional, default=False
If True, modifies the current hypergraph by removing elements found in other
.
Otherwise, returns a new Hypergraph instance.
name : Optional[str], default=None
The name for the resulting hypergraph. If None, defaults to 'Difference_of_{self.name}_{other.name}'.
Returns
Hypergraph The resulting difference hypergraph.
Raises
TypeError
If other
is not an instance of Hypergraph.
Source code in src/aeiva/hypergraph/hypergraph.py
2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 |
|
dual(name=None)
Constructs the dual of the current hypergraph by reversing the roles of nodes and hyperedges.
Parameters
name : Optional[str], default=None Name for the dual hypergraph. If None, defaults to the original hypergraph's name with '_dual' appended.
Returns
Hypergraph A new Hypergraph instance representing the dual of the current hypergraph.
Source code in src/aeiva/hypergraph/hypergraph.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
edge_elements()
Returns a dictionary where each key is a hyperedge ID and the value is a list of node IDs within that hyperedge.
Returns
Dict[Any, List[Any]] Dictionary mapping hyperedge IDs to lists of node IDs they contain.
Source code in src/aeiva/hypergraph/hypergraph.py
141 142 143 144 145 146 147 148 149 150 |
|
edges()
Returns a list of all hyperedge identifiers in the hypergraph.
Returns
List[Any] List of hyperedge IDs.
Source code in src/aeiva/hypergraph/hypergraph.py
130 131 132 133 134 135 136 137 138 139 |
|
from_bipartite_graph(bipartite_graph, hyperedge_prefix='HE', node_prefix='N', name=None)
classmethod
Constructs a Hypergraph instance from a bipartite graph.
Parameters
bipartite_graph : nx.Graph A bipartite graph where one set of nodes represents hyperedges and the other represents regular nodes. hyperedge_prefix : str, optional, default="HE" The prefix to identify hyperedge nodes in the bipartite graph. node_prefix : str, optional, default="N" The prefix to identify regular nodes in the bipartite graph. name : Optional[str], default=None The name assigned to the new Hypergraph. If None, defaults to 'FromBipartiteGraph'.
Returns
Hypergraph The constructed Hypergraph instance.
Raises
ValueError If the bipartite graph does not contain two distinct sets of nodes identifiable by the provided prefixes.
Source code in src/aeiva/hypergraph/hypergraph.py
2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 |
|
get_hyperedge_connected_components(s=1, return_singletons=False)
Yields the s-hyperedge-connected components of the hypergraph.
Parameters
s : int, optional, default=1 The connectivity level to check. return_singletons : bool, optional, default=False If True, includes singleton components. Otherwise, excludes them.
Yields
Set[Any] Sets of hyperedge IDs representing each connected component.
Source code in src/aeiva/hypergraph/hypergraph.py
1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 |
|
get_hyperedge_connected_subgraphs(s=1, return_singletons=False, name=None)
Yields subgraphs corresponding to each s-hyperedge-connected component.
Parameters
s : int, optional, default=1 The connectivity level to check. return_singletons : bool, optional, default=False If True, includes singleton components. Otherwise, excludes them. name : Optional[str], default=None Base name for the subgraphs. Each subgraph will have a unique name appended.
Yields
Hypergraph Subgraphs representing each connected component.
Source code in src/aeiva/hypergraph/hypergraph.py
1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 |
|
get_hyperedge_distance(source, target, s=1)
Returns the shortest s-walk distance between two hyperedges in the hypergraph.
Parameters
source : Any A hyperedge identifier in the hypergraph. target : Any A hyperedge identifier in the hypergraph. s : int, optional, default=1 The number of shared nodes required for hyperedges to be considered adjacent.
Returns
Union[int, float]
The shortest s-walk distance between the source and target hyperedges.
Returns float('inf')
if no path exists.
Raises
HypergraphError If either the source or target hyperedge does not exist in the hypergraph.
Source code in src/aeiva/hypergraph/hypergraph.py
2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 |
|
get_hyperedges_of_node(node_id)
Retrieves all hyperedges that a given node is part of.
Parameters
node_id : Any The node identifier.
Returns
Set[Any] A set of hyperedge IDs that the node belongs to.
Raises
HypergraphError If the node does not exist in the hypergraph.
Source code in src/aeiva/hypergraph/hypergraph.py
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 |
|
get_node_connected_components(s=1, return_singletons=False)
Yields the s-node-connected components of the hypergraph.
Parameters
s : int, optional, default=1 The connectivity level to check. return_singletons : bool, optional, default=False If True, includes singleton components. Otherwise, excludes them.
Yields
Set[Any] Sets of node IDs representing each connected component.
Source code in src/aeiva/hypergraph/hypergraph.py
1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 |
|
get_node_connected_subgraphs(s=1, return_singletons=False, name=None)
Yields subgraphs corresponding to each s-node-connected component.
Parameters
s : int, optional, default=1 The connectivity level to check. return_singletons : bool, optional, default=False If True, includes singleton components. Otherwise, excludes them. name : Optional[str], default=None Base name for the subgraphs. Each subgraph will have a unique name appended.
Yields
Hypergraph Subgraphs representing each connected component.
Source code in src/aeiva/hypergraph/hypergraph.py
1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 |
|
get_node_distance(source, target, s=1)
Returns the shortest s-walk distance between two nodes in the hypergraph.
Parameters
source : Any A node identifier in the hypergraph. target : Any A node identifier in the hypergraph. s : int, optional, default=1 The number of shared hyperedges required for nodes to be considered adjacent.
Returns
Union[int, float]
The shortest s-walk distance between the source and target nodes.
Returns float('inf')
if no path exists.
Raises
HypergraphError If either the source or target node does not exist in the hypergraph.
Source code in src/aeiva/hypergraph/hypergraph.py
2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 |
|
get_singleton_hyperedges()
Returns a list of singleton hyperedges. A singleton hyperedge is a hyperedge of size 1 where its sole node has degree 1.
Returns
List[Any] A list of singleton hyperedge IDs.
Source code in src/aeiva/hypergraph/hypergraph.py
1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 |
|
get_toplexes(return_hypergraph=False)
Computes a maximal collection of toplexes for the hypergraph.
A :term:toplex
is a hyperedge that is not contained in any other hyperedge.
Parameters
return_hypergraph : bool, optional, default=False If True, returns a new Hypergraph consisting only of the toplexes.
Returns
List[Any] or Hypergraph
- A list of toplex hyperedge IDs.
- If return_hypergraph=True
, returns a Hypergraph containing only the toplexes.
Source code in src/aeiva/hypergraph/hypergraph.py
1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 |
|
hyperedge_adjacency_matrix(s=1, index=False)
Generates the adjacency matrix for hyperedges based on s-hyperedge connectivity.
Parameters
s : int, optional, default=1 The number of shared nodes required for hyperedges to be considered adjacent. index : bool, optional, default=False If True, returns a mapping from matrix indices to hyperedge IDs.
Returns
Tuple[Optional[csr_matrix], Dict[int, Any]] - The adjacency matrix in CSR format. - A dictionary mapping matrix indices to hyperedge IDs.
Source code in src/aeiva/hypergraph/hypergraph.py
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 |
|
intersection(other, inplace=False, name=None)
Returns the intersection of the current hypergraph with another hypergraph. The intersection includes only nodes and hyperedges present in both hypergraphs.
Parameters
other : Hypergraph The hypergraph to intersect with. inplace : bool, optional, default=False If True, modifies the current hypergraph to keep only the intersecting elements. Otherwise, returns a new Hypergraph instance. name : Optional[str], default=None The name for the resulting hypergraph. If None, defaults to 'Intersection_of_{self.name}_{other.name}'.
Returns
Hypergraph The resulting intersection hypergraph.
Raises
TypeError
If other
is not an instance of Hypergraph.
Source code in src/aeiva/hypergraph/hypergraph.py
2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 |
|
is_hyperedge_connected(s=1)
Determines if the hypergraph is s-hyperedge-connected.
Parameters
s : int, optional, default=1 The connectivity level to check.
Returns
bool True if the hypergraph is s-hyperedge-connected, False otherwise.
Source code in src/aeiva/hypergraph/hypergraph.py
1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 |
|
is_node_connected(s=1)
Determines if the hypergraph is s-node-connected.
Parameters
s : int, optional, default=1 The connectivity level to check.
Returns
bool True if the hypergraph is s-node-connected, False otherwise.
Source code in src/aeiva/hypergraph/hypergraph.py
1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 |
|
node_memberships()
Returns a dictionary where each key is a node ID and the value is a list of hyperedge IDs that include the node.
Returns
Dict[Any, List[Any]] Dictionary mapping node IDs to the hyperedge IDs they belong to.
Source code in src/aeiva/hypergraph/hypergraph.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
nodes()
Returns a list of all unique node identifiers in the hypergraph.
Returns
List[Any] List of node IDs.
Source code in src/aeiva/hypergraph/hypergraph.py
104 105 106 107 108 109 110 111 112 113 |
|
remove_hyperedge(he_id)
Removes a hyperedge from the hypergraph.
Parameters
he_id : Any Identifier of the hyperedge to remove.
Raises
HypergraphError If the hyperedge does not exist.
Source code in src/aeiva/hypergraph/hypergraph.py
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 |
|
remove_hyperedges(he_ids, inplace=True)
Removes the specified hyperedges from the hypergraph.
Parameters
he_ids : Any | Iterable[Any] Hyperedge identifier(s) to remove. inplace : bool, default=True If True, modifies the existing Hypergraph. Otherwise, creates a new Hypergraph with the hyperedges removed.
Returns
Hypergraph The updated or new Hypergraph instance.
Raises
HypergraphError If any hyperedge ID does not exist.
Source code in src/aeiva/hypergraph/hypergraph.py
707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 |
|
remove_incidence(he_id, node_id, inplace=True)
Removes a single incidence from the hypergraph.
Parameters
he_id : Any Identifier of the hyperedge. node_id : Any Identifier of the node. inplace : bool, default=True If True, modifies the existing Hypergraph. Otherwise, creates a new Hypergraph with the incidence removed.
Returns
Hypergraph The updated or new Hypergraph instance.
Raises
HypergraphError If the hyperedge or node does not exist, or if the incidence does not exist.
Source code in src/aeiva/hypergraph/hypergraph.py
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 |
|
remove_incidences(incidences, inplace=True)
Removes the specified incidences from the hypergraph.
Parameters
incidences : Iterable[Tuple[Any, Any]] Incidence identifiers as tuples of (he_id, node_id). inplace : bool, default=True If True, modifies the existing Hypergraph. Otherwise, creates a new Hypergraph with the incidences removed.
Returns
Hypergraph The updated or new Hypergraph instance.
Raises
HypergraphError If any incidence does not exist.
Source code in src/aeiva/hypergraph/hypergraph.py
1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 |
|
remove_node(node_id, inplace=True)
Removes a node from the hypergraph.
Parameters
node_id : Any Identifier of the node to remove. inplace : bool, default=True If True, modifies the existing Hypergraph. Otherwise, creates a new Hypergraph with the node removed.
Returns
Hypergraph The updated or new Hypergraph instance.
Raises
HypergraphError If the node does not exist.
Source code in src/aeiva/hypergraph/hypergraph.py
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 |
|
remove_nodes_from(nodes, inplace=True)
Removes the specified nodes from the hypergraph.
Parameters
nodes : Any | Iterable[Any] Node identifier(s) to remove. inplace : bool, default=True If True, modifies the existing Hypergraph. Otherwise, creates a new Hypergraph with the nodes removed.
Returns
Hypergraph The updated or new Hypergraph instance.
Raises
HypergraphError If any node ID does not exist.
Source code in src/aeiva/hypergraph/hypergraph.py
777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 |
|
remove_singleton_hyperedges(name=None)
Constructs a clone of the hypergraph with singleton hyperedges removed.
Source code in src/aeiva/hypergraph/hypergraph.py
1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 |
|
restrict_to_specific_hyperedges(hyperedges_to_retain, name=None)
Creates a new hypergraph by retaining only the specified hyperedges and removing all others.
Parameters
hyperedges_to_retain : Iterable[Any] An iterable of hyperedge identifiers to retain in the new hypergraph.
Optional[str], default=None
The name assigned to the restricted hypergraph. If None, defaults to the original name suffixed with '_restricted_hyperedges'.
Returns
Hypergraph A new hypergraph containing only the specified hyperedges and their associated nodes.
Raises
HypergraphError If none of the specified hyperedges exist in the hypergraph.
Source code in src/aeiva/hypergraph/hypergraph.py
1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 |
|
restrict_to_specific_nodes(nodes_to_retain, name=None)
Creates a new hypergraph by retaining only the specified nodes and removing all others.
Parameters
nodes_to_retain : Iterable[Any] An iterable of node identifiers to retain in the new hypergraph.
Optional[str], default=None
The name assigned to the restricted hypergraph. If None, defaults to the original name suffixed with '_restricted_nodes'.
Returns
Hypergraph A new hypergraph containing only the specified nodes and their associated hyperedges.
Raises
HypergraphError If none of the specified nodes exist in the hypergraph.
Source code in src/aeiva/hypergraph/hypergraph.py
1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 |
|
s_component_subgraphs(s=1, hyperedges=True, return_singletons=False, name=None)
Yields subgraphs corresponding to each s-hyperedge-connected or s-node-connected component.
Parameters
s : int, optional, default=1 The connectivity level to check. hyperedges : bool, optional, default=True If True, yields subgraphs of s-hyperedge-connected components. Otherwise, yields subgraphs of s-node-connected components. return_singletons : bool, optional, default=False If True, includes singleton components. Otherwise, excludes them. name : Optional[str], default=None Base name for the subgraphs. Each subgraph will have a unique name appended.
Yields
Hypergraph Subgraphs representing each connected component.
Source code in src/aeiva/hypergraph/hypergraph.py
1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 |
|
s_connected_components(s=1, hyperedges=True, return_singletons=False)
Yields the s-hyperedge-connected or s-node-connected components of the hypergraph.
Parameters
s : int, optional, default=1 The connectivity level to check. hyperedges : bool, optional, default=True If True, yields s-hyperedge-connected components. Otherwise, yields s-node-connected components. return_singletons : bool, optional, default=False If True, includes singleton components. Otherwise, excludes them.
Yields
Set[Any] Sets of hyperedge IDs or node IDs representing each connected component.
Source code in src/aeiva/hypergraph/hypergraph.py
1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 |
|
symmetric_difference(other, inplace=False, name=None)
Returns the symmetric difference of the current hypergraph with another hypergraph. The symmetric difference includes elements present in either hypergraph but not in both.
Parameters
other : Hypergraph The hypergraph to symmetric difference with. inplace : bool, optional, default=False If True, modifies the current hypergraph to keep only the symmetric difference elements. Otherwise, returns a new Hypergraph instance. name : Optional[str], default=None The name for the resulting hypergraph. If None, defaults to 'SymmetricDifference_of_{self.name}_{other.name}'.
Returns
Hypergraph The resulting symmetric difference hypergraph.
Raises
TypeError
If other
is not an instance of Hypergraph.
Source code in src/aeiva/hypergraph/hypergraph.py
2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 |
|
to_bipartite_graph(keep_data=False, directed=False)
Creates a bipartite NetworkX graph from the hypergraph. The nodes and hyperedges of the hypergraph become nodes in the bipartite graph. For every hyperedge in the hypergraph and each node it connects to, there is an edge in the bipartite graph.
Parameters
keep_data : bool, optional, default = False If True, includes the node and hyperedge properties in the NetworkX graph. directed : bool, optional, default = False If True, the edges in the graph are directed with hyperedges as sources and nodes as targets.
Returns
networkx.Graph or networkx.DiGraph The bipartite graph representation of the hypergraph.
Source code in src/aeiva/hypergraph/hypergraph.py
2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 |
|
transpose(name=None)
Transposes the hypergraph by swapping the roles of nodes and hyperedges. The resulting hypergraph has hyperedges corresponding to the original nodes and vice versa.
Parameters
name : Optional[str], default=None The name assigned to the transposed hypergraph. If None, defaults to the original name suffixed with '_transposed'.
Returns
Hypergraph The transposed hypergraph.
Source code in src/aeiva/hypergraph/hypergraph.py
2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 |
|
union(other, inplace=False, name=None)
Returns the union of the current hypergraph with another hypergraph. The union combines all nodes and hyperedges from both hypergraphs.
Parameters
other : Hypergraph The hypergraph to union with. inplace : bool, optional, default=False If True, modifies the current hypergraph. Otherwise, returns a new Hypergraph instance. name : Optional[str], default=None The name for the resulting hypergraph. If None, defaults to 'Union_of_{self.name}_{other.name}'.
Returns
Hypergraph The resulting union hypergraph.
Raises
TypeError
If other
is not an instance of Hypergraph.
Source code in src/aeiva/hypergraph/hypergraph.py
2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 |
|
visualization
draw_hyper_edge_labels(H, pos, polys, labels={}, edge_labels_on_edge=True, ax=None, **kwargs)
Draws a label on the hyper edge boundary.
Should be passed Matplotlib PolyCollection representing the hyper-edges, see the return value of draw_hyper_edges.
The label will be draw on the least curvy part of the polygon, and will be aligned parallel to the orientation of the polygon where it is drawn.
Parameters
H: hnx.Hypergraph the entity to be drawn polys: PolyCollection collection of polygons returned by draw_hyper_edges labels: dict mapping of node id to string label ax: Axis matplotlib axis on which the plot is rendered kwargs: dict Keyword arguments are passed through to Matplotlib's annotate function.
Source code in src/aeiva/hypergraph/visualization.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
|
draw_hyper_edges(H, pos, ax=None, node_radius={}, contain_hyper_edges=False, dr=None, **kwargs)
Draws a convex hull around the nodes contained within each edge in H
Parameters
H: hnx.Hypergraph the entity to be drawn pos: dict mapping of node and edge positions to R^2 node_radius: dict mapping of node to R^1 (radius of each node) dr: float the spacing between concentric rings ax: Axis matplotlib axis on which the plot is rendered kwargs: dict keyword arguments, e.g., linewidth, facecolors, are passed through to the PolyCollection constructor
Returns
PolyCollection a Matplotlib PolyCollection that can be further styled
Source code in src/aeiva/hypergraph/visualization.py
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
|
draw_hyper_edges_two_column(H, pos, ax=None, **kwargs)
Renders hyper edges for the two column layout.
Each node-hyper edge membership is rendered as a line connecting the node in the left column to the edge in the right column.
Parameters
H: hnx.Hypergraph the entity to be drawn pos: dict mapping of node and edge positions to R^2 ax: Axis matplotlib axis on which the plot is rendered kwargs: dict keyword arguments passed to matplotlib.LineCollection
Returns
LineCollection the hyper edges
Source code in src/aeiva/hypergraph/visualization.py
725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 |
|
draw_hyper_labels(H, pos, node_radius={}, ax=None, labels={}, **kwargs)
Draws text labels for the hypergraph nodes.
The label is drawn to the right of the node. The node radius is needed (see draw_hyper_nodes) so the text can be offset appropriately as the node size changes.
The text label can be customized by passing in a dictionary, labels, mapping a node to its custom label. By default, the label is the string representation of the node.
Keyword arguments are passed through to Matplotlib's annotate function.
Parameters
H: hnx.Hypergraph the entity to be drawn pos: dict mapping of node and edge positions to R^2 node_radius: dict mapping of node to R^1 (radius of each node) ax: Axis matplotlib axis on which the plot is rendered labels: dict mapping of node to text label kwargs: dict keyword arguments passed to matplotlib.annotate
Source code in src/aeiva/hypergraph/visualization.py
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 |
|
draw_hyper_labels_two_column(H, pos, labels={}, with_node_labels=True, with_edge_labels=True, ax=None)
Renders hyper labels (nodes and edges) for the two column layout.
Parameters
H: hnx.Hypergraph the entity to be drawn pos: dict mapping of node and edge positions to R^2 labels: dict custom labels for nodes and edges can be supplied with_node_labels: bool False to disable node labels with_edge_labels: bool False to disable edge labels ax: Axis matplotlib axis on which the plot is rendered kwargs: dict keyword arguments passed to matplotlib.LineCollection
Source code in src/aeiva/hypergraph/visualization.py
764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 |
|
draw_hyper_nodes(H, pos, node_radius={}, r0=None, ax=None, **kwargs)
Draws a circle for each node in H.
The position of each node is specified by the a dictionary/list-like, pos, where pos[v] is the xy-coordinate for the vertex. The radius of each node can be specified as a dictionary where node_radius[v] is the radius. If a node is missing from this dictionary, or the node_radius is not specified at all, a sensible default radius is chosen based on distances between nodes given by pos.
Parameters
H: hnx.Hypergraph the entity to be drawn pos: dict mapping of node and edge positions to R^2 node_radius: dict mapping of node to R^1 (radius of each node) r0: float minimum distance that concentric rings start from the node position ax: Axis matplotlib axis on which the plot is rendered kwargs: dict keyword arguments, e.g., linewidth, facecolors, are passed through to the PolyCollection constructor
Returns
PolyCollection a Matplotlib PolyCollection that can be further styled
Source code in src/aeiva/hypergraph/visualization.py
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
|
draw_rubber_band(H, pos=None, with_color=True, with_node_counts=False, with_edge_counts=False, layout=nx.spring_layout, layout_kwargs={}, ax=None, node_radius=None, edges_kwargs={}, nodes_kwargs={}, edge_labels_on_edge=True, edge_labels={}, edge_labels_kwargs={}, node_labels={}, node_labels_kwargs={}, with_edge_labels=True, with_node_labels=True, node_label_alpha=0.35, edge_label_alpha=0.35, with_additional_edges=None, contain_hyper_edges=False, additional_edges_kwargs={}, return_pos=False)
Draw a hypergraph as a Matplotlib figure
By default this will draw a colorful "rubber band" like hypergraph, where convex hulls represent edges and are drawn around the nodes they contain.
This is a convenience function that wraps calls with sensible parameters to the following lower-level drawing functions:
- draw_hyper_edges,
- draw_hyper_edge_labels,
- draw_hyper_labels, and
- draw_hyper_nodes
The default layout algorithm is nx.spring_layout, but other layouts can be passed in. The Hypergraph is converted to a bipartite graph, and the layout algorithm is passed the bipartite graph.
If you have a pre-determined layout, you can pass in a "pos" dictionary. This is a dictionary mapping from node id's to x-y coordinates. For example:
>>> pos = {
>>> 'A': (0, 0),
>>> 'B': (1, 2),
>>> 'C': (5, -3)
>>> }
will position the nodes {A, B, C} manually at the locations specified. The coordinate system is in Matplotlib "data coordinates", and the figure will be centered within the figure.
By default, this will draw in a new figure, but the axis to render in can be
specified using :code:ax
.
This approach works well for small hypergraphs, and does not guarantee a rigorously "correct" drawing. Overlapping of sets in the drawing generally implies that the sets intersect, but sometimes sets overlap if there is no intersection. It is not possible, in general, to draw a "correct" hypergraph this way for an arbitrary hypergraph, in the same way that not all graphs have planar drawings.
Parameters
H: hnx.Hypergraph the entity to be drawn pos: dict mapping of node and edge positions to R^2 with_color: bool set to False to disable color cycling of edges with_node_counts: bool set to True to replace the label for collapsed nodes with the number of elements with_edge_counts: bool set to True to label collapsed edges with number of elements layout: function layout algorithm to compute layout_kwargs: dict keyword arguments passed to layout function ax: Axis matplotlib axis on which the plot is rendered edges_kwargs: dict keyword arguments passed to matplotlib.collections.PolyCollection for edges node_radius: None, int, float, or dict radius of all nodes, or dictionary of node:value; the default (None) calculates radius based on number of collapsed nodes; reasonable values range between 1 and 3 nodes_kwargs: dict keyword arguments passed to matplotlib.collections.PolyCollection for nodes edge_labels_on_edge: bool whether to draw edge labels on the edge (rubber band) or inside edge_labels_kwargs: dict keyword arguments passed to matplotlib.annotate for edge labels node_labels_kwargs: dict keyword argumetns passed to matplotlib.annotate for node labels with_edge_labels: bool set to False to make edge labels invisible with_node_labels: bool set to False to make node labels invisible node_label_alpha: float the transparency (alpha) of the box behind text drawn in the figure for node labels edge_label_alpha: float the transparency (alpha) of the box behind text drawn in the figure for edge labels with_additional_edges: networkx.Graph ... contain_hyper_edges: bool whether the rubber band shoudl be drawn around the location of the edge in the bipartite graph. This may be invisibile unless "with_additional_edges" contains this information.
Source code in src/aeiva/hypergraph/visualization.py
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 |
|
draw_two_column(H, with_node_labels=True, with_edge_labels=True, with_node_counts=False, with_edge_counts=False, with_color=True, edge_kwargs=None, ax=None)
Draw a hypergraph using a two-collumn layout.
This is intended reproduce an illustrative technique for bipartite graphs and hypergraphs that is typically used in papers and textbooks.
The left column is reserved for nodes and the right column is reserved for edges. A line is drawn between a node an an edge
The order of nodes and edges is optimized to reduce line crossings between the two columns. Spacing between disconnected components is adjusted to make the diagram easier to read, by reducing the angle of the lines.
Parameters
H: hnx.Hypergraph the entity to be drawn with_node_labels: bool False to disable node labels with_edge_labels: bool False to disable edge labels with_node_counts: bool set to True to label collapsed nodes with number of elements with_edge_counts: bool set to True to label collapsed edges with number of elements with_color: bool set to False to disable color cycling of hyper edges edge_kwargs: dict keyword arguments to pass to matplotlib.LineCollection ax: Axis matplotlib axis on which the plot is rendered
Source code in src/aeiva/hypergraph/visualization.py
803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 |
|
get_default_radius(H, pos)
Calculate a reasonable default node radius
This function iterates over the hyper edges and finds the most distant pair of points given the positions provided. Then, the node radius is a fraction of the median of this distance take across all hyper-edges.
Parameters
H: hnx.Hypergraph the entity to be drawn pos: dict mapping of node and edge positions to R^2
Returns
float the recommended radius
Source code in src/aeiva/hypergraph/visualization.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
|
get_frozenset_label(S, count=False, override={})
Helper function for rendering the labels of possibly collapsed nodes and edges
Parameters
S: iterable list of entities to be labeled count: bool True if labels should be counts of entities instead of list
Returns
dict mapping of entity to its string representation
Source code in src/aeiva/hypergraph/visualization.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
get_line_graph(H, collapse=True)
Computes the line graph, a directed graph, where a directed edge (u, v) exists if the edge u is a subset of the edge v in the hypergraph.
Parameters
H: hnx.Hypergraph the entity to be drawn collapse: bool True if edges should be added if hyper edges are identical
Returns
networkx.DiGraph A directed graph
Source code in src/aeiva/hypergraph/visualization.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
get_set_layering(H, collapse=True)
Computes a layering of the edges in the hyper graph.
In this layering, each edge is assigned a level. An edge u will be above (e.g., have a smaller level value) another edge v if v is a subset of u.
Parameters
H: hnx.Hypergraph the entity to be drawn collapse: bool True if edges should be added if hyper edges are identical
Returns
dict a mapping of vertices in H to integer levels
Source code in src/aeiva/hypergraph/visualization.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|
inflate_kwargs(items, kwargs)
Helper function to expand keyword arguments.
Parameters
n: int length of resulting list if argument is expanded kwargs: dict keyword arguments to be expanded
Returns
dict dictionary with same keys as kwargs and whose values are lists of length n
Source code in src/aeiva/hypergraph/visualization.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
layout_hyper_edges(H, pos, node_radius={}, dr=None, contain_hyper_edges=False)
Draws a convex hull for each edge in H.
Position of the nodes in the graph is specified by the position dictionary, pos. Convex hulls are spaced out such that if one set contains another, the convex hull will surround the contained set. The amount of spacing added between hulls is specified by the parameter, dr.
Parameters
H: hnx.Hypergraph the entity to be drawn pos: dict mapping of node and edge positions to R^2 node_radius: dict mapping of node to R^1 (radius of each node) dr: float the spacing between concentric rings ax: Axis matplotlib axis on which the plot is rendered
Returns
dict A mapping from hyper edge ids to paths (Nx2 numpy matrices)
Source code in src/aeiva/hypergraph/visualization.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
|
layout_node_link(H, G=None, layout=nx.spring_layout, **kwargs)
Helper function to use a NetwrokX-like graph layout algorithm on a Hypergraph
The hypergraph is converted to a bipartite graph, allowing the usual graph layout techniques to be applied.
Parameters
H: hnx.Hypergraph the entity to be drawn G: Graph an additional set of links to consider during the layout process layout: function the layout algorithm which accepts a NetworkX graph and keyword arguments kwargs: dict Keyword arguments are passed through to the layout algorithm
Returns
dict mapping of node and edge positions to R^2
Source code in src/aeiva/hypergraph/visualization.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
|
layout_two_column(H, spacing=2)
Two column (bipartite) layout algorithm.
This algorithm first converts the hypergraph into a bipartite graph and then computes connected components. Disonneccted components are handled independently and then stacked together.
Within a connected component, the spectral ordering of the bipartite graph provides a quick and dirty ordering that minimizes edge crossings in the diagram.
Parameters
H: hnx.Hypergraph the entity to be drawn spacing: float amount of whitespace between disconnected components
Source code in src/aeiva/hypergraph/visualization.py
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 |
|
llm
llm_client
LLMClient
Language Model interface that supports synchronous, asynchronous, and streaming modes, and optionally, tool usage via function calls.
Source code in src/aeiva/llm/llm_client.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
|
call_tool(api_name, function_name, params)
async
Calls the API via action module.
Source code in src/aeiva/llm/llm_client.py
279 280 281 282 |
|
call_tool_sync(api_name, function_name, params)
Calls the API via action module.
Source code in src/aeiva/llm/llm_client.py
284 285 286 287 |
|
call_tool_via_server(api_name, function_name, params)
Calls the API via FastAPI server.
Source code in src/aeiva/llm/llm_client.py
265 266 267 268 269 270 271 272 273 274 275 276 277 |
|
llm_gateway_config
LLMGatewayConfig
dataclass
Bases: BaseConfig
Configuration for the Language Model (LLM).
Source code in src/aeiva/llm/llm_gateway_config.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
llm_gateway_exceptions
LLMGatewayError
Bases: Exception
Unified exception class for all LLM-related errors.
Source code in src/aeiva/llm/llm_gateway_exceptions.py
25 26 27 28 29 30 |
|
llm_gateway_exception(e)
Converts a litellm exception to a unified LLMGatewayError.
Source code in src/aeiva/llm/llm_gateway_exceptions.py
55 56 57 58 59 |
|
llm_usage_metrics
LLMUsageMetrics
Tracks metrics such as token usage and cost.
Source code in src/aeiva/llm/llm_usage_metrics.py
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
model
macaw_model
LlamaAttention
Bases: Module
Multi-headed attention from 'Attention Is All You Need' paper
Source code in src/aeiva/model/macaw_model.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
|
LlamaDecoderLayer
Bases: Module
Source code in src/aeiva/model/macaw_model.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
|
forward(hidden_states, attention_mask=None, position_ids=None, past_key_value=None, output_attentions=False, use_cache=False)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hidden_states
|
`torch.FloatTensor`
|
input to the layer of shape |
required |
attention_mask
|
`torch.FloatTensor`, *optional*
|
attention mask of size
|
None
|
output_attentions
|
`bool`, *optional*
|
Whether or not to return the attentions tensors of all attention layers. See |
False
|
use_cache
|
`bool`, *optional*
|
If set to |
False
|
past_key_value
|
`Tuple(torch.FloatTensor)`, *optional*
|
cached past key and value projection states |
None
|
Source code in src/aeiva/model/macaw_model.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
|
LlamaModel
Bases: LlamaPreTrainedModel
Transformer decoder consisting of config.num_hidden_layers layers. Each layer is a [LlamaDecoderLayer
]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
LlamaConfig
|
LlamaConfig |
required |
Source code in src/aeiva/model/macaw_model.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 |
|
LlamaRMSNorm
Bases: Module
Source code in src/aeiva/model/macaw_model.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
|
__init__(hidden_size, eps=1e-06)
LlamaRMSNorm is equivalent to T5LayerNorm
Source code in src/aeiva/model/macaw_model.py
303 304 305 306 307 308 309 |
|
MM_LLMs_Config
Bases: PretrainedConfig
Source code in src/aeiva/model/macaw_model.py
807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 |
|
to_dict()
Serializes this instance to a Python dictionary. Override the default [~PretrainedConfig.to_dict
].
Returns:
Type | Description |
---|---|
|
Source code in src/aeiva/model/macaw_model.py
831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 |
|
WhisperEncoder
Bases: WhisperPreTrainedModel
Transformer encoder consisting of config.encoder_layers self attention layers. Each layer is a
[WhisperEncoderLayer
].
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
WhisperConfig
|
WhisperConfig |
required |
Source code in src/aeiva/model/macaw_model.py
662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 |
|
forward(input_features, attention_mask=None, head_mask=None, output_attentions=None, output_hidden_states=None, return_dict=None)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_features
|
`torch.LongTensor` of shape `(batch_size, feature_size, sequence_length)`
|
Float values of mel features extracted from the raw speech waveform. Raw speech waveform can be
obtained by loading a |
required |
attention_mask
|
`torch.Tensor`)`, *optional*
|
Whisper does not support masking of the |
None
|
head_mask
|
`torch.Tensor` of shape `(encoder_layers, encoder_attention_heads)`, *optional*
|
Mask to nullify selected heads of the attention modules. Mask values selected in
|
None
|
output_attentions
|
`bool`, *optional*
|
Whether or not to return the attentions tensors of all attention layers. See |
None
|
output_hidden_states
|
`bool`, *optional*
|
Whether or not to return the hidden states of all layers. See |
None
|
return_dict
|
`bool`, *optional*
|
Whether or not to return a [ |
None
|
Source code in src/aeiva/model/macaw_model.py
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 |
|
rotate_half(x)
Rotates half the hidden dims of the input.
Source code in src/aeiva/model/macaw_model.py
76 77 78 79 80 |
|
macaw_model_old
This script contains the implementation of the MACAW model. MACAW is a multimodal transformer model that combines the CLIP and Whisper models.
Author: Bang Liu Date: 2023-06-22
References: - Macaw-LLM code repository: https://github.com/lyuchenyang/Macaw-LLM/blob/main/modeling.py
LlamaAttention
Bases: Module
Multi-headed attention from 'Attention Is All You Need' paper
Source code in src/aeiva/model/macaw_model_old.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
|
LlamaDecoderLayer
Bases: Module
Source code in src/aeiva/model/macaw_model_old.py
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 |
|
forward(hidden_states, attention_mask=None, position_ids=None, past_key_value=None, output_attentions=False, use_cache=False)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hidden_states
|
`torch.FloatTensor`
|
input to the layer of shape |
required |
attention_mask
|
`torch.FloatTensor`, *optional*
|
attention mask of size
|
None
|
output_attentions
|
`bool`, *optional*
|
Whether or not to return the attentions tensors of all attention layers. See |
False
|
use_cache
|
`bool`, *optional*
|
If set to |
False
|
past_key_value
|
`Tuple(torch.FloatTensor)`, *optional*
|
cached past key and value projection states |
None
|
Source code in src/aeiva/model/macaw_model_old.py
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 |
|
LlamaModel
Bases: LlamaPreTrainedModel
Transformer decoder consisting of config.num_hidden_layers layers. Each layer is a [LlamaDecoderLayer
]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
LlamaConfig
|
LlamaConfig |
required |
Source code in src/aeiva/model/macaw_model_old.py
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 |
|
LlamaRMSNorm
Bases: Module
Source code in src/aeiva/model/macaw_model_old.py
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
|
__init__(hidden_size, eps=1e-06)
LlamaRMSNorm is equivalent to T5LayerNorm The overall effect of this layer is to ensure that, for each feature in the hidden_states, the activations have zero mean and unit variance across the batch. This can make the training process more stable and faster.
Source code in src/aeiva/model/macaw_model_old.py
317 318 319 320 321 322 323 324 325 326 327 |
|
LlamaRotaryEmbedding
Bases: Module
Rotary embedding described in: https://arxiv.org/pdf/2104.09864.pdf. It is used to modulate the position information in the input embeddings. Llama used rotary embedding.
Source code in src/aeiva/model/macaw_model_old.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
|
MM_LLMs
Bases: PreTrainedModel
This is the multimodal language model that combines CLIP and Whisper encoders with a language model. We need a config file to specify the multimodal encoder configurations.
Source code in src/aeiva/model/macaw_model_old.py
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 |
|
encode_video(videos)
Encode video features to video embeddings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
videos
|
(batch_size, n_frames, n_channels, height, width) |
required |
Returns:
Name | Type | Description |
---|---|---|
video_embeddings |
(batch_size, n_frames, embedding_dim) |
Source code in src/aeiva/model/macaw_model_old.py
1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 |
|
encode_video_long(videos)
Encode video features to video embeddings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
videos
|
(batch_size, n_frames, n_channels, height, width) |
required |
Returns:
Name | Type | Description |
---|---|---|
video_embeddings |
(batch_size, n_frames, embedding_dim) |
Source code in src/aeiva/model/macaw_model_old.py
1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 |
|
prepare_inputs_for_generation(inputs)
The purpose of this method is to integrate the different modalities into the text embeddings and prepare the associated attention mask and labels for the language model, so the model can generate text conditioned on all the input modalities.
(!!! my hypothesis)
video_frames: (B x F) audios: B x 1 images: B x 1 input_ids: B x L attention_mask: B x L labels: B x L video_starts: B x 1 video_ends: B x 1 audio_starts: B x 1 audio_ends: B x 1 image_starts: B x 1 image_ends: B x 1 inference: True/False
Source code in src/aeiva/model/macaw_model_old.py
1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 |
|
MM_LLMs_Config
Bases: PretrainedConfig
This is the configuration class to store the configuration of a MM_LLMsModel
.
It contains class level and instance level attributes.
It also contains the load (from_pretrained) and save (to_dict) methods for saving and loading configuration files.
Source code in src/aeiva/model/macaw_model_old.py
961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 |
|
to_dict()
Serializes this instance to a Python dictionary. Override the default [~PretrainedConfig.to_dict
].
This method overrides the base class method to include serialization of the
image, audio, and language model configurations along with the base configuration.
Returns:
Type | Description |
---|---|
|
Source code in src/aeiva/model/macaw_model_old.py
980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 |
|
WhisperEncoder
Bases: WhisperPreTrainedModel
Transformer encoder consisting of config.encoder_layers self attention layers. Each layer is a
[WhisperEncoderLayer
].
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
WhisperConfig
|
WhisperConfig |
required |
Source code in src/aeiva/model/macaw_model_old.py
801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 |
|
forward(input_features, attention_mask=None, head_mask=None, output_attentions=None, output_hidden_states=None, return_dict=None)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_features
|
`torch.LongTensor` of shape `(batch_size, feature_size, sequence_length)`
|
Float values of mel features extracted from the raw speech waveform. Raw speech waveform can be
obtained by loading a |
required |
attention_mask
|
`torch.Tensor`)`, *optional*
|
Whisper does not support masking of the |
None
|
head_mask
|
`torch.Tensor` of shape `(encoder_layers, encoder_attention_heads)`, *optional*
|
Mask to nullify selected heads of the attention modules. Mask values selected in
|
None
|
output_attentions
|
`bool`, *optional*
|
Whether or not to return the attentions tensors of all attention layers. See |
None
|
output_hidden_states
|
`bool`, *optional*
|
Whether or not to return the hidden states of all layers. See |
None
|
return_dict
|
`bool`, *optional*
|
Whether or not to return a [ |
None
|
Source code in src/aeiva/model/macaw_model_old.py
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 |
|
rotate_half(x)
Rotates half the hidden dims of the input.
Source code in src/aeiva/model/macaw_model_old.py
125 126 127 128 129 |
|
operator
custom_ops
macaw_dataitem_ops
This module contains the data item processing functions.
For a data item processing function, it takes a data example (a dict) as input and return a processed data example.
@Author: Bang Liu (chatsci.ai@gmail.com) @Date: 2023-07-11
Copyright (C) 2023 Bang Liu - All Rights Reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree.
dataitem_ops
This module contains the data item processing functions.
For a data item processing function, it takes a data example (a dict) as input and return a processed data example.
@Author: Bang Liu (chatsci.ai@gmail.com) @Date: 2023-07-11
Copyright (C) 2023 Bang Liu - All Rights Reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree.
dataset_ops
This module contains the utils for processing datasets.
A dataset in aeiva is a dictionary with the following structure: { "data": [ {sample1}, {sample2}, ..., {sampleN} ], "metadata": { "num_samples": XX, ... } } where each sample is a dictionary itself, and metadata is a dictionary that contains the number of samples and possibly other fields.
@Author: Bang Liu (chatsci.ai@gmail.com) @Date: 2023-07-13
Copyright (C) 2023 Bang Liu - All Rights Reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree.
build_and_merge_datasets(dataset_names, input_filepaths_dict, pipeline, output_dir, max_samples=sys.maxsize)
Build multiple datasets by formatting and processing them.
Source code in src/aeiva/operator/dataset_ops.py
70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
build_dataset(dataset_name, input_filepaths_dict, pipeline, output_dir, max_samples=sys.maxsize)
Build a dataset by formatting and processing it.
Source code in src/aeiva/operator/dataset_ops.py
43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
filter_dataset(dataset, filter_criteria, *args, **kwargs)
Filter a dataset by a filter function.
Source code in src/aeiva/operator/dataset_ops.py
93 94 95 96 97 98 99 |
|
filter_dataset_by_keys(dataset, keys_to_preserve)
Filter the dataset to only include specified keys in each sample.
Source code in src/aeiva/operator/dataset_ops.py
102 103 104 105 106 107 108 109 110 111 112 113 |
|
merge_datasets(datasets)
Merge multiple datasets into one.
Source code in src/aeiva/operator/dataset_ops.py
58 59 60 61 62 63 64 65 66 67 |
|
sample_dataset(dataset, n_samples)
Sample a number of samples from a dataset.
Source code in src/aeiva/operator/dataset_ops.py
85 86 87 88 89 90 |
|
save_dataset(dataset, output_path)
Save a dataset to a file by pickling it.
Source code in src/aeiva/operator/dataset_ops.py
148 149 150 151 152 |
|
split_dataset(dataset, train_ratio, seed=42)
Split a dataset into a training set and a validation set.
Source code in src/aeiva/operator/dataset_ops.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
|
perception
base_perception_system
PerceptionSystem
Bases: ABC
Abstract base class representing the Perception System of an agent.
The Perception System is responsible for capturing raw sensory data from the environment, processing this data into meaningful observations, and providing access to these observations for other components of the cognitive architecture.
Attributes:
Name | Type | Description |
---|---|---|
config |
Any
|
Configuration settings for the Perception System. |
state |
Any
|
The internal state of the Perception System, including raw data and observations. |
Source code in src/aeiva/perception/base_perception_system.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
|
__init__(config)
Initialize the Perception System with the provided configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Any
|
Configuration settings for the Perception System. |
required |
Source code in src/aeiva/perception/base_perception_system.py
20 21 22 23 24 25 26 27 28 |
|
capture(raw_data)
abstractmethod
async
Asynchronously capture raw sensory data from the environment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raw_data
|
Any
|
The raw sensory data to capture. |
required |
Raises:
Type | Description |
---|---|
CaptureError
|
If capturing the raw data fails. |
Source code in src/aeiva/perception/base_perception_system.py
54 55 56 57 58 59 60 61 62 63 64 65 |
|
get_observations()
Retrieve the current processed observations from the Perception System.
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The current observations. |
Source code in src/aeiva/perception/base_perception_system.py
98 99 100 101 102 103 104 105 |
|
handle_error(error)
Handle errors that occur during perception operations.
This method can be overridden to implement custom error handling logic, such as logging or retry mechanisms.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
error
|
Exception
|
The exception that was raised. |
required |
Source code in src/aeiva/perception/base_perception_system.py
107 108 109 110 111 112 113 114 115 116 117 118 |
|
init_state()
abstractmethod
Initialize the internal state of the Perception System.
This method should set up the initial state required for the Perception System's operations.
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The initial state of the Perception System. |
Source code in src/aeiva/perception/base_perception_system.py
30 31 32 33 34 35 36 37 38 39 40 |
|
perceive(raw_data)
async
Asynchronously perform the full perception cycle: capture and process raw sensory data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raw_data
|
Any
|
The raw sensory data to perceive. |
required |
Raises:
Type | Description |
---|---|
CaptureError
|
If capturing the raw data fails. |
ProcessingError
|
If processing the raw data fails. |
Source code in src/aeiva/perception/base_perception_system.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
process()
abstractmethod
async
Asynchronously process the captured raw sensory data into meaningful observations.
This method should transform raw data stored in the internal state into structured observations that can be utilized by other components of the cognitive architecture.
Raises:
Type | Description |
---|---|
ProcessingError
|
If processing the raw data fails. |
Source code in src/aeiva/perception/base_perception_system.py
67 68 69 70 71 72 73 74 75 76 77 78 |
|
setup()
abstractmethod
async
Asynchronously set up the Perception System's components.
This method should initialize any necessary components or resources based on the provided configuration.
Raises:
Type | Description |
---|---|
ConfigurationError
|
If the configuration is invalid or incomplete. |
Source code in src/aeiva/perception/base_perception_system.py
42 43 44 45 46 47 48 49 50 51 52 |
|
perception_system
PerceptionSystem
Manages multiple sensors and emits stimuli via the EventBus.
Source code in src/aeiva/perception/perception_system.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|
__init__(config, event_bus)
Initializes the PerceptionSystem with a list of sensors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Any
|
Configuration dictionary for the sensors. |
required |
event_bus
|
The EventBus instance for emitting events. |
required |
Source code in src/aeiva/perception/perception_system.py
15 16 17 18 19 20 21 22 23 24 25 26 |
|
setup()
Sets up the perception system by initializing all configured sensors.
Source code in src/aeiva/perception/perception_system.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
signal_to_stimuli(data)
Processes raw data from sensors into structured stimuli.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Any
|
The raw data emitted by sensors. |
required |
Returns:
Type | Description |
---|---|
Any
|
Processed data (stimuli). |
Source code in src/aeiva/perception/perception_system.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|
start()
async
Starts all sensors asynchronously.
Source code in src/aeiva/perception/perception_system.py
43 44 45 46 47 48 49 |
|
stop()
async
Stops all sensors asynchronously.
Source code in src/aeiva/perception/perception_system.py
51 52 53 54 55 56 57 |
|
sensation
Signal
Represents an atomic unit of perception that carries raw data from the environment. This class defines a signal, its characteristics, and its dependencies on other signals.
Source code in src/aeiva/perception/sensation.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
__init__(data, name=None, modularity=None, type=None, timestamp=None, id=None, dependencies=None, description=None, metadata=None)
Initialize a signal with its data and other optional metadata.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Any
|
The raw data of the signal. |
required |
name
|
Optional[str]
|
An optional name for the signal. |
None
|
modularity
|
Optional[str]
|
The modality of the signal (e.g., image, video, text, audio). |
None
|
type
|
Optional[str]
|
A more detailed signal type (e.g., 'text', 'document', etc.). |
None
|
timestamp
|
Optional[datetime]
|
The time when the signal was created or captured. |
None
|
id
|
Optional[str]
|
Unique identifier for the signal. |
None
|
dependencies
|
Optional[Dict[str, Any]]
|
Attributes of dependencies (e.g., relationship types). |
None
|
description
|
Optional[str]
|
Description of the signal. |
None
|
metadata
|
Optional[Dict[str, Any]]
|
Optional additional metadata for the signal. |
None
|
Source code in src/aeiva/perception/sensation.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|
to_dict()
Converts the signal into a dictionary representation.
Source code in src/aeiva/perception/sensation.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
sensor
Sensor
Bases: ABC
Abstract base class for all sensors.
Source code in src/aeiva/perception/sensor.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
__init__(name, params, event_bus)
Initializes the BaseSensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the sensor. |
required |
params
|
dict
|
Configuration parameters for the sensor. |
required |
event_bus
|
The EventBus instance for emitting events. |
required |
Source code in src/aeiva/perception/sensor.py
10 11 12 13 14 15 16 17 18 19 20 21 |
|
start()
abstractmethod
async
Starts the sensor.
Source code in src/aeiva/perception/sensor.py
23 24 25 26 27 28 |
|
stop()
abstractmethod
async
Stops the sensor.
Source code in src/aeiva/perception/sensor.py
30 31 32 33 34 35 |
|
stimuli
Stimuli
Represents a structured composition of signals, where each node can be a Signal or a sub-Stimuli. The graph allows flexible, directed relationships between nodes, and the graph can contain cycles.
Source code in src/aeiva/perception/stimuli.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
__init__(signals, id=None, name=None, type=None, modularity=None, timestamp=None, dependencies=None, description=None, metadata=None)
Initializes the Stimuli object by organizing signals or sub-stimuli in a graph structure.
Source code in src/aeiva/perception/stimuli.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
to_dict()
Converts the stimuli into a dictionary representation, including its signals and their relationships.
Source code in src/aeiva/perception/stimuli.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|
traverse(method='dfs')
Traverses the graph using the specified method ('dfs' or 'bfs').
Parameters:
Name | Type | Description | Default |
---|---|---|---|
method
|
str
|
The traversal method to use, either 'dfs' (Depth-First Search) or 'bfs' (Breadth-First Search). |
'dfs'
|
Returns:
Type | Description |
---|---|
List[Union[Signal, Stimuli]]
|
List[Union[Signal, 'Stimuli']]: A list of signals or sub-stimuli in the order they were visited. |
Source code in src/aeiva/perception/stimuli.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
visualize(save_path=None)
Visualizes the procedure's structure using networkx and matplotlib.
Source code in src/aeiva/perception/stimuli.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
terminal_input_sensor
TerminalInputSensor
Bases: Sensor
A sensor that reads input from the terminal and emits stimuli via the EventBus.
Source code in src/aeiva/perception/terminal_input_sensor.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
start()
async
Starts the sensor by launching the input thread.
Source code in src/aeiva/perception/terminal_input_sensor.py
20 21 22 23 24 25 26 |
|
stop()
async
Stops the sensor by signaling the thread to stop and waiting for it to finish.
Source code in src/aeiva/perception/terminal_input_sensor.py
29 30 31 32 33 34 35 |
|
test
handle_observation(stimuli)
async
Processes stimuli using the cognition system and outputs the response.
Source code in src/aeiva/perception/test.py
25 26 27 28 29 30 31 32 33 |
|
plugin
ability
plugin_a
plugin
PluginA
Bases: Plugin
Example Plugin A.
Source code in src/aeiva/plugin/ability/plugin_a/plugin.py
5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
plugin_b
plugin
PluginB
Bases: Plugin
Example Plugin B.
Source code in src/aeiva/plugin/ability/plugin_b/plugin.py
5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
plug
Plug Module
This module provides a flexible plugin system with support for:
- Multiple plugin sources with isolation
- Context managers and import hooks
- Resource loading from plugins
- Loading plugins from directories and zip files
- Hot swapping and lazy loading of plugins
Author: Bang Liu Date: 2024-11-19
Plugin
Bases: ABC
Abstract base class that all plugins must inherit from.
Source code in src/aeiva/plugin/plug.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
activate()
abstractmethod
Method called when the plugin is activated.
Source code in src/aeiva/plugin/plug.py
35 36 37 38 |
|
deactivate()
abstractmethod
Method called when the plugin is deactivated.
Source code in src/aeiva/plugin/plug.py
40 41 42 43 |
|
PluginFinder
Bases: MetaPathFinder
Custom finder for plugin modules.
Finds plugins as directories containing a plugin.py
file.
Source code in src/aeiva/plugin/plug.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
find_spec(fullname, path, target=None)
Find the module spec for the given module. Handles both the namespace package and its submodules (plugins).
Source code in src/aeiva/plugin/plug.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
PluginLoader
Bases: Loader
Custom loader for plugin modules.
Loads the plugin.py
file within the plugin directory.
Source code in src/aeiva/plugin/plug.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
create_module(spec)
Use default module creation semantics.
Source code in src/aeiva/plugin/plug.py
56 57 58 |
|
exec_module(module)
Execute the plugin's plugin.py
module.
Source code in src/aeiva/plugin/plug.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
PluginManager
Manages multiple PluginSources and controls plugin imports.
Source code in src/aeiva/plugin/plug.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
|
create_plugin_source(name, search_path=None)
Creates a new PluginSource.
:param name: Unique name for the plugin source. :param search_path: List of paths to search for plugins. :return: The created PluginSource.
Source code in src/aeiva/plugin/plug.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
|
get_plugin_source(name)
Retrieves a PluginSource by name.
:param name: Name of the PluginSource. :return: The PluginSource instance, or None if not found.
Source code in src/aeiva/plugin/plug.py
322 323 324 325 326 327 328 329 |
|
remove_plugin_source(name)
Removes a PluginSource.
:param name: Name of the PluginSource to remove.
Source code in src/aeiva/plugin/plug.py
331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
|
PluginSource
Represents an isolated source of plugins.
Each plugin is a directory containing a plugin.py
file.
Source code in src/aeiva/plugin/plug.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
|
__enter__()
Enter the runtime context related to this object.
Source code in src/aeiva/plugin/plug.py
147 148 149 150 |
|
__exit__(exc_type, exc_value, traceback)
Exit the runtime context.
Source code in src/aeiva/plugin/plug.py
152 153 154 |
|
__init__(name, search_path=None)
Initializes the PluginSource.
:param name: Unique name for the plugin source. :param search_path: List of paths (directories or zip files) to search for plugins.
Source code in src/aeiva/plugin/plug.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
|
disable()
Disable the plugin import mechanism.
Source code in src/aeiva/plugin/plug.py
163 164 165 166 167 168 169 170 171 |
|
enable()
Enable the plugin import mechanism.
Source code in src/aeiva/plugin/plug.py
156 157 158 159 160 161 |
|
get_plugin_code(plugin_name)
Get the source code of the plugin's plugin.py
.
:param plugin_name: Name of the plugin to load.
:return: Source code of plugin.py
as a string.
Source code in src/aeiva/plugin/plug.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
|
list_plugins()
Lists available plugins in the search paths.
Each plugin is a directory containing a plugin.py
file.
:return: List of plugin names.
Source code in src/aeiva/plugin/plug.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
|
load_plugin(plugin_name)
Loads a plugin by name.
:param plugin_name: Name of the plugin to load. :return: The loaded plugin module.
Source code in src/aeiva/plugin/plug.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
|
load_resource(plugin_name, resource_name)
Loads a resource from a plugin.
:param plugin_name: Name of the plugin. :param resource_name: Name of the resource file. :return: Contents of the resource file as bytes.
Source code in src/aeiva/plugin/plug.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
|
unload_plugin(plugin_name)
Unloads a plugin by name.
:param plugin_name: Name of the plugin to unload.
Source code in src/aeiva/plugin/plug.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
|
test
Main Application
This script demonstrates the usage of the plug module and plugin system.
society
society
Society
Bases: ABC
Abstract base class representing a Society that connects an environment and agents.
The Society enables agents to interact with each other and with the environment, providing mechanisms for integrating social systems, such as communication or economy.
Attributes:
Name | Type | Description |
---|---|---|
config |
Any
|
Configuration settings for the society. |
environment |
Environment
|
The environment in which agents operate. |
agents |
Dict[str, Any]
|
A dictionary of agents within the society. |
social_systems |
Dict[str, Any]
|
A dictionary representing various social systems (e.g., communication). |
Source code in src/aeiva/society/society.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
__init__(config, environment, agents)
Initialize the Society with the provided configuration, environment, and agents.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Any
|
Configuration settings for the society. |
required |
env
|
Environment
|
The environment in which agents operate. |
required |
agents
|
Dict[str, Any]
|
A dictionary of agents within the society, keyed by their IDs. |
required |
Source code in src/aeiva/society/society.py
20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
add_agent(agent_id, agent)
Add a new agent to the society.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent_id
|
str
|
The unique identifier of the agent. |
required |
agent
|
Any
|
The agent object to add to the society. |
required |
Source code in src/aeiva/society/society.py
63 64 65 66 67 68 69 70 71 |
|
get_agent(agent_id)
Retrieve an agent by its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent_id
|
str
|
The unique identifier of the agent. |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The agent object, if found. |
Source code in src/aeiva/society/society.py
83 84 85 86 87 88 89 90 91 92 93 |
|
handle_error(error)
Handle errors that occur during society operations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
error
|
Exception
|
The exception that was raised. |
required |
Source code in src/aeiva/society/society.py
95 96 97 98 99 100 101 102 |
|
init_social_systems()
abstractmethod
Initialize the social systems that operate within the society (e.g., communication, financial, law, political, social network systems).
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary of initialized social systems. |
Source code in src/aeiva/society/society.py
34 35 36 37 38 39 40 41 42 |
|
remove_agent(agent_id)
Remove an agent from the society by its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent_id
|
str
|
The unique identifier of the agent. |
required |
Source code in src/aeiva/society/society.py
73 74 75 76 77 78 79 80 81 |
|
run()
abstractmethod
async
Asynchronously run the society, managing interactions between agents and the environment.
This method should control the flow of interactions between agents and the environment, and it can be designed as a continuous loop or a task-based execution.
Source code in src/aeiva/society/society.py
53 54 55 56 57 58 59 60 61 |
|
setup()
abstractmethod
async
Asynchronously set up the society's components, such as initializing the environment and agents.
Source code in src/aeiva/society/society.py
44 45 46 47 48 49 50 51 |
|
storage
azure_ai_search
azure_ai_search_config
AzureAISearchConfig
dataclass
Bases: BaseConfig
Configuration for Azure Cognitive Search vector database.
Source code in src/aeiva/storage/azure_ai_search/azure_ai_search_config.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
azure_ai_search_database
AzureAISearchDatabase
Bases: VectorDatabase
Concrete implementation of VectorStoreBase using Azure Cognitive Search.
Source code in src/aeiva/storage/azure_ai_search/azure_ai_search_database.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
|
__del__()
Clean up resources.
Source code in src/aeiva/storage/azure_ai_search/azure_ai_search_database.py
318 319 320 321 |
|
__init__(config)
Initialize the Azure Cognitive Search vector store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Dict[str, Any]
|
Configuration dictionary. |
required |
Source code in src/aeiva/storage/azure_ai_search/azure_ai_search_database.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
create_client(uri=None, service_name=None, api_key=None, **kwargs)
Initializes the client connection to the vector store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri
|
Optional[str]
|
Not used for Azure Cognitive Search. |
None
|
service_name
|
str
|
Azure Cognitive Search service name. |
None
|
api_key
|
str
|
API key for the Azure Cognitive Search service. |
None
|
**kwargs
|
Additional parameters. |
{}
|
Source code in src/aeiva/storage/azure_ai_search/azure_ai_search_database.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
create_collection(collection_name, vector_size, distance_metric)
Create a new vector collection (index) in Azure Cognitive Search.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
vector_size
|
int
|
The dimensionality of the vectors. |
required |
distance_metric
|
str
|
The distance metric to use (e.g., 'cosine'). |
required |
Source code in src/aeiva/storage/azure_ai_search/azure_ai_search_database.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
|
delete_collection(collection_name)
Delete an entire vector collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection to delete. |
required |
Source code in src/aeiva/storage/azure_ai_search/azure_ai_search_database.py
291 292 293 294 295 296 297 298 299 |
|
delete_vector(collection_name, vector_id)
Delete a vector from a collection by its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
vector_id
|
str
|
The unique identifier of the vector to delete. |
required |
Source code in src/aeiva/storage/azure_ai_search/azure_ai_search_database.py
216 217 218 219 220 221 222 223 224 225 226 227 |
|
get_collection_info(collection_name)
Get information about a collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: Information about the collection. |
Source code in src/aeiva/storage/azure_ai_search/azure_ai_search_database.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
|
get_vector(collection_name, vector_id)
Retrieve a vector by its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
vector_id
|
str
|
The unique identifier of the vector. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary containing the vector data and payload. |
Source code in src/aeiva/storage/azure_ai_search/azure_ai_search_database.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
|
insert_vectors(collection_name, vectors, payloads=None, ids=None)
Insert vectors into the index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
vectors
|
List[List[float]]
|
A list of vectors to insert. |
required |
payloads
|
Optional[List[Dict[str, Any]]]
|
Optional metadata associated with each vector. |
None
|
ids
|
Optional[List[str]]
|
Optional unique identifiers for each vector. |
None
|
Source code in src/aeiva/storage/azure_ai_search/azure_ai_search_database.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
list_collections()
List all available vector collections.
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: A list of collection names. |
Source code in src/aeiva/storage/azure_ai_search/azure_ai_search_database.py
281 282 283 284 285 286 287 288 289 |
|
search_vectors(collection_name, query_vector, top_k=5, filters=None)
Search for similar vectors in a collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
query_vector
|
List[float]
|
The vector to search with. |
required |
top_k
|
int
|
The number of top results to return. |
5
|
filters
|
Optional[Dict[str, Any]]
|
Optional filters to apply to the search. |
None
|
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of search results. |
Source code in src/aeiva/storage/azure_ai_search/azure_ai_search_database.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
|
update_vector(collection_name, vector_id, vector=None, payload=None)
Update a vector's data or payload.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
vector_id
|
str
|
The unique identifier of the vector to update. |
required |
vector
|
Optional[List[float]]
|
The new vector data. |
None
|
payload
|
Optional[Dict[str, Any]]
|
The new payload data. |
None
|
Source code in src/aeiva/storage/azure_ai_search/azure_ai_search_database.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
|
chroma
chroma_config
ChromaConfig
dataclass
Bases: BaseConfig
Configuration for ChromaDB vector database.
Source code in src/aeiva/storage/chroma/chroma_config.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
chroma_database
ChromaDatabase
Bases: VectorDatabase
Concrete implementation of VectorStoreBase using ChromaDB.
Source code in src/aeiva/storage/chroma/chroma_database.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
|
__init__(config)
Initialize the ChromaDB vector store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Dict[str, Any]
|
Configuration dictionary. |
required |
Source code in src/aeiva/storage/chroma/chroma_database.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
create_client(uri=None, host=None, port=None, path=None, **kwargs)
Initializes the client connection to the vector store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri
|
Optional[str]
|
Not used for ChromaDB. |
None
|
host
|
Optional[str]
|
Host address for ChromaDB server. |
None
|
port
|
Optional[int]
|
Port for ChromaDB server. |
None
|
path
|
Optional[str]
|
Path to the database directory. |
None
|
**kwargs
|
Additional parameters. |
{}
|
Source code in src/aeiva/storage/chroma/chroma_database.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
|
create_collection(collection_name, vector_size, distance_metric)
Create a new vector collection in ChromaDB.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
vector_size
|
int
|
Not used for ChromaDB. |
required |
distance_metric
|
str
|
Not used for ChromaDB. |
required |
Source code in src/aeiva/storage/chroma/chroma_database.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
|
delete_collection(collection_name)
Delete an entire vector collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection to delete. |
required |
Source code in src/aeiva/storage/chroma/chroma_database.py
240 241 242 243 244 245 246 247 248 |
|
delete_vector(collection_name, vector_id)
Delete a vector from a collection by its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
vector_id
|
str
|
The unique identifier of the vector to delete. |
required |
Source code in src/aeiva/storage/chroma/chroma_database.py
169 170 171 172 173 174 175 176 177 178 179 180 181 |
|
get_collection_info(collection_name)
Get information about a collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: Information about the collection. |
Source code in src/aeiva/storage/chroma/chroma_database.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
|
get_vector(collection_name, vector_id)
Retrieve a vector by its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
vector_id
|
str
|
The unique identifier of the vector. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary containing the vector data and payload. |
Source code in src/aeiva/storage/chroma/chroma_database.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
|
insert_vectors(collection_name, vectors, payloads=None, ids=None)
Insert vectors into a collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
vectors
|
List[List[float]]
|
A list of vectors to insert. |
required |
payloads
|
Optional[List[Dict[str, Any]]]
|
Optional metadata associated with each vector. |
None
|
ids
|
Optional[List[str]]
|
Optional unique identifiers for each vector. |
None
|
Source code in src/aeiva/storage/chroma/chroma_database.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
list_collections()
List all available vector collections.
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: A list of collection names. |
Source code in src/aeiva/storage/chroma/chroma_database.py
230 231 232 233 234 235 236 237 238 |
|
search_vectors(collection_name, query_vector, top_k=5, filters=None)
Search for similar vectors in a collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
query_vector
|
List[float]
|
The vector to search with. |
required |
top_k
|
int
|
The number of top results to return. |
5
|
filters
|
Optional[Dict[str, Any]]
|
Optional filters to apply to the search. |
None
|
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of search results. |
Source code in src/aeiva/storage/chroma/chroma_database.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|
update_vector(collection_name, vector_id, vector=None, payload=None)
Update a vector's data or payload.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
vector_id
|
str
|
The unique identifier of the vector to update. |
required |
vector
|
Optional[List[float]]
|
The new vector data. |
None
|
payload
|
Optional[Dict[str, Any]]
|
The new payload data. |
None
|
Source code in src/aeiva/storage/chroma/chroma_database.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
|
database_factory
DatabaseConfigFactory
Factory class to create database configuration objects based on the provider name.
Example
config = DatabaseConfigFactory.create( 'milvus', host='localhost', port=19530, embedding_model_dims=128, ... )
Source code in src/aeiva/storage/database_factory.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
create(provider_name, **kwargs)
classmethod
Create a database configuration object based on the provider name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
provider_name
|
str
|
The name of the database provider (e.g., 'milvus', 'chroma'). |
required |
**kwargs
|
Configuration parameters specific to the database provider. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
An instance of the database configuration class. |
Raises:
Type | Description |
---|---|
ValueError
|
If the provider name is not supported. |
ImportError
|
If the configuration class cannot be imported. |
Source code in src/aeiva/storage/database_factory.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
DatabaseFactory
Factory class to create database objects based on the provider name and configuration.
Example
db = DatabaseFactory.create('milvus', config)
Source code in src/aeiva/storage/database_factory.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
create(provider_name, config)
classmethod
Create a database object based on the provider name and configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
provider_name
|
str
|
The name of the database provider. |
required |
config
|
Any
|
Configuration object or dictionary for the database. |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
An instance of the database class. |
Raises:
Type | Description |
---|---|
ValueError
|
If the provider name is not supported. |
ImportError
|
If the database class cannot be imported. |
TypeError
|
If the configuration cannot be converted to a dictionary. |
Source code in src/aeiva/storage/database_factory.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
load_class(class_path)
Dynamically load a class from a string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
class_path
|
str
|
The full path to the class, e.g., 'module.submodule.ClassName'. |
required |
Returns:
Name | Type | Description |
---|---|---|
Type |
Type
|
The class type. |
Raises:
Type | Description |
---|---|
ImportError
|
If the module or class cannot be found. |
Source code in src/aeiva/storage/database_factory.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
graph_database
GraphDatabase
Bases: ABC
Abstract base class for graph database operations.
Source code in src/aeiva/storage/graph_database.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
|
add_edge(source_id, target_id, relationship, properties=None)
abstractmethod
Adds an edge (relationship) between two nodes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_id
|
str
|
Unique identifier of the source node. |
required |
target_id
|
str
|
Unique identifier of the target node. |
required |
relationship
|
str
|
Type of the relationship. |
required |
properties
|
Optional[Dict[str, Any]]
|
Properties associated with the edge. |
None
|
Raises:
Type | Description |
---|---|
NodeNotFoundError
|
If either the source or target node does not exist. |
StorageError
|
If there is an issue adding the edge. |
Source code in src/aeiva/storage/graph_database.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
add_node(node_id, properties=None, labels=None)
abstractmethod
Adds a node to the graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
str
|
Unique identifier for the node. |
required |
properties
|
Optional[Dict[str, Any]]
|
Properties associated with the node. |
None
|
labels
|
Optional[List[str]]
|
Labels or types associated with the node. |
None
|
Raises:
Type | Description |
---|---|
StorageError
|
If there is an issue adding the node. |
Source code in src/aeiva/storage/graph_database.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
close()
abstractmethod
Closes the graph database connection and releases resources.
Source code in src/aeiva/storage/graph_database.py
281 282 283 284 285 286 |
|
delete_all()
abstractmethod
Deletes all nodes and their associated relationships from the graph.
Raises:
Type | Description |
---|---|
StorageError
|
If there is an issue deleting all nodes and relationships. |
Source code in src/aeiva/storage/graph_database.py
114 115 116 117 118 119 120 121 122 |
|
delete_all_edges()
abstractmethod
Deletes all edges from the graph without deleting the nodes.
Raises:
Type | Description |
---|---|
StorageError
|
If there is an issue deleting all relationships. |
Source code in src/aeiva/storage/graph_database.py
124 125 126 127 128 129 130 131 132 |
|
delete_edge(source_id, target_id, relationship)
abstractmethod
Deletes a specific relationship between two nodes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_id
|
str
|
Unique identifier of the source node. |
required |
target_id
|
str
|
Unique identifier of the target node. |
required |
relationship
|
str
|
Type of the relationship to delete. |
required |
Raises:
Type | Description |
---|---|
RelationshipNotFoundError
|
If the relationship does not exist. |
StorageError
|
If there is an issue deleting the relationship. |
Source code in src/aeiva/storage/graph_database.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
delete_node(node_id)
abstractmethod
Deletes a node from the graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
str
|
Unique identifier of the node. |
required |
Raises:
Type | Description |
---|---|
NodeNotFoundError
|
If the node does not exist. |
StorageError
|
If there is an issue deleting the node. |
Source code in src/aeiva/storage/graph_database.py
100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
delete_relationships_by_type(relationship)
abstractmethod
Deletes all relationships of a specific type from the graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
relationship
|
str
|
The type of relationships to delete. |
required |
Raises:
Type | Description |
---|---|
StorageError
|
If there is an issue deleting the relationships. |
Source code in src/aeiva/storage/graph_database.py
134 135 136 137 138 139 140 141 142 143 144 145 |
|
execute_query(query, parameters=None)
abstractmethod
Executes a raw query against the graph database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
The query string. |
required |
parameters
|
Optional[Dict[str, Any]]
|
Parameters for parameterized queries. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The result of the query. |
Raises:
Type | Description |
---|---|
StorageError
|
If there is an issue executing the query. |
Source code in src/aeiva/storage/graph_database.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
|
get_neighbors(node_id, relationship=None, direction='both')
abstractmethod
Retrieves neighboring nodes connected by edges.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
str
|
Unique identifier of the node. |
required |
relationship
|
Optional[str]
|
Filter by relationship type. |
None
|
direction
|
str
|
Direction of the relationships ('in', 'out', 'both'). |
'both'
|
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of neighboring nodes. |
Raises:
Type | Description |
---|---|
NodeNotFoundError
|
If the node does not exist. |
StorageError
|
If there is an issue retrieving neighbors. |
Source code in src/aeiva/storage/graph_database.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
|
get_node(node_id)
abstractmethod
Retrieves a node by its identifier.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
str
|
Unique identifier of the node. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary containing the node's properties and labels. |
Raises:
Type | Description |
---|---|
NodeNotFoundError
|
If the node does not exist. |
StorageError
|
If there is an issue retrieving the node. |
Source code in src/aeiva/storage/graph_database.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
get_relationship(source_id, target_id, relationship)
abstractmethod
Retrieves a specific relationship between two nodes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_id
|
str
|
Unique identifier of the source node. |
required |
target_id
|
str
|
Unique identifier of the target node. |
required |
relationship
|
str
|
Type of the relationship to retrieve. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary containing the relationship's properties. |
Raises:
Type | Description |
---|---|
RelationshipNotFoundError
|
If the relationship does not exist. |
StorageError
|
If there is an issue retrieving the relationship. |
Source code in src/aeiva/storage/graph_database.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
|
query_nodes(properties, labels=None)
abstractmethod
Queries nodes based on properties and labels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
properties
|
Dict[str, Any]
|
Properties to filter nodes. |
required |
labels
|
Optional[List[str]]
|
Labels to filter nodes. |
None
|
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of nodes matching the query. |
Raises:
Type | Description |
---|---|
StorageError
|
If there is an issue querying nodes. |
Source code in src/aeiva/storage/graph_database.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
|
update_edge(source_id, target_id, relationship, properties)
abstractmethod
Updates properties of a specific relationship between two nodes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_id
|
str
|
Unique identifier of the source node. |
required |
target_id
|
str
|
Unique identifier of the target node. |
required |
relationship
|
str
|
Type of the relationship to update. |
required |
properties
|
Dict[str, Any]
|
Properties to update on the relationship. |
required |
Raises:
Type | Description |
---|---|
RelationshipNotFoundError
|
If the relationship does not exist. |
StorageError
|
If there is an issue updating the relationship. |
Source code in src/aeiva/storage/graph_database.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
|
update_node(node_id, properties)
abstractmethod
Updates properties of a node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
str
|
Unique identifier of the node. |
required |
properties
|
Dict[str, Any]
|
Properties to update. |
required |
Raises:
Type | Description |
---|---|
NodeNotFoundError
|
If the node does not exist. |
StorageError
|
If there is an issue updating the node. |
Source code in src/aeiva/storage/graph_database.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
NodeNotFoundError
Bases: Exception
Exception raised when a node is not found in the graph database.
Source code in src/aeiva/storage/graph_database.py
5 6 7 |
|
RelationshipNotFoundError
Bases: Exception
Exception raised when a relationship is not found in the graph database.
Source code in src/aeiva/storage/graph_database.py
10 11 12 |
|
StorageError
Bases: Exception
Exception raised when there is a storage-related error in the graph database.
Source code in src/aeiva/storage/graph_database.py
15 16 17 |
|
milvus
milvus_config
MilvusConfig
dataclass
Bases: BaseConfig
Configuration for Milvus vector database.
Source code in src/aeiva/storage/milvus/milvus_config.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
|
milvus_database
MilvusDatabase
Bases: VectorDatabase
Concrete implementation of VectorStoreBase using Milvus.
Source code in src/aeiva/storage/milvus/milvus_database.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
|
__del__()
Clean up resources.
Source code in src/aeiva/storage/milvus/milvus_database.py
350 351 352 |
|
__init__(config)
Initialize the Milvus vector store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Dict[str, Any]
|
Configuration dictionary. |
required |
Source code in src/aeiva/storage/milvus/milvus_database.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
create_client(uri, user=None, password=None, token=None, **kwargs)
Initializes the client connection to the Milvus vector store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri
|
str
|
The URI of the vector store instance. |
required |
user
|
Optional[str]
|
Username for authentication. |
None
|
password
|
Optional[str]
|
Password for authentication. |
None
|
token
|
Optional[str]
|
Access token for authentication. |
None
|
**kwargs
|
Additional parameters. |
{}
|
Source code in src/aeiva/storage/milvus/milvus_database.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
create_collection(collection_name, vector_size, distance_metric)
Create a new vector collection in Milvus.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
vector_size
|
int
|
The dimensionality of the vectors. |
required |
distance_metric
|
str
|
The distance metric to use (e.g., 'L2', 'IP', 'COSINE'). |
required |
Source code in src/aeiva/storage/milvus/milvus_database.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
delete_collection(collection_name)
Delete an entire vector collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection to delete. |
required |
Source code in src/aeiva/storage/milvus/milvus_database.py
324 325 326 327 328 329 330 331 332 |
|
delete_vector(collection_name, vector_id)
Delete a vector from a collection by its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
vector_id
|
str
|
The unique identifier of the vector to delete. |
required |
Source code in src/aeiva/storage/milvus/milvus_database.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
|
get_collection_info(collection_name)
Get information about a collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: Information about the collection. |
Source code in src/aeiva/storage/milvus/milvus_database.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
|
get_vector(collection_name, vector_id)
Retrieve a vector by its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
vector_id
|
str
|
The unique identifier of the vector. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary containing the vector data and payload. |
Source code in src/aeiva/storage/milvus/milvus_database.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
|
insert_vectors(collection_name, vectors, payloads=None, ids=None)
Insert vectors into a collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
vectors
|
List[List[float]]
|
A list of vectors to insert. |
required |
payloads
|
Optional[List[Dict[str, Any]]]
|
Optional metadata associated with each vector. |
None
|
ids
|
Optional[List[str]]
|
Optional unique identifiers for each vector. |
None
|
Source code in src/aeiva/storage/milvus/milvus_database.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
|
list_collections()
List all available vector collections.
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: A list of collection names. |
Source code in src/aeiva/storage/milvus/milvus_database.py
315 316 317 318 319 320 321 322 |
|
search_vectors(collection_name, query_vector, top_k=5, filters=None)
Search for similar vectors in a collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
query_vector
|
List[float]
|
The vector to search with. |
required |
top_k
|
int
|
The number of top results to return. |
5
|
filters
|
Optional[Dict[str, Any]]
|
Optional filters to apply to the search. |
None
|
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of search results. |
Source code in src/aeiva/storage/milvus/milvus_database.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
|
update_vector(collection_name, vector_id, vector=None, payload=None)
Update a vector's data or payload.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
vector_id
|
str
|
The unique identifier of the vector to update. |
required |
vector
|
Optional[List[float]]
|
The new vector data. |
None
|
payload
|
Optional[Dict[str, Any]]
|
The new payload data. |
None
|
Source code in src/aeiva/storage/milvus/milvus_database.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
|
neo4jdb
neo4j_config
Neo4jConfig
dataclass
Bases: BaseConfig
Configuration for Neo4j graph database.
Source code in src/aeiva/storage/neo4jdb/neo4j_config.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
neo4j_database
Neo4jDatabase
Bases: GraphDatabase
Concrete implementation of GraphStoreBase using Neo4j.
Source code in src/aeiva/storage/neo4jdb/neo4j_database.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 |
|
__del__()
Destructor to ensure resources are cleaned up.
Source code in src/aeiva/storage/neo4jdb/neo4j_database.py
564 565 566 |
|
__init__(config)
Initialize the Neo4j graph database connection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Dict[str, Any]
|
Configuration dictionary. |
required |
Source code in src/aeiva/storage/neo4jdb/neo4j_database.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
add_edge(source_id, target_id, relationship, properties=None)
Adds an edge (relationship) between two nodes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_id
|
str
|
Unique identifier of the source node. |
required |
target_id
|
str
|
Unique identifier of the target node. |
required |
relationship
|
str
|
Type of the relationship. |
required |
properties
|
Optional[Dict[str, Any]]
|
Properties associated with the edge. |
None
|
Raises:
Type | Description |
---|---|
NodeNotFoundError
|
If either the source or target node does not exist. |
StorageError
|
If there is an issue adding the edge. |
Source code in src/aeiva/storage/neo4jdb/neo4j_database.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|
add_node(node_id, properties=None, labels=None)
Adds a node to the graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
str
|
Unique identifier for the node. |
required |
properties
|
Optional[Dict[str, Any]]
|
Properties associated with the node. |
None
|
labels
|
Optional[List[str]]
|
Labels or types associated with the node. |
None
|
Raises:
Type | Description |
---|---|
StorageError
|
If there is an issue adding the node. |
Source code in src/aeiva/storage/neo4jdb/neo4j_database.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
close()
Closes the graph database connection and releases resources.
Source code in src/aeiva/storage/neo4jdb/neo4j_database.py
554 555 556 557 558 559 560 561 562 |
|
create_client(uri, user, password, encrypted=True, **kwargs)
Initializes the client connection to the Neo4j graph database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri
|
str
|
The URI of the Neo4j instance. |
required |
user
|
str
|
Username for authentication. |
required |
password
|
str
|
Password for authentication. |
required |
encrypted
|
bool
|
Whether to use encrypted connection. |
True
|
**kwargs
|
Additional parameters. |
{}
|
Raises:
Type | Description |
---|---|
ConnectionError
|
If the client fails to connect to the graph database. |
Source code in src/aeiva/storage/neo4jdb/neo4j_database.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
|
delete_all()
Deletes all nodes and relationships from the Neo4j graph database.
Raises:
Type | Description |
---|---|
StorageError
|
If there is an issue deleting all nodes and relationships. |
Source code in src/aeiva/storage/neo4jdb/neo4j_database.py
410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
|
delete_all_edges()
Deletes all relationships from the Neo4j graph database without deleting nodes.
Raises:
Type | Description |
---|---|
StorageError
|
If there is an issue deleting relationships. |
Source code in src/aeiva/storage/neo4jdb/neo4j_database.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
|
delete_edge(source_id, target_id, relationship)
Deletes a specific relationship between two nodes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_id
|
str
|
Unique identifier of the source node. |
required |
target_id
|
str
|
Unique identifier of the target node. |
required |
relationship
|
str
|
Type of the relationship to delete. |
required |
Raises:
Type | Description |
---|---|
StorageError
|
If there is an issue deleting the relationship. |
Source code in src/aeiva/storage/neo4jdb/neo4j_database.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
|
delete_node(node_id)
Deletes a node from the graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
str
|
Unique identifier of the node. |
required |
Raises:
Type | Description |
---|---|
NodeNotFoundError
|
If the node does not exist. |
StorageError
|
If there is an issue deleting the node. |
Source code in src/aeiva/storage/neo4jdb/neo4j_database.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
|
delete_relationships_by_type(relationship)
Deletes all relationships of a specific type from the Neo4j graph database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
relationship
|
str
|
The type of relationships to delete. |
required |
Raises:
Type | Description |
---|---|
StorageError
|
If there is an issue deleting the relationships. |
Source code in src/aeiva/storage/neo4jdb/neo4j_database.py
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
|
execute_query(query, parameters=None)
Executes a raw query against the graph database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
The query string. |
required |
parameters
|
Optional[Dict[str, Any]]
|
Parameters for parameterized queries. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The result of the query. |
Raises:
Type | Description |
---|---|
StorageError
|
If there is an issue executing the query. |
Source code in src/aeiva/storage/neo4jdb/neo4j_database.py
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 |
|
get_neighbors(node_id, relationship=None, direction='both')
Retrieves neighboring nodes connected by edges.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
str
|
Unique identifier of the node. |
required |
relationship
|
Optional[str]
|
Filter by relationship type. |
None
|
direction
|
str
|
Direction of the relationships ('in', 'out', 'both'). |
'both'
|
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of neighboring nodes. |
Raises:
Type | Description |
---|---|
NodeNotFoundError
|
If the node does not exist. |
StorageError
|
If there is an issue retrieving neighbors. |
Source code in src/aeiva/storage/neo4jdb/neo4j_database.py
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 |
|
get_node(node_id)
Retrieves a node by its identifier.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
str
|
Unique identifier of the node. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary containing the node's properties and labels. |
Raises:
Type | Description |
---|---|
NodeNotFoundError
|
If the node does not exist. |
StorageError
|
If there is an issue retrieving the node. |
Source code in src/aeiva/storage/neo4jdb/neo4j_database.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
|
get_relationship(source_id, target_id, relationship)
Retrieves a specific relationship between two nodes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_id
|
str
|
Unique identifier of the source node. |
required |
target_id
|
str
|
Unique identifier of the target node. |
required |
relationship
|
str
|
Type of the relationship to retrieve. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary containing the relationship's properties. |
Raises:
Type | Description |
---|---|
StorageError
|
If there is an issue retrieving the relationship. |
Source code in src/aeiva/storage/neo4jdb/neo4j_database.py
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
|
query_nodes(properties, labels=None)
Queries nodes based on properties and labels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
properties
|
Dict[str, Any]
|
Properties to filter nodes. |
required |
labels
|
Optional[List[str]]
|
Labels to filter nodes. |
None
|
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of nodes matching the query. |
Raises:
Type | Description |
---|---|
StorageError
|
If there is an issue querying nodes. |
Source code in src/aeiva/storage/neo4jdb/neo4j_database.py
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 |
|
update_edge(source_id, target_id, relationship, properties)
Updates properties of a specific relationship between two nodes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_id
|
str
|
Unique identifier of the source node. |
required |
target_id
|
str
|
Unique identifier of the target node. |
required |
relationship
|
str
|
Type of the relationship to update. |
required |
properties
|
Dict[str, Any]
|
Properties to update on the relationship. |
required |
Raises:
Type | Description |
---|---|
StorageError
|
If there is an issue updating the relationship. |
Source code in src/aeiva/storage/neo4jdb/neo4j_database.py
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
|
update_node(node_id, properties)
Updates properties of a node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
str
|
Unique identifier of the node. |
required |
properties
|
Dict[str, Any]
|
Properties to update. |
required |
Raises:
Type | Description |
---|---|
NodeNotFoundError
|
If the node does not exist. |
StorageError
|
If there is an issue updating the node. |
Source code in src/aeiva/storage/neo4jdb/neo4j_database.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
|
NodeNotFoundError
Bases: Exception
Exception raised when a node is not found in the graph database.
Source code in src/aeiva/storage/neo4jdb/neo4j_database.py
11 12 13 |
|
StorageError
Bases: Exception
Exception raised when there is a storage-related error in the graph database.
Source code in src/aeiva/storage/neo4jdb/neo4j_database.py
16 17 18 |
|
pgvector
pgvector_config
PGVectorConfig
dataclass
Bases: BaseConfig
Configuration for PGVector (PostgreSQL with vector extension).
Source code in src/aeiva/storage/pgvector/pgvector_config.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
pgvector_database
PGVectorDatabase
Bases: VectorDatabase
Concrete implementation of VectorStoreBase using PGVector.
Source code in src/aeiva/storage/pgvector/pgvector_database.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
|
__del__()
Clean up resources.
Source code in src/aeiva/storage/pgvector/pgvector_database.py
317 318 319 320 321 322 323 |
|
__init__(config)
Initialize the PGVector vector store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Dict[str, Any]
|
Configuration dictionary. |
required |
Source code in src/aeiva/storage/pgvector/pgvector_database.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
create_client(**kwargs)
Initializes the client connection to the PGVector database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Additional parameters. |
{}
|
Source code in src/aeiva/storage/pgvector/pgvector_database.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
create_collection(collection_name, vector_size, distance_metric)
Create a new vector collection (table) in PGVector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
vector_size
|
int
|
The dimensionality of the vectors. |
required |
distance_metric
|
str
|
The distance metric to use (e.g., 'cosine'). |
required |
Source code in src/aeiva/storage/pgvector/pgvector_database.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
delete_collection(collection_name)
Delete an entire vector collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection to delete. |
required |
Source code in src/aeiva/storage/pgvector/pgvector_database.py
284 285 286 287 288 289 290 291 292 293 294 |
|
delete_vector(collection_name, vector_id)
Delete a vector from a collection by its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
vector_id
|
str
|
The unique identifier of the vector to delete. |
required |
Source code in src/aeiva/storage/pgvector/pgvector_database.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
|
get_collection_info(collection_name)
Get information about a collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: Information about the collection. |
Source code in src/aeiva/storage/pgvector/pgvector_database.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
|
get_vector(collection_name, vector_id)
Retrieve a vector by its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
vector_id
|
str
|
The unique identifier of the vector. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary containing the vector data and payload. |
Source code in src/aeiva/storage/pgvector/pgvector_database.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
|
insert_vectors(collection_name, vectors, payloads=None, ids=None)
Insert vectors into a collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
vectors
|
List[List[float]]
|
A list of vectors to insert. |
required |
payloads
|
Optional[List[Dict[str, Any]]]
|
Optional metadata associated with each vector. |
None
|
ids
|
Optional[List[str]]
|
Optional unique identifiers for each vector. |
None
|
Source code in src/aeiva/storage/pgvector/pgvector_database.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
list_collections()
List all available vector collections (tables).
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: A list of collection names. |
Source code in src/aeiva/storage/pgvector/pgvector_database.py
271 272 273 274 275 276 277 278 279 280 281 282 |
|
search_vectors(collection_name, query_vector, top_k=5, filters=None)
Search for similar vectors in a collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
query_vector
|
List[float]
|
The vector to search with. |
required |
top_k
|
int
|
The number of top results to return. |
5
|
filters
|
Optional[Dict[str, Any]]
|
Optional filters to apply to the search. |
None
|
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of search results. |
Source code in src/aeiva/storage/pgvector/pgvector_database.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
update_vector(collection_name, vector_id, vector=None, payload=None)
Update a vector's data or payload.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
vector_id
|
str
|
The unique identifier of the vector to update. |
required |
vector
|
Optional[List[float]]
|
The new vector data. |
None
|
payload
|
Optional[Dict[str, Any]]
|
The new payload data. |
None
|
Source code in src/aeiva/storage/pgvector/pgvector_database.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
|
postgresql
postgresql_config
PostgreSQLConfig
dataclass
Bases: BaseConfig
Configuration for PostgreSQL database.
Source code in src/aeiva/storage/postgresql/postgresql_config.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
postgresql_database
PostgreSQLDatabase
Bases: RelationalDatabase
Concrete implementation of RelationalStoreBase using PostgreSQL.
Source code in src/aeiva/storage/postgresql/postgresql_database.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
|
__init__(config)
Initialize the PostgreSQL database connection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Dict[str, Any]
|
Configuration dictionary. |
required |
Source code in src/aeiva/storage/postgresql/postgresql_database.py
24 25 26 27 28 29 30 31 32 33 34 |
|
begin_transaction()
Begins a transaction.
Source code in src/aeiva/storage/postgresql/postgresql_database.py
230 231 232 233 234 |
|
close()
Closes the database connection and releases resources.
Source code in src/aeiva/storage/postgresql/postgresql_database.py
53 54 55 56 57 58 59 60 |
|
commit_transaction()
Commits the current transaction.
Source code in src/aeiva/storage/postgresql/postgresql_database.py
236 237 238 239 240 241 |
|
connect()
Establishes a connection to the PostgreSQL database.
Source code in src/aeiva/storage/postgresql/postgresql_database.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
delete_record(table, primary_key)
Deletes a record from a table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table
|
str
|
The name of the table. |
required |
primary_key
|
Any
|
The primary key of the record. |
required |
Raises:
Type | Description |
---|---|
RecordNotFoundError
|
If the record does not exist. |
StorageError
|
If there is an issue deleting the record. |
Source code in src/aeiva/storage/postgresql/postgresql_database.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
|
execute_sql(query, parameters=None)
Executes a raw SQL query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
The SQL query string. |
required |
parameters
|
Optional[Dict[str, Any]]
|
Parameters for parameterized queries. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The result of the query. |
Raises:
Type | Description |
---|---|
StorageError
|
If there is an issue executing the query. |
Source code in src/aeiva/storage/postgresql/postgresql_database.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
|
get_record(table, primary_key)
Retrieves a record by its primary key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table
|
str
|
The name of the table. |
required |
primary_key
|
Any
|
The primary key of the record. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: The retrieved record. |
Raises:
Type | Description |
---|---|
RecordNotFoundError
|
If the record does not exist. |
StorageError
|
If there is an issue retrieving the record. |
Source code in src/aeiva/storage/postgresql/postgresql_database.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
insert_record(table, record)
Inserts a record into a table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table
|
str
|
The name of the table. |
required |
record
|
Dict[str, Any]
|
A dictionary representing the record to insert. |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The primary key of the inserted record. |
Raises:
Type | Description |
---|---|
StorageError
|
If there is an issue inserting the record. |
Source code in src/aeiva/storage/postgresql/postgresql_database.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
query_records(table, conditions=None, limit=None, offset=None)
Queries records from a table based on conditions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table
|
str
|
The name of the table. |
required |
conditions
|
Optional[Dict[str, Any]]
|
Conditions to filter records. |
None
|
limit
|
Optional[int]
|
Maximum number of records to return. |
None
|
offset
|
Optional[int]
|
Number of records to skip. |
None
|
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of records matching the query. |
Raises:
Type | Description |
---|---|
StorageError
|
If there is an issue querying records. |
Source code in src/aeiva/storage/postgresql/postgresql_database.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
|
rollback_transaction()
Rolls back the current transaction.
Source code in src/aeiva/storage/postgresql/postgresql_database.py
243 244 245 246 247 248 |
|
update_record(table, primary_key, updates)
Updates a record in a table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table
|
str
|
The name of the table. |
required |
primary_key
|
Any
|
The primary key of the record. |
required |
updates
|
Dict[str, Any]
|
A dictionary of fields to update. |
required |
Raises:
Type | Description |
---|---|
RecordNotFoundError
|
If the record does not exist. |
StorageError
|
If there is an issue updating the record. |
Source code in src/aeiva/storage/postgresql/postgresql_database.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
RecordNotFoundError
Bases: Exception
Exception raised when a record is not found in the database.
Source code in src/aeiva/storage/postgresql/postgresql_database.py
9 10 11 |
|
StorageError
Bases: Exception
Exception raised when there is a storage-related error in the database.
Source code in src/aeiva/storage/postgresql/postgresql_database.py
14 15 16 |
|
test
RecordNotFoundError
Bases: Exception
Exception raised when a record is not found in the database.
Source code in src/aeiva/storage/postgresql/test.py
8 9 10 |
|
qdrant
qdrant_config
QdrantConfig
dataclass
Bases: BaseConfig
Configuration for Qdrant vector database.
Source code in src/aeiva/storage/qdrant/qdrant_config.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
qdrant_database
QdrantDatabase
Bases: VectorDatabase
Concrete implementation of VectorStoreBase using Qdrant.
Source code in src/aeiva/storage/qdrant/qdrant_database.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
|
__init__(config)
Initialize the Qdrant vector store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Dict[str, Any]
|
Configuration dictionary. |
required |
Source code in src/aeiva/storage/qdrant/qdrant_database.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
create_client(**kwargs)
Initializes the client connection to the Qdrant vector store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Additional parameters. |
{}
|
Source code in src/aeiva/storage/qdrant/qdrant_database.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
create_collection(collection_name, vector_size, distance_metric)
Create a new vector collection in Qdrant.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
vector_size
|
int
|
The dimensionality of the vectors. |
required |
distance_metric
|
str
|
The distance metric to use (e.g., 'COSINE'). |
required |
Source code in src/aeiva/storage/qdrant/qdrant_database.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
delete_collection(collection_name)
Delete an entire vector collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection to delete. |
required |
Source code in src/aeiva/storage/qdrant/qdrant_database.py
293 294 295 296 297 298 299 300 301 |
|
delete_vector(collection_name, vector_id)
Delete a vector from a collection by its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
vector_id
|
str
|
The unique identifier of the vector to delete. |
required |
Source code in src/aeiva/storage/qdrant/qdrant_database.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
|
get_collection_info(collection_name)
Get information about a collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: Information about the collection. |
Source code in src/aeiva/storage/qdrant/qdrant_database.py
303 304 305 306 307 308 309 310 311 312 313 314 |
|
get_vector(collection_name, vector_id)
Retrieve a vector by its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
vector_id
|
str
|
The unique identifier of the vector. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary containing the vector data and payload. |
Source code in src/aeiva/storage/qdrant/qdrant_database.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
|
insert_vectors(collection_name, vectors, payloads=None, ids=None)
Insert vectors into a collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
vectors
|
List[List[float]]
|
A list of vectors to insert. |
required |
payloads
|
Optional[List[Dict[str, Any]]]
|
Optional metadata associated with each vector. |
None
|
ids
|
Optional[List[str]]
|
Optional unique identifiers for each vector. |
None
|
Source code in src/aeiva/storage/qdrant/qdrant_database.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
|
list_collections()
List all available vector collections.
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: A list of collection names. |
Source code in src/aeiva/storage/qdrant/qdrant_database.py
283 284 285 286 287 288 289 290 291 |
|
search_vectors(collection_name, query_vector, top_k=5, filters=None)
Search for similar vectors in a collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
query_vector
|
List[float]
|
The vector to search with. |
required |
top_k
|
int
|
The number of top results to return. |
5
|
filters
|
Optional[Dict[str, Any]]
|
Optional filters to apply to the search. |
None
|
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of search results. |
Source code in src/aeiva/storage/qdrant/qdrant_database.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
|
update_vector(collection_name, vector_id, vector=None, payload=None)
Update a vector's data or payload.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
vector_id
|
str
|
The unique identifier of the vector to update. |
required |
vector
|
Optional[List[float]]
|
The new vector data. |
None
|
payload
|
Optional[Dict[str, Any]]
|
The new payload data. |
None
|
Source code in src/aeiva/storage/qdrant/qdrant_database.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
|
relational_database
RelationalDatabase
Bases: ABC
Abstract base class for relational database operations.
Source code in src/aeiva/storage/relational_database.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
begin_transaction()
abstractmethod
Begins a transaction.
Source code in src/aeiva/storage/relational_database.py
112 113 114 115 116 117 |
|
close()
abstractmethod
Closes the database connection and releases resources.
Source code in src/aeiva/storage/relational_database.py
133 134 135 136 137 138 |
|
commit_transaction()
abstractmethod
Commits the current transaction.
Source code in src/aeiva/storage/relational_database.py
119 120 121 122 123 124 |
|
delete_record(table, primary_key)
abstractmethod
Deletes a record from a table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table
|
str
|
The name of the table. |
required |
primary_key
|
Any
|
The primary key of the record. |
required |
Raises:
Type | Description |
---|---|
RecordNotFoundError
|
If the record does not exist. |
StorageError
|
If there is an issue deleting the record. |
Source code in src/aeiva/storage/relational_database.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
|
execute_sql(query, parameters=None)
abstractmethod
Executes a raw SQL query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
The SQL query string. |
required |
parameters
|
Optional[Dict[str, Any]]
|
Parameters for parameterized queries. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The result of the query. |
Raises:
Type | Description |
---|---|
StorageError
|
If there is an issue executing the query. |
Source code in src/aeiva/storage/relational_database.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
get_record(table, primary_key)
abstractmethod
Retrieves a record by its primary key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table
|
str
|
The name of the table. |
required |
primary_key
|
Any
|
The primary key of the record. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: The retrieved record. |
Raises:
Type | Description |
---|---|
RecordNotFoundError
|
If the record does not exist. |
StorageError
|
If there is an issue retrieving the record. |
Source code in src/aeiva/storage/relational_database.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
insert_record(table, record)
abstractmethod
Inserts a record into a table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table
|
str
|
The name of the table. |
required |
record
|
Dict[str, Any]
|
A dictionary representing the record to insert. |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The primary key of the inserted record. |
Raises:
Type | Description |
---|---|
StorageError
|
If there is an issue inserting the record. |
Source code in src/aeiva/storage/relational_database.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
query_records(table, conditions=None, limit=None, offset=None)
abstractmethod
Queries records from a table based on conditions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table
|
str
|
The name of the table. |
required |
conditions
|
Optional[Dict[str, Any]]
|
Conditions to filter records. |
None
|
limit
|
Optional[int]
|
Maximum number of records to return. |
None
|
offset
|
Optional[int]
|
Number of records to skip. |
None
|
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of records matching the query. |
Raises:
Type | Description |
---|---|
StorageError
|
If there is an issue querying records. |
Source code in src/aeiva/storage/relational_database.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
rollback_transaction()
abstractmethod
Rolls back the current transaction.
Source code in src/aeiva/storage/relational_database.py
126 127 128 129 130 131 |
|
update_record(table, primary_key, updates)
abstractmethod
Updates a record in a table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table
|
str
|
The name of the table. |
required |
primary_key
|
Any
|
The primary key of the record. |
required |
updates
|
Dict[str, Any]
|
A dictionary of fields to update. |
required |
Raises:
Type | Description |
---|---|
RecordNotFoundError
|
If the record does not exist. |
StorageError
|
If there is an issue updating the record. |
Source code in src/aeiva/storage/relational_database.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
sqlite
sqlite_config
SQLiteConfig
dataclass
Bases: BaseConfig
Configuration for SQLite database.
Source code in src/aeiva/storage/sqlite/sqlite_config.py
7 8 9 10 11 12 13 14 15 |
|
sqlite_database
RecordNotFoundError
Bases: Exception
Exception raised when a record is not found in the database.
Source code in src/aeiva/storage/sqlite/sqlite_database.py
8 9 10 |
|
SQLiteDatabase
Bases: RelationalDatabase
Concrete implementation of RelationalStoreBase using SQLite.
Source code in src/aeiva/storage/sqlite/sqlite_database.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
|
__init__(config)
Initialize the SQLite database connection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Dict[str, Any]
|
Configuration dictionary. |
required |
Source code in src/aeiva/storage/sqlite/sqlite_database.py
23 24 25 26 27 28 29 30 31 32 33 34 |
|
begin_transaction()
Begins a transaction.
Source code in src/aeiva/storage/sqlite/sqlite_database.py
226 227 228 229 230 231 |
|
close()
Closes the database connection and releases resources.
Source code in src/aeiva/storage/sqlite/sqlite_database.py
48 49 50 51 52 53 54 55 |
|
commit_transaction()
Commits the current transaction.
Source code in src/aeiva/storage/sqlite/sqlite_database.py
233 234 235 236 237 238 |
|
connect()
Establishes a connection to the SQLite database.
Source code in src/aeiva/storage/sqlite/sqlite_database.py
36 37 38 39 40 41 42 43 44 45 46 |
|
delete_record(table, primary_key)
Deletes a record from a table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table
|
str
|
The name of the table. |
required |
primary_key
|
Any
|
The primary key of the record. |
required |
Raises:
Type | Description |
---|---|
RecordNotFoundError
|
If the record does not exist. |
StorageError
|
If there is an issue deleting the record. |
Source code in src/aeiva/storage/sqlite/sqlite_database.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
execute_sql(query, params=None)
Executes a SQL query and returns the cursor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
The SQL query to execute. |
required |
params
|
Optional[Tuple]
|
Parameters to substitute into the query. |
None
|
Returns:
Type | Description |
---|---|
sqlite3.Cursor: The cursor after executing the query. |
Source code in src/aeiva/storage/sqlite/sqlite_database.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
get_record(table, primary_key)
Retrieves a record by its primary key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table
|
str
|
The name of the table. |
required |
primary_key
|
Any
|
The primary key of the record. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: The retrieved record. |
Raises:
Type | Description |
---|---|
RecordNotFoundError
|
If the record does not exist. |
StorageError
|
If there is an issue retrieving the record. |
Source code in src/aeiva/storage/sqlite/sqlite_database.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
insert_record(table, record)
Inserts a record into a table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table
|
str
|
The name of the table. |
required |
record
|
Dict[str, Any]
|
A dictionary representing the record to insert. |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The primary key of the inserted record. |
Raises:
Type | Description |
---|---|
StorageError
|
If there is an issue inserting the record. |
Source code in src/aeiva/storage/sqlite/sqlite_database.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
query_records(table, conditions=None, limit=None, offset=None)
Queries records from a table based on conditions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table
|
str
|
The name of the table. |
required |
conditions
|
Optional[Dict[str, Any]]
|
Conditions to filter records. |
None
|
limit
|
Optional[int]
|
Maximum number of records to return. |
None
|
offset
|
Optional[int]
|
Number of records to skip. |
None
|
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of records matching the query. |
Raises:
Type | Description |
---|---|
StorageError
|
If there is an issue querying records. |
Source code in src/aeiva/storage/sqlite/sqlite_database.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
rollback_transaction()
Rolls back the current transaction.
Source code in src/aeiva/storage/sqlite/sqlite_database.py
240 241 242 243 244 245 |
|
update_record(table, primary_key, updates)
Updates a record in a table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table
|
str
|
The name of the table. |
required |
primary_key
|
Any
|
The primary key of the record. |
required |
updates
|
Dict[str, Any]
|
A dictionary of fields to update. |
required |
Raises:
Type | Description |
---|---|
RecordNotFoundError
|
If the record does not exist. |
StorageError
|
If there is an issue updating the record. |
Source code in src/aeiva/storage/sqlite/sqlite_database.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|
StorageError
Bases: Exception
Exception raised when there is a storage-related error in the database.
Source code in src/aeiva/storage/sqlite/sqlite_database.py
13 14 15 |
|
test
RecordNotFoundError
Bases: Exception
Exception raised when a record is not found in the database.
Source code in src/aeiva/storage/sqlite/test.py
9 10 11 |
|
test
main()
Main function to run tests for Milvus, Neo4j, and SQLite databases.
Source code in src/aeiva/storage/test.py
179 180 181 182 183 184 185 |
|
test_milvus()
Test the DatabaseFactory and DatabaseConfigFactory with Milvus database.
Source code in src/aeiva/storage/test.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
test_neo4j()
Test the DatabaseFactory and DatabaseConfigFactory with Neo4j database.
Source code in src/aeiva/storage/test.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
test_sqlite()
Test the DatabaseFactory and DatabaseConfigFactory with SQLite database.
Source code in src/aeiva/storage/test.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
|
vector_database
VectorDatabase
Bases: ABC
Abstract base class for vector storage operations.
Source code in src/aeiva/storage/vector_database.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
|
create_client(uri, user=None, password=None, db_name=None, token=None, timeout=None, **kwargs)
abstractmethod
Initializes the client connection to the vector store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri
|
str
|
The URI of the vector store instance. |
required |
user
|
Optional[str]
|
Username for authentication. |
None
|
password
|
Optional[str]
|
Password for authentication. |
None
|
db_name
|
Optional[str]
|
Name of the database. |
None
|
token
|
Optional[str]
|
Access token for authentication. |
None
|
timeout
|
Optional[float]
|
Timeout duration for operations. |
None
|
**kwargs
|
Additional implementation-specific parameters. |
{}
|
Raises:
Type | Description |
---|---|
ConnectionError
|
If the client fails to connect to the vector store. |
Source code in src/aeiva/storage/vector_database.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
create_collection(collection_name, vector_size, distance_metric)
abstractmethod
Create a new vector collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
vector_size
|
int
|
The dimensionality of the vectors. |
required |
distance_metric
|
str
|
The distance metric to use (e.g., 'euclidean', 'cosine'). |
required |
Raises:
Type | Description |
---|---|
CollectionAlreadyExistsError
|
If a collection with the given name already exists. |
StorageError
|
If there is an issue creating the collection. |
Source code in src/aeiva/storage/vector_database.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
delete_collection(collection_name)
abstractmethod
Delete an entire vector collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection to delete. |
required |
Raises:
Type | Description |
---|---|
CollectionNotFoundError
|
If the specified collection does not exist. |
StorageError
|
If there is an issue deleting the collection. |
Source code in src/aeiva/storage/vector_database.py
156 157 158 159 160 161 162 163 164 165 166 167 168 |
|
delete_vector(collection_name, vector_id)
abstractmethod
Delete a vector from a collection by its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
vector_id
|
str
|
The unique identifier of the vector to delete. |
required |
Raises:
Type | Description |
---|---|
CollectionNotFoundError
|
If the specified collection does not exist. |
VectorNotFoundError
|
If the vector with the specified ID does not exist. |
StorageError
|
If there is an issue deleting the vector. |
Source code in src/aeiva/storage/vector_database.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
get_collection_info(collection_name)
abstractmethod
Get information about a collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: Information about the collection, such as vector size and distance metric. |
Raises:
Type | Description |
---|---|
CollectionNotFoundError
|
If the specified collection does not exist. |
StorageError
|
If there is an issue retrieving the collection information. |
Source code in src/aeiva/storage/vector_database.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
|
get_vector(collection_name, vector_id)
abstractmethod
Retrieve a vector by its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
vector_id
|
str
|
The unique identifier of the vector. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary containing the vector data and payload. |
Raises:
Type | Description |
---|---|
CollectionNotFoundError
|
If the specified collection does not exist. |
VectorNotFoundError
|
If the vector with the specified ID does not exist. |
StorageError
|
If there is an issue retrieving the vector. |
Source code in src/aeiva/storage/vector_database.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
|
insert_vectors(collection_name, vectors, payloads=None, ids=None)
abstractmethod
Insert vectors into a collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
vectors
|
List[List[float]]
|
A list of vectors to insert. |
required |
payloads
|
Optional[List[Dict[str, Any]]]
|
Optional metadata associated with each vector. |
None
|
ids
|
Optional[List[str]]
|
Optional unique identifiers for each vector. |
None
|
Raises:
Type | Description |
---|---|
CollectionNotFoundError
|
If the specified collection does not exist. |
StorageError
|
If there is an issue inserting the vectors. |
Source code in src/aeiva/storage/vector_database.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
list_collections()
abstractmethod
List all available vector collections.
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: A list of collection names. |
Raises:
Type | Description |
---|---|
StorageError
|
If there is an issue retrieving the collection list. |
Source code in src/aeiva/storage/vector_database.py
143 144 145 146 147 148 149 150 151 152 153 154 |
|
search_vectors(collection_name, query_vector, top_k=5, filters=None)
abstractmethod
Search for similar vectors in a collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
query_vector
|
List[float]
|
The vector to search with. |
required |
top_k
|
int
|
The number of top results to return. |
5
|
filters
|
Optional[Dict[str, Any]]
|
Optional filters to apply to the search. |
None
|
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of search results, each containing the vector ID, score, and payload. |
Raises:
Type | Description |
---|---|
CollectionNotFoundError
|
If the specified collection does not exist. |
StorageError
|
If there is an issue performing the search. |
Source code in src/aeiva/storage/vector_database.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
update_vector(collection_name, vector_id, vector=None, payload=None)
abstractmethod
Update a vector's data or payload.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
required |
vector_id
|
str
|
The unique identifier of the vector to update. |
required |
vector
|
Optional[List[float]]
|
The new vector data. |
None
|
payload
|
Optional[Dict[str, Any]]
|
The new payload data. |
None
|
Raises:
Type | Description |
---|---|
CollectionNotFoundError
|
If the specified collection does not exist. |
VectorNotFoundError
|
If the vector with the specified ID does not exist. |
StorageError
|
If there is an issue updating the vector. |
Source code in src/aeiva/storage/vector_database.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
weaviate
weaviate_config
WeaviateConfig
dataclass
Bases: BaseConfig
Configuration for Weaviate vector database.
Source code in src/aeiva/storage/weaviate/weaviate_config.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
weaviate_database
WeaviateDatabase
Bases: VectorDatabase
Concrete implementation of VectorStoreBase using Weaviate.
Source code in src/aeiva/storage/weaviate/weaviate_database.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 |
|
__del__()
Clean up resources.
Source code in src/aeiva/storage/weaviate/weaviate_database.py
412 413 414 415 416 |
|
__init__(config)
Initialize the Weaviate vector store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Dict[str, Any]
|
Configuration dictionary. |
required |
Source code in src/aeiva/storage/weaviate/weaviate_database.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
create_client()
Initializes the client connection to the Weaviate vector store.
Returns:
Name | Type | Description |
---|---|---|
Client |
Client
|
The Weaviate client instance. |
Raises:
Type | Description |
---|---|
ConnectionError
|
If the client fails to connect to the Weaviate instance. |
Source code in src/aeiva/storage/weaviate/weaviate_database.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
|
create_index(index_name, vector_dim, distance_metric)
Create a new index (class) in Weaviate.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index_name
|
str
|
The name of the index. |
required |
vector_dim
|
int
|
The dimensionality of the vectors. |
required |
distance_metric
|
str
|
The distance metric to use. |
required |
Raises:
Type | Description |
---|---|
WeaviateException
|
If there is an issue creating the index. |
Source code in src/aeiva/storage/weaviate/weaviate_database.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
delete_collection(collection_name)
Delete an entire index (class).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection (index) to delete. |
required |
Raises:
Type | Description |
---|---|
WeaviateException
|
If there is an issue deleting the collection. |
Source code in src/aeiva/storage/weaviate/weaviate_database.py
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
|
delete_vector(collection_name, vector_id)
Delete a vector from the collection by its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection (index). |
required |
vector_id
|
str
|
The unique identifier of the vector to delete. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If collection name does not match. |
WeaviateException
|
If there is an issue deleting the vector. |
Source code in src/aeiva/storage/weaviate/weaviate_database.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
|
get_collection_info(collection_name)
Get information about a collection (index).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection (index). |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: Information about the collection. |
Raises:
Type | Description |
---|---|
WeaviateException
|
If there is an issue retrieving the collection info. |
Source code in src/aeiva/storage/weaviate/weaviate_database.py
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
|
get_vector(collection_name, vector_id)
Retrieve a vector by its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection (index). |
required |
vector_id
|
str
|
The unique identifier of the vector. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary containing the vector data and payload. |
Raises:
Type | Description |
---|---|
ValueError
|
If collection name does not match. |
KeyError
|
If the vector is not found. |
WeaviateException
|
If there is an issue retrieving the vector. |
Source code in src/aeiva/storage/weaviate/weaviate_database.py
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
|
insert_vectors(collection_name, vectors, payloads=None, ids=None)
Insert vectors into the collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection (index). |
required |
vectors
|
List[List[float]]
|
A list of vectors to insert. |
required |
payloads
|
Optional[List[Dict[str, Any]]]
|
Optional metadata associated with each vector. |
None
|
ids
|
Optional[List[str]]
|
Optional unique identifiers for each vector. |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
If input data is invalid. |
WeaviateException
|
If there is an issue inserting vectors. |
Source code in src/aeiva/storage/weaviate/weaviate_database.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
list_collections()
List all available indexes (classes).
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: A list of index names. |
Source code in src/aeiva/storage/weaviate/weaviate_database.py
361 362 363 364 365 366 367 368 369 370 371 372 373 |
|
search_vectors(collection_name, query_vector, top_k=5, filters=None)
Search for similar vectors in the collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection (index). |
required |
query_vector
|
List[float]
|
The vector to search with. |
required |
top_k
|
int
|
The number of top results to return. |
5
|
filters
|
Optional[Dict[str, Any]]
|
Optional filters to apply to the search. |
None
|
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of search results. |
Raises:
Type | Description |
---|---|
ValueError
|
If collection name does not match. |
WeaviateException
|
If there is an issue performing the search. |
Source code in src/aeiva/storage/weaviate/weaviate_database.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
|
update_vector(collection_name, vector_id, vector=None, payload=None)
Update a vector's data or payload.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection (index). |
required |
vector_id
|
str
|
The unique identifier of the vector to update. |
required |
vector
|
Optional[List[float]]
|
The new vector data. |
None
|
payload
|
Optional[Dict[str, Any]]
|
The new payload data. |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
If collection name does not match. |
WeaviateException
|
If there is an issue updating the vector. |
Source code in src/aeiva/storage/weaviate/weaviate_database.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
|
tool
api_server
call_api_action(api_name, action_name, request)
async
Endpoint to dynamically call an action within a specified API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
api_name
|
str
|
The name of the API. |
required |
action_name
|
str
|
The name of the action/function to execute. |
required |
request
|
Request
|
The incoming HTTP request. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
The result of the action or an error message. |
Source code in src/aeiva/tool/api_server.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
load_api_module(api_name)
Dynamically load the API module for the given api_name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
api_name
|
str
|
The name of the API. |
required |
Returns:
Name | Type | Description |
---|---|---|
module |
The loaded API module. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the API module does not exist. |
ImportError
|
If the module cannot be imported. |
Source code in src/aeiva/tool/api_server.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
root()
async
Root endpoint to confirm the API server is running.
Source code in src/aeiva/tool/api_server.py
55 56 57 58 59 60 |
|
tool
Tool
Source code in src/aeiva/tool/tool.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
__init__(api_name)
Initialize the tool, determining whether it should run locally or via an external service. Args: api_name (str): The name of the tool API (matches the function name).
Source code in src/aeiva/tool/tool.py
12 13 14 15 16 17 18 19 |
|
aexecute(params)
async
Execute the tool by calling the corresponding function (whether it's for a local function or encapsulated API call). Args: params (dict): Parameters to pass to the tool. Returns: Any: The result of the tool execution.
Source code in src/aeiva/tool/tool.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
execute(params)
Execute the tool synchronously by calling the corresponding function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params
|
dict
|
Parameters to pass to the tool. |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The result of the tool execution. |
Source code in src/aeiva/tool/tool.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
load_tool_schema(api_name)
classmethod
Load the tool's schema from the JSON file. Args: api_name (str): The name of the API or function. Returns: dict: The loaded schema from the JSON file.
Source code in src/aeiva/tool/tool.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
toolkit
arxiv_toolkit
ArxivToolkit
Bases: Toolkit
A toolkit for interacting with the arXiv API.
Source code in src/aeiva/tool/toolkit/arxiv_toolkit.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
auto_ui_toolkit
AutoUIToolkit
Bases: Toolkit
A toolkit for automating GUI interactions.
Source code in src/aeiva/tool/toolkit/auto_ui_toolkit.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
docx_toolkit
DocxToolkit
Bases: Toolkit
A toolkit for interacting with Docx files.
Source code in src/aeiva/tool/toolkit/docx_toolkit.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
file_toolkit
FileToolkit
Bases: Toolkit
A toolkit for file-related operations.
Source code in src/aeiva/tool/toolkit/file_toolkit.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
git_toolkit
GitToolkit
Bases: Toolkit
A toolkit for interacting with Git repositories.
Source code in src/aeiva/tool/toolkit/git_toolkit.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
math_toolkit
MathToolkit
Bases: Toolkit
A toolkit for mathematical operations.
Source code in src/aeiva/tool/toolkit/math_toolkit.py
5 6 7 8 9 10 11 12 13 14 15 |
|
pdf_toolkit
PdfToolkit
Bases: Toolkit
A toolkit for interacting with PDF files.
Source code in src/aeiva/tool/toolkit/pdf_toolkit.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
rbac
PermissionError
Bases: Exception
Custom exception for permission-related errors.
Source code in src/aeiva/tool/toolkit/rbac.py
6 7 8 |
|
check_permission(user_role, api_name, config)
Check if the user_role has permission to execute the given api_name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user_role
|
str
|
The role of the user. |
required |
api_name
|
str
|
The name of the API function. |
required |
config
|
ToolkitConfig
|
The toolkit configuration containing role permissions. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if permitted, False otherwise. |
Raises:
Type | Description |
---|---|
PermissionError
|
If the user does not have the required permission. |
Source code in src/aeiva/tool/toolkit/rbac.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
security
sanitize_file_path(file_path, config)
Sanitize the file path to prevent directory traversal attacks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str
|
The input file path. |
required |
config
|
ToolkitConfig
|
The configuration instance. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The sanitized absolute file path. |
Raises:
Type | Description |
---|---|
ValueError
|
If the file path is not within allowed directories. |
Source code in src/aeiva/tool/toolkit/security.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
shell_toolkit
ShellToolkit
Bases: Toolkit
A toolkit for shell and terminal operations.
Source code in src/aeiva/tool/toolkit/shell_toolkit.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
system_toolkit
SystemToolkit
Bases: Toolkit
A toolkit for interacting with system-level operations.
Source code in src/aeiva/tool/toolkit/system_toolkit.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|
toolkit
Toolkit
Toolkit class that manages multiple Tool instances, handles validation, enforces RBAC, and manages shared resources.
Source code in src/aeiva/tool/toolkit/toolkit.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
|
__init__(name, tool_names, config=None)
Initialize the Toolkit with a name, list of tool names, and optional configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the toolkit. |
required |
tool_names
|
List[str]
|
The names of tools to be managed by the toolkit. |
required |
config
|
Optional[ToolkitConfig]
|
Configuration for security and roles. |
None
|
Source code in src/aeiva/tool/toolkit/toolkit.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
__init_subclass__(**kwargs)
Automatically register subclasses in the Toolkit's subclasses dictionary.
Source code in src/aeiva/tool/toolkit/toolkit.py
31 32 33 34 35 36 |
|
acontext()
async
Asynchronous context manager to handle setup and teardown of shared resources.
Usage
async with toolkit.acontent(): # Execute tools
Source code in src/aeiva/tool/toolkit/toolkit.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
aexecute(api_name, params)
async
Asynchronously execute a tool's API function with validation and RBAC checks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
api_name
|
str
|
The name of the API function to execute. |
required |
params
|
Dict[str, Any]
|
The parameters for the API function. |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The result of the tool execution. |
Raises:
Type | Description |
---|---|
ValueError
|
If tool not found or parameter validation fails. |
PermissionError
|
If user does not have permission. |
RuntimeError
|
If tool execution fails. |
Source code in src/aeiva/tool/toolkit/toolkit.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
|
asetup()
async
Asynchronously setup shared resources.
Source code in src/aeiva/tool/toolkit/toolkit.py
191 192 193 194 195 196 197 |
|
ateardown()
async
Asynchronously teardown shared resources.
Source code in src/aeiva/tool/toolkit/toolkit.py
199 200 201 202 203 204 205 |
|
context()
Synchronous context manager to handle setup and teardown of shared resources.
Usage
with toolkit.context(): # Execute tools
Source code in src/aeiva/tool/toolkit/toolkit.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
|
execute(api_name, params)
Synchronously execute a tool's API function with validation and RBAC checks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
api_name
|
str
|
The name of the API function to execute. |
required |
params
|
Dict[str, Any]
|
The parameters for the API function. |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The result of the tool execution. |
Raises:
Type | Description |
---|---|
ValueError
|
If tool not found or parameter validation fails. |
PermissionError
|
If user does not have permission. |
RuntimeError
|
If tool execution fails. |
Source code in src/aeiva/tool/toolkit/toolkit.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
|
generate_documentation()
Generate documentation for all functions managed by this toolkit based on their schemas.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Generated documentation as a markdown string. |
Source code in src/aeiva/tool/toolkit/toolkit.py
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
|
init_shared_resources()
Initialize shared resources required by the toolkit. Override this method in subclasses if needed.
Source code in src/aeiva/tool/toolkit/toolkit.py
124 125 126 127 128 129 130 131 132 133 |
|
load_pydantic_models_for_all_tools()
Load Pydantic models (Params and Result) for all tools for validation.
Source code in src/aeiva/tool/toolkit/toolkit.py
78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
load_pydantic_models_for_tool(api_name)
Load the parameter and result Pydantic models for the given API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
api_name
|
str
|
The name of the API function. |
required |
Returns:
Type | Description |
---|---|
Tuple[Type[BaseModel], Type[BaseModel]]
|
Tuple[Type[BaseModel], Type[BaseModel]]: The parameter and result model classes. |
Raises:
Type | Description |
---|---|
ValueError
|
If models cannot be loaded. |
Source code in src/aeiva/tool/toolkit/toolkit.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
perform_security_checks(param_instance)
Perform security checks on parameters that require sanitization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
param_instance
|
BaseModel
|
The validated parameter instance. |
required |
Returns:
Name | Type | Description |
---|---|---|
BaseModel |
BaseModel
|
The sanitized parameter instance. |
Raises:
Type | Description |
---|---|
ValueError
|
If sanitization fails for any field or if config is required but not provided. |
Source code in src/aeiva/tool/toolkit/toolkit.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 |
|
setup()
Setup the toolkit by loading tools, their schemas, and initializing shared resources.
Source code in src/aeiva/tool/toolkit/toolkit.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
teardown()
Teardown the toolkit by unloading tools, their schemas, and cleaning up shared resources.
Source code in src/aeiva/tool/toolkit/toolkit.py
135 136 137 138 139 140 141 142 143 144 145 146 147 |
|
teardown_shared_resources()
Teardown shared resources. Override this method in subclasses if needed.
Source code in src/aeiva/tool/toolkit/toolkit.py
149 150 151 152 153 154 155 156 157 158 159 |
|
toolkit_config
ToolkitConfig
dataclass
Bases: BaseConfig
Configuration for the Toolkit.
Source code in src/aeiva/tool/toolkit/toolkit_config.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
web_toolkit
WebToolkit
Bases: Toolkit
A toolkit for interacting with web pages.
Source code in src/aeiva/tool/toolkit/web_toolkit.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
trainer
pl_trainer
LightningTrainer
Bases: LightningModule
Source code in src/aeiva/trainer/pl_trainer.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
|
configure_optimizers()
Function to prepare the optimizer and learning rate scheduler for model training. This function separates model parameters into two categories: parameters that will experience weight decay, and those that will not (e.g., bias and layernorm weights).
Returns:
Type | Description |
---|---|
Tuple[Optimizer, Scheduler]: Tuple containing the optimizer and learning rate scheduler. |
Source code in src/aeiva/trainer/pl_trainer.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
|
estimate_mfu(fwdbwd_per_iter, dt)
estimate model flops utilization (MFU) in units of A100 bfloat16 peak FLOPS
Source code in src/aeiva/trainer/pl_trainer.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
|
get_num_params(non_embedding=True)
Return the number of parameters in the model. For non-embedding count (default), the position embeddings get subtracted. The token embeddings would too, except due to the parameter sharing these params are actually used as weights in the final layer, so we include them.
Source code in src/aeiva/trainer/pl_trainer.py
137 138 139 140 141 142 143 144 145 146 147 148 |
|
util
file_utils
from_json_or_yaml(filepath)
Load configuration from a JSON or YAML file based on the file extension.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath
|
str
|
The path to the configuration file. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
The configuration dictionary. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the file does not exist. |
ValueError
|
If the file extension is unsupported or if parsing fails. |
Source code in src/aeiva/util/file_utils.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
os_utils
get_os_user()
Retrieve the current OS username.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The current OS user's name. |
Source code in src/aeiva/util/os_utils.py
4 5 6 7 8 9 10 11 |
|
path_utils
get_package_root(package_name)
Obtain the root directory of a given package.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
package_name
|
str
|
The name of the package. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The absolute path to the package root directory. |
Source code in src/aeiva/util/path_utils.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
get_user_home_path()
Retrieves the home directory of the current user across different platforms.
Supported Platforms
- Windows
- macOS
- Linux
- iOS (best-effort)
- Android (best-effort)
Returns:
Name | Type | Description |
---|---|---|
Path |
Path
|
A |
Raises:
Type | Description |
---|---|
EnvironmentError
|
If the home directory cannot be determined. |
Source code in src/aeiva/util/path_utils.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
snake_to_camel(snake_str)
Convert a snake_case string to CamelCase.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
snake_str
|
str
|
The snake_case string. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The CamelCase string. |
Source code in src/aeiva/util/path_utils.py
85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
token_utils
pad_or_truncate_tokens(tokens, max_length, pad_token_id)
This function aims to pad or truncate tokens to max_length.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tokens
|
list
|
the list of tokens. |
required |
max_length
|
int
|
the max length of tokens. |
required |
pad_token_id
|
int
|
the id of pad token. |
required |
Returns:
Name | Type | Description |
---|---|---|
tokens |
list
|
the list of tokens after padding or truncating. |
Source code in src/aeiva/util/token_utils.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|