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.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.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) – _description_

  • model_name (str) – _description_

  • nodes (_type_, optional) – _description_. Defaults to None.

  • log_to_file (bool, optional) – _description_. Defaults to False.

ia.gaius.kb_ops.recursive_update_model(agent: AgentClient, model_name: str, model: dict = {}, nodes=None, log_to_file: bool = False)

_summary_ :param agent: _description_ :type agent: AgentClient :param model_name: _description_ :type model_name: str :param nodes: _description_. Defaults to None. :type nodes: _type_, optional :param log_to_file: _description_. Defaults to False. :type log_to_file: bool, optional