diff --git a/erniebot-agent/cookbook/langchain_function_agent_with_retrieval.ipynb b/erniebot-agent/cookbook/langchain_function_agent_with_retrieval.ipynb index 67642f061..0628da4cc 100644 --- a/erniebot-agent/cookbook/langchain_function_agent_with_retrieval.ipynb +++ b/erniebot-agent/cookbook/langchain_function_agent_with_retrieval.ipynb @@ -26,7 +26,7 @@ "metadata": {}, "outputs": [], "source": [ - "! pip install langchain" + "!pip install langchain" ] }, { @@ -93,16 +93,16 @@ "name": "stdout", "output_type": "stream", "text": [ - "--2024-01-02 02:23:31-- https://paddlenlp.bj.bcebos.com/datasets/examples/construction_regulations.tar\n", + "--2024-01-02 02:52:27-- https://paddlenlp.bj.bcebos.com/datasets/examples/construction_regulations.tar\n", "Resolving paddlenlp.bj.bcebos.com (paddlenlp.bj.bcebos.com)... 36.110.192.178, 2409:8c04:1001:1002:0:ff:b001:368a\n", "Connecting to paddlenlp.bj.bcebos.com (paddlenlp.bj.bcebos.com)|36.110.192.178|:443... connected.\n", "HTTP request sent, awaiting response... 200 OK\n", "Length: 1239040 (1.2M) [application/x-tar]\n", "Saving to: ‘construction_regulations.tar’\n", "\n", - "construction_regula 100%[===================>] 1.18M 4.92MB/s in 0.2s \n", + "construction_regula 100%[===================>] 1.18M 874KB/s in 1.4s \n", "\n", - "2024-01-02 02:23:32 (4.92 MB/s) - ‘construction_regulations.tar’ saved [1239040/1239040]\n", + "2024-01-02 02:52:28 (874 KB/s) - ‘construction_regulations.tar’ saved [1239040/1239040]\n", "\n", "construction_regulations/\n", "construction_regulations/城市管理执法办法.pdf\n", @@ -159,17 +159,18 @@ "outputs": [], "source": [ "class FaissSearch:\n", - " def __init__(self, db):\n", - " # 类的初始化方法,接收一个数据库实例并将其存储在类的实例变量 self.db 中\n", + " def __init__(self, db, embeddings):\n", + " # 类的初始化方法,接收一个数据库实例并将其存储在类的实例变量 self.db 中,接收一个embeddings方法传到self.embeddings中\n", " self.db = db\n", + " self.embeddings = embeddings\n", "\n", " def search(self, query: str, top_k: int = 10, **kwargs):\n", " # 定义一个搜索方法,接受一个查询字符串 'query' 和一个整数 'top_k',默认为 10\n", " docs = self.db.similarity_search(query, top_k)\n", " # 调用数据库的 similarity_search 方法来获取与查询最相关的文档\n", - " para_result = embeddings.embed_documents([i.page_content for i in docs])\n", + " para_result = self.embeddings.embed_documents([i.page_content for i in docs])\n", " # 对获取的文档内容进行嵌入(embedding),以便进行相似性比较\n", - " query_result = embeddings.embed_query(query)\n", + " query_result = self.embeddings.embed_query(query)\n", " # 对查询字符串也进行嵌入\n", " similarities = cosine_similarity([query_result], para_result).reshape((-1,))\n", " # 计算查询嵌入和文档嵌入之间的余弦相似度\n", @@ -216,15 +217,15 @@ "output_type": "stream", "text": [ "Created a chunk of size 408, which is longer than the specified 320\n", - "Retrying requests: Attempt 1 ended with: \n", - "Retrying requests: Attempt 1 ended with: \n", - "Retrying requests: Attempt 1 ended with: \n", - "Retrying requests: Attempt 1 ended with: \n", - "Retrying requests: Attempt 1 ended with: \n", - "Retrying requests: Attempt 1 ended with: \n", - "Retrying requests: Attempt 1 ended with: \n", - "Retrying requests: Attempt 1 ended with: \n", - "Retrying requests: Attempt 1 ended with: \n" + "Retrying requests: Attempt 1 ended with: \n", + "Retrying requests: Attempt 1 ended with: \n", + "Retrying requests: Attempt 1 ended with: \n", + "Retrying requests: Attempt 1 ended with: \n", + "Retrying requests: Attempt 1 ended with: \n", + "Retrying requests: Attempt 1 ended with: \n", + "Retrying requests: Attempt 1 ended with: \n", + "Retrying requests: Attempt 1 ended with: \n", + "Retrying requests: Attempt 1 ended with: \n" ] } ], @@ -261,8 +262,8 @@ "name": "stderr", "output_type": "stream", "text": [ - "Retrying requests: Attempt 1 ended with: \n", - "Retrying requests: Attempt 1 ended with: \n" + "Retrying requests: Attempt 1 ended with: \n", + "Retrying requests: Attempt 1 ended with: \n" ] }, { @@ -362,7 +363,7 @@ } ], "source": [ - "faiss_search = FaissSearch(db=db)\n", + "faiss_search = FaissSearch(db=db, embeddings=embeddings)\n", "res = faiss_search.search(query=\"城市管理执法主管部门的职责是什么?\")\n", "from pprint import pprint\n", "\n", diff --git a/erniebot-agent/cookbook/llama_index_function_agent_with_retrieval.ipynb b/erniebot-agent/cookbook/llama_index_function_agent_with_retrieval.ipynb index d892ac9d6..54bf64ffb 100644 --- a/erniebot-agent/cookbook/llama_index_function_agent_with_retrieval.ipynb +++ b/erniebot-agent/cookbook/llama_index_function_agent_with_retrieval.ipynb @@ -26,7 +26,7 @@ "metadata": {}, "outputs": [], "source": [ - "! pip install llama-index" + "!pip install llama-index" ] }, {