KB Ops
Provides utilities for higher level operations on KnowledgeBases
- ia.gaius.kb_ops.get_kb_subset(agent: AgentClient, model_dict: dict)
Retrieve a subset of a Knowledgebase based on the provided model_dict. Will only provide used symbols and vectors, all others will be trimmed.
- Parameters:
agent (AgentClient) – GAIuS Agent
model_dict (dict) – {node_name: model_list}. Expected format is similar to that returned from
list_models()
- Raises:
e – Exception in subset iteration (e.g. model not found on node, get_kb failed, etc.)
- Returns:
Subset of Knowledgebases corresponding to provided model_dict
- Return type:
dict
Example
from ia.gaius.kb_ops import get_kb_subset, list_models from ia.gaius.agent_client import AgentClient agent = AgentClient(agent_info) agent.connect() models = list_models(agent=agent, nodes=['P1']) # get a subset of available models models = {k: v[:20] for k,v in models.items()} # get a subset of the entire Knowledgebase kb_subset = get_kb_subset(agent=agent, model_dict=models)
- ia.gaius.kb_ops.get_models_containing_symbol(agent: AgentClient, symbol_set: set, nodes=None)
Checks for presence of symbols from symbol_set in each model on nodes, adding to return dict if a symbol is found.
- Parameters:
agent (AgentClient) – GAIuS Agent
symbol (str) – the symbol to search for
nodes (_type_, optional) – nodes to search. Defaults to searching all nodes
Example
from ia.gaius.agent_client import AgentClient from ia.gaius.kb_ops import get_models_containing_symbol symbols = ["world"] agent = AgentClient(agent_info) output = get_models_containing_symbol(agent=agent, symbol_set=set(symbols))
- ia.gaius.kb_ops.get_models_containing_symbol_strict(agent: AgentClient, symbol_set: set, nodes=None)
Checks for presence of symbols from symbol_set in each model on nodes. Only adds model to return dict if all symbols in model are from symbol set Store as a dict of {node_name : list}
- Parameters:
agent (AgentClient) – GAIuS Agent
symbol (str) – the symbol to search for
nodes (_type_, optional) – nodes to search. Defaults to searching all nodes
Example
from ia.gaius.agent_client import AgentClient from ia.gaius.kb_ops import get_models_containing_symbol_strict symbols = ["hello", "world", "goodbye", "cruel"] agent = AgentClient(agent_info) output = get_models_containing_symbol_strict(agent=agent, symbol_set=set(symbols))
- ia.gaius.kb_ops.is_abstracted_symbol(symbol: str) bool
Check if the symbol provided is an abstracted symbol
- Parameters:
symbol (str) – symbol
- Returns:
True or False
- Return type:
bool
- ia.gaius.kb_ops.list_models(agent: AgentClient, nodes=None)
Return a dict of {node_name: model_list} found on specified nodes
- Parameters:
agent (AgentClient) – GAIuS Agent
nodes (list, optional) – nodes to list models on
- Returns:
{node_name: model_list} for each node specified in nodes
- Return type:
dict
Example
from ia.gaius.agent_client import AgentClient from ia.gaius.kb_ops import list_models agent = AgentClient(agent_info) #get list of models found on node P1 models = list_models(agent, nodes=['P1'])
- ia.gaius.kb_ops.list_symbols(agent: AgentClient, nodes=None)
Return a dict of {node_name: symbol_list} found on specified nodes
- Parameters:
agent (AgentClient) – GAIuS Agent
nodes (list, optional) – nodes to list symbols on
- Returns:
{node_name: symbol_list} for each node specified in nodes
- Return type:
dict
Example
from ia.gaius.agent_client import AgentClient from ia.gaius.kb_ops import list_symbols agent = AgentClient(agent_info) #get list of symbols found on node P1 symbols = list_symbols(agent, nodes=['P1'])
- ia.gaius.kb_ops.merge_kbs(kb1: dict, kb2: dict) Dict[str, dict]
Merge two Knowledgebases
can perform merging on two kbs with multiple nodes, or a single node kb
- Parameters:
kb1 (dict) –
kb2 (dict) –
- Raises:
Exception – If there are multiple nodes in the kb, and they do not line up exactly, raise Exception
- Returns:
merged KB
- Return type:
Dict[str, dict]
- ia.gaius.kb_ops.merge_single_node_kb(kb1: Dict[str, dict], kb2: Dict[str, dict]) dict
Merge two single node KBs. Used internally by merge_kbs
- Parameters:
kb1 (Dict[str, dict]) –
kb2 (Dict[str, dict]) –
- Raises:
Exception – _description_
- Returns:
_description_
- Return type:
dict
- ia.gaius.kb_ops.recursive_delete_model(agent: AgentClient, model_name: str, nodes=None, log_to_file: bool = False)
Recursively remove a model from an Agent.
- Parameters:
agent (AgentClient) – GAIuS Agent
model_name (str) – Model to remove
nodes (_type_, optional) – Nodes to delete model from. Defaults to None.
log_to_file (bool, optional) – output log data to file. Defaults to False.
- ia.gaius.kb_ops.recursive_update_model(agent: AgentClient, model_name: str, model: dict = {}, nodes=None, log_to_file: bool = False)
Recursively update model in a hierarchical agent
- Parameters:
agent (AgentClient) – GAIuS Agent
model_name (str) – Model name to update
model (dict) – updated model contents
nodes (_type_, optional) – _description_. Defaults to None.
log_to_file (bool, optional) – _description_. Defaults to False.
- ia.gaius.kb_ops.remove_abstracted_symbols(agent: AgentClient, symbols: list)
Take an abstracted symbol, split it into corresponding parts, and call remove symbol on the symbol that has been abstracted up.
Symbol format: PRIMITIVE|<NODE_ID>|<MODEL HASH>|<ABSTRACTED FIELD>|<ABSTRACTED VALUE>
- Parameters:
agent (AgentClient) – Agent to perform removal on
symbols (list) – Abstracted symbols to be removed.