agentscope.rag.knowledge_bank module

Knowledge bank for making Knowledge objects easier to use

class agentscope.rag.knowledge_bank.KnowledgeBank(configs: dict | str)[source]

Bases: object

KnowledgeBank enables 1) provide an easy and fast way to initialize the Knowledge object; 2) make Knowledge object reusable and sharable for multiple agents.

__init__(configs: dict | str) None[source]

initialize the knowledge bank

add_data_as_knowledge(knowledge_id: str, emb_model_name: str, data_dirs_and_types: dict[str, list[str]] | None = None, model_name: str | None = None, knowledge_config: dict | None = None) None[source]

Transform data in a directory to be ready to work with RAG. :param knowledge_id: user-defined unique id for the knowledge :type knowledge_id: str :param emb_model_name: name of the embedding model :type emb_model_name: str :param model_name: name of the LLM for potential post-processing or query rewrite :type model_name: Optional[str] :param data_dirs_and_types: dictionary of data paths (keys) to the data types

(file extensions) for knowledgebase (e.g., [“.md”, “.py”, “.html”])

Parameters:
  • knowledge_config (optional[dict]) – complete indexing configuration, used for more advanced applications. Users can customize - loader, - transformations, - … Examples can refer to../examples/conversation_with_RAG_agents/

  • object (a simple example of importing data to Knowledge)

  • ''

    knowledge_bank.add_data_as_knowledge(

    knowledge_id=”agentscope_tutorial_rag”, emb_model_name=”qwen_emb_config”, data_dirs_and_types={

    ”../../docs/sphinx_doc/en/source/tutorial”: [“.md”],

    }, persist_dir=”./rag_storage/tutorial_assist”,

    )

  • ''

get_knowledge(knowledge_id: str, duplicate: bool = False) Knowledge[source]

Get a Knowledge object from the knowledge bank. :param knowledge_id: unique id for the Knowledge object :type knowledge_id: str :param duplicate: whether return a copy of the Knowledge object. :type duplicate: bool

Returns:

the Knowledge object defined with Llama-index

Return type:

Knowledge

equip(agent: AgentBase, knowledge_id_list: list[str] | None = None, duplicate: bool = False) None[source]

Equip the agent with the knowledge by knowledge ids.

Parameters:
  • agent (AgentBase) – the agent to be equipped with knowledge

  • knowledge_id_list – the list of knowledge ids to be equipped with the agent

  • duplicate (bool) – whether to deepcopy the knowledge object

TODO: to accommodate with distributed setting