agentscope.rag.knowledge_bank module
Knowledge bank for making Knowledge objects easier to use
- class agentscope.rag.knowledge_bank.KnowledgeBank(configs: dict | str)[源代码]
基类:
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.
- 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 [源代码]
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”])
- 参数:
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 [源代码]
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
- 返回:
the Knowledge object defined with Llama-index
- 返回类型:
- equip(agent: AgentBase, knowledge_id_list: list[str] | None = None, duplicate: bool = False) None [源代码]
Equip the agent with the knowledge by knowledge ids.
- 参数:
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