From 36945ebfb94def02be48a66bd9a29b1f9eab76d2 Mon Sep 17 00:00:00 2001 From: yinjiaqi Date: Tue, 17 Dec 2024 18:55:16 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=96=B0=E5=A2=9E2024-12-18=E7=9B=B4?= =?UTF-8?q?=E6=92=ADCookbook?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2024_12_18/rag_knowledgebase_01.ipynb | 486 ++++++++++++++++++ 1 file changed, 486 insertions(+) create mode 100644 cookbooks/live_broadcast_material/2024_12_18/rag_knowledgebase_01.ipynb diff --git a/cookbooks/live_broadcast_material/2024_12_18/rag_knowledgebase_01.ipynb b/cookbooks/live_broadcast_material/2024_12_18/rag_knowledgebase_01.ipynb new file mode 100644 index 000000000..525632c5a --- /dev/null +++ b/cookbooks/live_broadcast_material/2024_12_18/rag_knowledgebase_01.ipynb @@ -0,0 +1,486 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# AppBuilder-Knowledge:生产环境的知识库/文档/切片管理教学\n", + "\n", + "[知识库组件](https://github.com/baidubce/app-builder/blob/master/docs/BasisModule/Platform/KnowledgeBase/knowledgebase.md)\n", + "\n", + "知识库组件(KnowledgeBase)是对线上知识库操作的组件,可以通过SDK实现创建知识库、添加知识文档、查询知识库文档、删除知识文档等操作,可在平台console中查看结果。对console端知识库进行操作,可以通过SDK实现创建知识库、添加知识文档、查询知识库文档、删除知识文档等操作,可在平台console中查看结果\n", + "\n", + "## 1. 创建Agent应用\n", + "\n", + "### 1.1 平台Console创建Agent应用\n", + "\n", + "- 创建空应用并发布\n", + "\n", + "![](https://bj.bcebos.com/v1/appbuilder-sdk-components/console%E5%88%9B%E5%BB%BA%E6%B0%91%E6%B3%95%E5%85%B8.png?authorization=bce-auth-v1%2FALTAKGa8m4qCUasgoljdEDAzLm%2F2024-12-17T07%3A38%3A28Z%2F-1%2Fhost%2Ff497d9db3d8945859043fe24fcca4490c3e93a27042e42abc280d0fea7fd3305)\n", + "\n", + "### 1.2 使用SDK调用创建的民法典智能问答Agent\n" + ] + }, + { + "cell_type": "code", + "execution_count": 86, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "民法典第二编第一章的内容是关于物权编通则的一般规定,主要包括以下几个方面:\n", + "\n", + "### 一、物权编的调整范围\n", + "\n", + "* **第二百零五条**:本编调整因物的归属和利用产生的民事关系。\n", + "\n", + "### 二、国家基本经济制度\n", + "\n", + "* **第二百零六条**:国家坚持和完善公有制为主体、多种所有制经济共同发展,按劳分配为主体、多种分配方式并存,社会主义市场经济体制等社会主义基本经济制度。国家巩固和发展公有制经济,鼓励、支持和引导非公有制经济的发展。国家实行社会主义市场经济,保障一切市场主体的平等法律地位和发展权利。\n", + "\n", + "### 三、物权保护原则\n", + "\n", + "* **第二百零七条**:国家、集体、私人的物权和其他权利人的物权受法律平等保护,任何组织或者个人不得侵犯。\n", + "\n", + "### 四、物权设立、变更、转让和消灭的基本原则\n", + "\n", + "* **第二百零八条**:不动产物权的设立、变更、转让和消灭,应当依照法律规定登记。动产物权的设立和转让,应当依照法律规定交付。\n", + "\n", + "### 五、其他规定\n", + "\n", + "民法典第二编第一章还包含了一些其他与物权相关的一般性规定,这些规定为物权编后续章节的具体内容提供了基础和指导。\n", + "\n", + "综上所述,民法典第二编第一章作为物权编通则的一般规定,明确了物权编的调整范围、国家基本经济制度、物权保护原则以及物权设立、变更、转让和消灭的基本原则,为后续章节的具体规定提供了基础和指导。\n" + ] + } + ], + "source": [ + "import appbuilder\n", + "import os\n", + "\n", + "# 更换为自己的Appbuilder-token\n", + "os.environ[\"APPBUILDER_TOKEN\"] = \"bce-v3/ALTAK-mTvDIz1UXh1hXOXlPGhgZ/c248674382dd0bdda93b55c74758b2d2060be77e\"\n", + "\n", + "# 更换为自己的App ID\n", + "app_id = \"094eeeb7-d877-4a39-9305-1a38adf5c51e\"\n", + "client = appbuilder.AppBuilderClient(app_id)\n", + "conversation_id = client.create_conversation()\n", + "message = client.run(conversation_id, \"请输出民法典第二编第一章的内容\")\n", + "# 打印对话结果\n", + "print(message.content.answer)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "![](https://bj.bcebos.com/v1/appbuilder-sdk-components/%E6%B0%91%E6%B3%95%E5%85%B8%E7%AC%AC%E4%BA%8C%E7%BC%96%E7%AC%AC%E4%B8%80%E7%AB%A0%E4%B8%80%E8%88%AC%E8%A7%84%E5%AE%9A.png?authorization=bce-auth-v1%2FALTAKGa8m4qCUasgoljdEDAzLm%2F2024-12-17T08%3A10%3A14Z%2F-1%2Fhost%2F7852a4156383383e6190435f76b6709409def221e3835369f7d155d3c9dd438a)\n", + "\n", + "我们可以观察到上述Agent基本回答除了对于民法典的第二编第一章一般规定的内容,但是对照上图中的内容不够准确,这说明LLM在运行中出现了一定程度的幻觉,所以我们需要使用RAG(KnowledgeBase)对Agent进行优化。\n", + "\n", + "## 2. RAG(KnowledgeBase)\n", + "\n", + "Appbuilder中支持多种实现创建知识库、添加知识文档、查询知识库文档、删除知识文档等操作方式,包括:\n", + "- 平台Console实现知识库操作\n", + "- 使用SDK/API代码态实现知识库操作\n", + "这里我们选择使用代码态SDK实现知识库的操作\n", + "\n", + "### 2.1 创建知识库\n", + "\n", + "首先我们需要创建知识库,这里我们使用SDK代码态实现知识库的创建" + ] + }, + { + "cell_type": "code", + "execution_count": 80, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "知识库ID: 6ac10164-e80a-4497-ae9f-06ac35f38b97\n" + ] + } + ], + "source": [ + "knowledge = appbuilder.KnowledgeBase()\n", + "resp = knowledge.create_knowledge_base(\n", + " name=\"中华人民共和国民法典\",\n", + " description=\"中华人民共和国民法典的中文版\",\n", + " type=\"public\",\n", + " )\n", + "my_knowledge_base_id = resp.id # 传入知识库ID\n", + "my_knowledge = appbuilder.KnowledgeBase(my_knowledge_base_id)\n", + "print(\"知识库ID: \", my_knowledge.knowledge_id)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- 我们可以到平台Console中查看知识库是否创建成功,我们可以观察到知识库的名称和ID,知识库创建成功!\n", + "\n", + "![](https://bj.bcebos.com/v1/appbuilder-sdk-components/%E6%9F%A5%E7%9C%8B%E7%9F%A5%E8%AF%86%E5%BA%93%E6%B0%91%E6%B3%95%E5%85%B8.png?authorization=bce-auth-v1%2FALTAKGa8m4qCUasgoljdEDAzLm%2F2024-12-17T08%3A37%3A16Z%2F-1%2Fhost%2F40c0d55c6d01d538853bf3b8167c9c5271d74083a20afd5d17590986b44eb954)\n", + "\n", + "\n", + "### 2.2 上传文档到知识库\n", + "\n", + "上传文档到知识库共有以下三种方式:\n", + "- 上传文档到知识库\n", + "- 上传通用文档\n", + "\n", + "##### 2.2.1 上传文档到知识库\n", + "- 主要提供自定义文档处理策略,向知识库添加文档\n", + " - 文档格式:rawText (允许配置后续分割策略)\n", + " - 文档处理策略\n", + "\n", + "```python\n", + "knowledge_base_id = my_knowledge.knowledge_id\n", + "knowledge.create_documents(\n", + "\tid=knowledge_base_id,\n", + "\tcontentFormat=\"rawText\",\n", + "\tsource=appbuilder.DocumentSource(\n", + "\t\ttype=\"web\",\n", + "\t\turls=[\"网页版的文档链接地址\"],\n", + "\t\turlDepth=1,\n", + "\t),\n", + "\tprocessOption=appbuilder.DocumentProcessOption(\n", + "\t\ttemplate=\"custom\",\n", + "\t\tparser=appbuilder.DocumentChoices(\n", + "\t\t\tchoices=[\"layoutAnalysis\", \"ocr\"]\n", + "\t\t),\n", + "\t\tchunker=appbuilder.DocumentChunker(\n", + "\t\t\tchoices=[\"separator\"],\n", + "\t\t\tseparator=appbuilder.DocumentSeparator(\n", + "\t\t\t\tseparators=[\"。\"],\n", + "\t\t\t\ttargetLength=300,\n", + "\t\t\t\toverlapRate=0.25,\n", + "\t\t\t),\n", + "\t\t\tprependInfo=[\"title\", \"filename\"],\n", + "\t\t),\n", + "\t\tknowledgeAugmentation=appbuilder.DocumentChoices(choices=[\"faq\"]),\n", + "\t),\n", + ")\n", + "```\n", + "\n", + "#### 2.2.2 上传通用文档\n", + "- SDK支持基于代码态的文档上传方法`upload_file`,以及包含文档的自定义切分逻辑的向知识库添加文档的方法``add_document`\n", + "- 需要先将文档下载至本地\n", + "\n", + "#### 采用上传通用文档的方案上传文档到知识库\n", + "- 下面将提供一个缺少第七编第十章的民法典txt文件,同时使用SDK将其上传到知识库中,首先下载我们储存到云端的txt文件。" + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "文件已成功下载到 mingfadian.txt\n" + ] + } + ], + "source": [ + "# 下载云端民法典到本地\n", + "import requests\n", + "\n", + "def download_file(url, local_filename):\n", + " try:\n", + " response = requests.get(url, stream=True)\n", + " with open(local_filename, 'wb') as f:\n", + " for chunk in response.iter_content(chunk_size=8192):\n", + " f.write(chunk)\n", + "\n", + " print(f\"文件已成功下载到 {local_filename}\")\n", + " except requests.RequestException as e:\n", + " print(f\"下载文件时发生错误: {e}\")\n", + "\n", + "# 使用示例\n", + "url = 'https://bj.bcebos.com/v1/appbuilder-sdk-components/mingfadian.txt?authorization=bce-auth-v1\\\n", + "%2FALTAKGa8m4qCUasgoljdEDAzLm%2F2024-12-17T10%3A44%3A33Z%2F-1%2Fhost%2Fb97e44abe836f58de9632c374d4055c391a84f7998562493c22fdff8596cdf49'\n", + "local_filename = 'mingfadian.txt' \n", + "download_file(url, local_filename)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- 接下来我们将下载好的mingfadian.txt文件使用SDK上传到Appbuilder的知识库中,使用`appbuilder.CustomProcessRule`设置文档的切分规则。" + ] + }, + { + "cell_type": "code", + "execution_count": 83, + "metadata": {}, + "outputs": [], + "source": [ + "upload_res = knowledge.upload_file(local_filename)\n", + "add_res = knowledge.add_document(\n", + " content_type=\"raw_text\",\n", + " file_ids=[upload_res.id],\n", + " custom_process_rule=appbuilder.CustomProcessRule(\n", + " separators=[\"?\"], target_length=600, overlap_rate=0.3\n", + " ),\n", + " knowledge_base_id=my_knowledge.knowledge_id\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- 此时就可以在平台Console中查看到我们上传的民法典知识库了\n", + "\n", + "![](https://bj.bcebos.com/v1/appbuilder-sdk-components/%E6%B0%91%E6%B3%95%E5%85%B8%E7%9F%A5%E8%AF%86%E5%BA%93%E4%B8%AD%E6%9F%A5%E7%9C%8B%E5%AF%B9%E5%BA%94%E6%96%87%E4%BB%B6.png?authorization=bce-auth-v1%2FALTAKGa8m4qCUasgoljdEDAzLm%2F2024-12-17T08%3A51%3A35Z%2F-1%2Fhost%2F4025b0777017d0776e08ebe81c94b794c0883165ceaac1751d6c9824ed5727c2)\n", + "\n", + "### 2.3 为Agent应用添加知识库\n", + "\n", + "- 在平台console中找到我们创建的Agent应用,添加我们创建的民法典知识库,并更新发布应用\n", + "\n", + "![](https://bj.bcebos.com/v1/appbuilder-sdk-components/%E5%BA%94%E7%94%A8%E6%B7%BB%E5%8A%A0%E7%9F%A5%E8%AF%86%E5%BA%93.png?authorization=bce-auth-v1%2FALTAKGa8m4qCUasgoljdEDAzLm%2F2024-12-17T08%3A55%3A22Z%2F-1%2Fhost%2F4213ddd932eb9db15a507d985092797f168f5bb338df0453ea0848a1f9814597)\n", + "\n", + "- 再次调用我们的Agent应用,就可以看到我们添加民法典知识库之后,Agent应用可以正确回答我们的问题了" + ] + }, + { + "cell_type": "code", + "execution_count": 88, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "**民法典第二编第一章的内容如下**:\n", + "\n", + "第一章 一般规定\n", + "\n", + "第二百零五条 本编调整因物的归属和利用产生的民事关系。\n", + "\n", + "第二百零六条 国家坚持和完善公有制为主体、多种所有制经济共同发展,按劳分配为主体、多种分配方式并存,社会主义市场经济体制等社会主义基本经济制度。国家巩固和发展公有制经济,鼓励、支持和引导非公有制经济的发展。国家实行社会主义市场经济,保障一切市场主体的平等法律地位和发展权利。\n", + "\n", + "第二百零七条 国家、集体、私人的物权和其他权利人的物权受法律平等保护,任何组织或者个人不得侵犯。\n", + "\n", + "第二百零八条 不动产物权的设立、变更、转让和消灭,应当依照法律规定登记。动产物权的设立和转让,应当依照法律规定交付。\n" + ] + } + ], + "source": [ + "client = appbuilder.AppBuilderClient(app_id)\n", + "conversation_id = client.create_conversation()\n", + "message = client.run(conversation_id, \"请输出民法典第二编第一章的内容\")\n", + "# 打印对话结果\n", + "print(message.content.answer)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- 可以观察到在使用了RAG(KnowledgeBase)之后,可以准确的输出【民法典的第二编第一分编第一章一般规定】部分的准确内容,接下来我们实验查询我们刻意删除掉的民法典第七编第十章部分的内容,查看Agent能否输出准确答案。(使用此方法模拟我们知识库中的文档更新之后,并没有被上传到知识库的情况)" + ] + }, + { + "cell_type": "code", + "execution_count": 89, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "无法回答此问题。\n" + ] + } + ], + "source": [ + "client = appbuilder.AppBuilderClient(app_id)\n", + "conversation_id = client.create_conversation()\n", + "message = client.run(conversation_id, \"请输出中华人民共和国民法典第七编第十章原文内容\")\n", + "# 打印对话结果\n", + "print(message.content.answer)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- 我们可以发现Agent并没有输出民法典的第七编第十章的准确内容,此时我们就需要Appbuilder的切片管理功能,对知识库新增切片\n", + "\n", + "## 3. 知识库切片管理\n", + "\n", + "Appbuilder中支持多种知识库切片管理操作方式,包括:\n", + "- 平台Console实现知识库切片管理\n", + "- 使用SDK/API代码态实现知识库切片管理(优势)\n", + "这里我们选择使用代码态SDK实现知识库切片管理的操作\n", + "\n", + "### 3.1KnowledgeBase 代码态切片管理功能\n", + "\n", + "* 创建切片\n", + "* 修改切片信息\n", + "* 获取切片信息\n", + "* 获取切片列表\n", + "* 删除切片\n", + "\n", + "\n", + "- 接下来我们使用SDK上传一个民法典第七编第十章部分的内容的切片" + ] + }, + { + "cell_type": "code", + "execution_count": 90, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "切片ID: f1e1962f-70dd-4573-9068-37485980ac5c\n" + ] + } + ], + "source": [ + "# 获取知识库全部文档:get_all_documents\n", + "doc_list = knowledge.get_all_documents(my_knowledge.knowledge_id)\n", + "\n", + "# 获取doc_list列表的第一个文档的document_id\n", + "document_id = doc_list[0].id # 这里我们的知识库只有一个文档,所以获取第一个文档的document_id\n", + "my_knowledge = appbuilder.KnowledgeBase(my_knowledge_base_id)\n", + "\n", + "# 这里我们使用来web_crawler函数来模拟爬虫功能,在生产环境中开发者可以使用自己的爬虫模块来周期性的获取最新的文档更新内容\n", + "def web_crawler():\n", + " \"\"\"\n", + " 此函数模拟爬虫功能,获取最新的文档更新内容内容\n", + " \"\"\"\n", + " content = \"\"\"\n", + " 中华人民共和国民法典第七编第十章原文内容如下:\n", + " 建筑物和物件损害责任\n", + " 第一千二百五十二条 建筑物、构筑物或者其他设施倒塌、塌陷造成他人损害的,由建设单位与施工单位承担连带责任,但是建设单位与施工单位能够证明不存在质量缺陷的除外。建设单位、施工单位赔偿后,有其他责任人的,有权向其他责任人追偿。\n", + " 因所有人、管理人、使用人或者第三人的原因,建筑物、构筑物或者其他设施倒塌、塌陷造成他人损害的,由所有人、管理人、使用人或者第三人承担侵权责任。\n", + " 第一千二百五十三条 建筑物、构筑物或者其他设施及其搁置物、悬挂物发生脱落、坠落造成他人损害,所有人、管理人或者使用人不能证明自己没有过错的,应当承担侵权责任。所有人、管理人或者使用人赔偿后,有其他责任人的,有权向其他责任人追偿。\n", + " 第一千二百五十四条 禁止从建筑物中抛掷物品。从建筑物中抛掷物品或者从建筑物上坠落的物品造成他人损害的,由侵权人依法承担侵权责任;经调查难以确定具体侵权人的,除能够证明自己不是侵权人的外,由可能加害的建筑物使用人给予补偿。可能加害的建筑物使用人补偿后,有权向侵权人追偿。\n", + " 物业服务企业等建筑物管理人应当采取必要的安全保障措施防止前款规定情形的发生;未采取必要的安全保障措施的,应当依法承担未履行安全保障义务的侵权责任。\n", + " 发生本条第一款规定的情形的,公安等机关应当依法及时调查,查清责任人。\n", + " 第一千二百五十五条 堆放物倒塌、滚落或者滑落造成他人损害,堆放人不能证明自己没有过错的,应当承担侵权责任。\n", + " 第一千二百五十六条 在公共道路上堆放、倾倒、遗撒妨碍通行的物品造成他人损害的,由行为人承担侵权责任。公共道路管理人不能证明已经尽到清理、防护、警示等义务的,应当承担相应的责任。\n", + " 第一千二百五十七条 因林木折断、倾倒或者果实坠落等造成他人损害,林木的所有人或者管理人不能证明自己没有过错的,应当承担侵权责任。\n", + " 第一千二百五十八条 在公共场所或者道路上挖掘、修缮安装地下设施等造成他人损害,施工人不能证明已经设置明显标志和采取安全措施的,应当承担侵权责任。\n", + " 窨井等地下设施造成他人损害,管理人不能证明尽到管理职责的,应当承担侵权责任。\n", + " \"\"\"\n", + " return content\n", + "\n", + "\n", + "resp = my_knowledge.create_chunk(documentId=document_id, content=web_crawler())\n", + "print(\"切片ID: \", resp.id)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- 接下来我们再次调用Agent应用,查看一下他对民法典第七编第十章的说明。" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "以下是《中华人民共和国民法典》第七编第十章的全部内容:\n", + "\n", + "**建筑物和物件损害责任**\n", + "\n", + "**第一千二百五十二条** 建筑物、构筑物或者其他设施倒塌、塌陷造成他人损害的,由建设单位与施工单位承担连带责任,但是建设单位与施工单位能够证明不存在质量缺陷的除外。建设单位、施工单位赔偿后,有其他责任人的,有权向其他责任人追偿。\n", + "\n", + "因所有人、管理人、使用人或者第三人的原因,建筑物、构筑物或者其他设施倒塌、塌陷造成他人损害的,由所有人、管理人、使用人或者第三人承担侵权责任。\n", + "\n", + "**第一千二百五十三条** 建筑物、构筑物或者其他设施及其搁置物、悬挂物发生脱落、坠落造成他人损害,所有人、管理人或者使用人不能证明自己没有过错的,应当承担侵权责任。所有人、管理人或者使用人赔偿后,有其他责任人的,有权向其他责任人追偿。\n", + "\n", + "**第一千二百五十四条** 禁止从建筑物中抛掷物品。从建筑物中抛掷物品或者从建筑物上坠落的物品造成他人损害的,由侵权人依法承担侵权责任;经调查难以确定具体侵权人的,除能够证明自己不是侵权人的外,由可能加害的建筑物使用人给予补偿。可能加害的建筑物使用人补偿后,有权向侵权人追偿。\n", + "\n", + "物业服务企业等建筑物管理人应当采取必要的安全保障措施防止前款规定情形的发生;未采取必要的安全保障措施的,应当依法承担未履行安全保障义务的侵权责任。\n", + "\n", + "发生本条第一款规定的情形的,公安等机关应当依法及时调查,查清责任人。\n", + "\n", + "**第一千二百五十五条** 堆放物倒塌、滚落或者滑落造成他人损害,堆放人不能证明自己没有过错的,应当承担侵权责任。\n", + "\n", + "**第一千二百五十六条** 在公共道路上堆放、倾倒、遗撒妨碍通行的物品造成他人损害的,由行为人承担侵权责任。公共道路管理人不能证明已经尽到清理、防护、警示等义务的,应当承担相应的责任。\n", + "\n", + "**第一千二百五十七条** 因林木折断、倾倒或者果实坠落等造成他人损害,林木的所有人或者管理人不能证明自己没有过错的,应当承担侵权责任。\n", + "\n", + "**第一千二百五十八条** 在公共场所或者道路上挖掘、修缮安装地下设施等造成他人损害,施工人不能证明已经设置明显标志和采取安全措施的,应当承担侵权责任。\n", + "\n", + "窨井等地下设施造成他人损害,管理人不能证明尽到管理职责的,应当承担侵权责任。\n" + ] + } + ], + "source": [ + "client = appbuilder.AppBuilderClient(app_id)\n", + "conversation_id = client.create_conversation()\n", + "message = client.run(conversation_id, \"请输出中华人民共和国民法典第七编第十章原文内容\")\n", + "# 打印对话结果\n", + "print(message.content.answer)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- 可以观察到此次Agent运行准确的的输出了民法典第七编第十章的内容\n", + "\n", + "#### 其他的知识库文档&切片管理方法\n", + "\n", + "###### 修改切片信息`modify_chunk`\n", + "\n", + "- 如果我们对之前设置的切片信息不满意,可以通过`modify_chunk`方法进行修改。\n", + "\n", + "###### 获取切片信息`describe_chunk`\n", + "\n", + "- 我需要查看我刚才创建切片信息,可以使用`describe_chunk`方法\n", + "\n", + "###### 删除切片信息`delete_chunk`\n", + "\n", + "- 切片信息创建出来后,如果不需要了,可以通过`delete_chunk`方法进行删除。\n", + "\n", + "##### 删除文档和知识库\n", + "\n", + "- 当你不再需要文档知识库时,可以删除它,SDK同样提供删除文档和知识库的方法\n", + " - 从知识库删除文档 `KnowledgeBase().delete_document`\n", + " - 删除知识库`delete_knowledge_base`" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "python-3.10.14", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.14" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From 274e4623e135a6615829c7f119541c06dedf6c67 Mon Sep 17 00:00:00 2001 From: yinjiaqi Date: Tue, 17 Dec 2024 19:02:59 +0800 Subject: [PATCH 2/2] update --- .../live_broadcast_material/2024_08_22/knowledgebase.ipynb | 2 +- .../2024_12_18/rag_knowledgebase_01.ipynb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cookbooks/live_broadcast_material/2024_08_22/knowledgebase.ipynb b/cookbooks/live_broadcast_material/2024_08_22/knowledgebase.ipynb index 1bfae0c9d..fff989ef1 100644 --- a/cookbooks/live_broadcast_material/2024_08_22/knowledgebase.ipynb +++ b/cookbooks/live_broadcast_material/2024_08_22/knowledgebase.ipynb @@ -6,7 +6,7 @@ "source": [ "# AppBuilder-Knowledge:生产环境的知识库/文档/切片管理教学\n", "\n", - "[知识库组件](https://github.com/baidubce/app-builder/blob/master/docs/basic_module/knowledgebase.md)\n", + "[知识库组件](https://github.com/baidubce/app-builder/blob/master/docs/BasisModule/Platform/KnowledgeBase/knowledgebase.md)\n", "\n", "知识库组件(KnowledgeBase)是对线上知识库操作的组件,可以通过SDK实现创建知识库、添加知识文档、查询知识库文档、删除知识文档等操作,可在平台console中查看结果。对console端知识库进行操作,可以通过SDK实现创建知识库、添加知识文档、查询知识库文档、删除知识文档等操作,可在平台console中查看结果\n", "\n", diff --git a/cookbooks/live_broadcast_material/2024_12_18/rag_knowledgebase_01.ipynb b/cookbooks/live_broadcast_material/2024_12_18/rag_knowledgebase_01.ipynb index 525632c5a..cc6d76ef9 100644 --- a/cookbooks/live_broadcast_material/2024_12_18/rag_knowledgebase_01.ipynb +++ b/cookbooks/live_broadcast_material/2024_12_18/rag_knowledgebase_01.ipynb @@ -23,7 +23,7 @@ }, { "cell_type": "code", - "execution_count": 86, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -61,10 +61,10 @@ "import os\n", "\n", "# 更换为自己的Appbuilder-token\n", - "os.environ[\"APPBUILDER_TOKEN\"] = \"bce-v3/ALTAK-mTvDIz1UXh1hXOXlPGhgZ/c248674382dd0bdda93b55c74758b2d2060be77e\"\n", + "os.environ[\"APPBUILDER_TOKEN\"] = \"\"\n", "\n", "# 更换为自己的App ID\n", - "app_id = \"094eeeb7-d877-4a39-9305-1a38adf5c51e\"\n", + "app_id = \"\"\n", "client = appbuilder.AppBuilderClient(app_id)\n", "conversation_id = client.create_conversation()\n", "message = client.run(conversation_id, \"请输出民法典第二编第一章的内容\")\n",