国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

目錄
學(xué)習(xí)目標(biāo)
組件
rag vs agentic rag
>從文檔或構(gòu)建知識圖中提取信息。
現(xiàn)在創(chuàng)建一個名為
>系統(tǒng)軟件包
ChromaDB
清潔器:
現(xiàn)在,我們將一一
>轉(zhuǎn)換器將PDF轉(zhuǎn)換並發(fā)送清潔以進(jìn)行清潔。然後,清潔工將清潔的文檔發(fā)送到分離器以進(jìn)行分解。然後,這些塊將傳遞到嵌入式矢量化,最後嵌入的嵌入將把這些嵌入到作者的存儲中。
我們將使用Haystack提示式佈置組件來從模板
首頁 科技週邊 人工智慧 如何使用Haystack Framework構(gòu)建代理QA抹布系統(tǒng)

如何使用Haystack Framework構(gòu)建代理QA抹布系統(tǒng)

Mar 03, 2025 pm 06:35 PM

想像您正在建立一個客戶支持AI,需要回答有關(guān)您的產(chǎn)品的問題。有時,它需要從您的文檔中獲取信息,而其他時間則需要搜索網(wǎng)絡(luò)以獲取最新更新。代理抹布系統(tǒng)在此類複雜的AI應(yīng)用程序中派上用場。將他們視為聰明的研究助理,他們不僅知道您的內(nèi)部文檔,而且決定何時搜索網(wǎng)絡(luò)。在本指南中,我們將使用Haystack Framework進(jìn)行構(gòu)建代理QA抹布系統(tǒng)的過程。

學(xué)習(xí)目標(biāo)

  • 知道什麼是代理LLM,並且了解它與抹布系統(tǒng)有何不同。 >
  • 熟悉Agesic LLM應(yīng)用程序的Haystack框架。
  • >了解從模板提示構(gòu)建的過程,並學(xué)習(xí)如何將不同的提示連接在一起。
  • 學(xué)習(xí)如何在Haystack中使用Chromadb創(chuàng)建嵌入。
  • >
  • 學(xué)習(xí)如何建立從嵌入到世代的完整本地開發(fā)系統(tǒng)。
  • >本文是

> > data Science Blogathon的一部分。 目錄的>>什麼是代理llm?塊

組件

    • 管道
    >連接圖形
    • Question-Asswer rag項目,用於高級物理學(xué)的
    • >管道
    • >>實現(xiàn)路由器
    >>創(chuàng)建提示模板
  • >實現(xiàn)Query Pipeline
    • 繪製查詢管道圖形
    • 結(jié)論
    • 常見問題問題。
    • 什麼是代理LLM?
    • >
    • >代理LLM是一個可以自主做出決定並根據(jù)其對任務(wù)的理解採取行動的AI系統(tǒng)。與主要產(chǎn)生文本響應(yīng)的傳統(tǒng)LLM不同,代理LLM可以做更多的事情。
    • >它可以思考,計劃和行動,以最少的人類投入。它評估其知識,認(rèn)識到何時需要更多信息或外部工具。
    • >代理LLMS
    不依賴靜態(tài)數(shù)據(jù)或索引知識,他們決定要信任哪些來源以及如何收集最佳見解。
  • >
  • 這種類型的系統(tǒng)還可以為作業(yè)選擇正確的工具。它可以決定何時需要檢索文檔,運行計算或自動化任務(wù)。使它們與眾不同的是它可以將復(fù)雜問題分解為步驟並獨立執(zhí)行它們的能力,從而使其對於研究,分析和工作流動自動化很有價值。

    rag vs agentic rag

    >傳統(tǒng)的抹布系統(tǒng)遵循線性過程。 收到查詢時,系統(tǒng)首先標(biāo)識請求中的密鑰元素。然後,它搜索知識庫,掃描相關(guān)信息,以幫助設(shè)計準(zhǔn)確的響應(yīng)。一旦檢索了相關(guān)信息或數(shù)據(jù),系統(tǒng)就會對其進(jìn)行處理以生成有意義且具有上下文相關(guān)的響應(yīng)。

    您可以通過下圖輕鬆理解這些過程。

    如何使用Haystack Framework構(gòu)建代理QA抹布系統(tǒng)現(xiàn)在,一個代理抹布系統(tǒng)通過以下方式增強了此過程

    評估查詢要求

      在多個知識源之間決定
    • 可能將來自不同來源的信息
    • 組合
    • >就響應(yīng)策略做出自主決定
    • 提供源代理響應(yīng)
    • >關(guān)鍵區(qū)別在於系統(tǒng)對如何處理查詢做出明智決定的能力,而不是遵循固定的檢索生成模式。
    • 了解乾草框架組件
    Haystack是一個開源框架,用於構(gòu)建可準(zhǔn)備生產(chǎn)的AI,LLM應(yīng)用程序,RAG管道和搜索系統(tǒng)。它為構(gòu)建LLM應(yīng)用程序提供了一個強大而靈活的框架。它使您可以整合來自Huggingface,OpenAI,Cohere,Mistral和Local Ollama等各種平臺的模型。您還可以在AWS Sagemaker,Bedrock,Azure和GCP等雲(yún)服務(wù)上部署模型。

    > Haystack提供可靠的文檔存儲,以進(jìn)行有效的數(shù)據(jù)管理。它還配備了一套全面的評估,監(jiān)視和數(shù)據(jù)集成工具,可確保您應(yīng)用程序的所有層次的平穩(wěn)性能。它還具有強大的社區(qū)合作,可以定期從各種服務(wù)提供商那裡進(jìn)行新的服務(wù)集成。

    您可以使用Haystack構(gòu)建什麼?

    >使用強大的檢索和發(fā)電技術(shù)易於促進(jìn)數(shù)據(jù)的抹布。

    > 聊天機(jī)器人和代理使用最新的Genai模型,例如GPT-4,Llama3.2,DeepSeek-r1。

    在混合類型(圖像,文本,音頻和表)知識庫上如何使用Haystack Framework構(gòu)建代理QA抹布系統(tǒng)生成多模式提問系統(tǒng)。

    >從文檔或構(gòu)建知識圖中提取信息。

    • > HAYSTACK構(gòu)建塊
    • Haystack有兩個主要概念,用於構(gòu)建功能齊全的Genai LLM系統(tǒng) - 組件和管道。讓我們以日語動漫角色的抹布的簡單示例來理解它們。

      組件

      >組件是Haystack的核心構(gòu)建塊。他們可以執(zhí)行諸如文檔存儲,文檔檢索,文本生成和嵌入之類的任務(wù)。 Haystack有許多組件,您可以在安裝後直接使用,它還提供了通過編寫Python類製造自己組件的API。

      有合作夥伴公司和社區(qū)的集成集合。 >

      >

      >安裝庫,並設(shè)置Ollama

      >

      $ pip install haystack-ai ollama-haystack
      
      # On you system download Ollama and install LLM
      
      ollama pull llama3.2:3b
      
      ollama pull nomic-embed-text
      
      
      # And then start ollama server
      ollama serve
      導(dǎo)入一些組件

      創(chuàng)建文檔和文檔存儲
      from haystack import Document, Pipeline
      from haystack.components.builders.prompt_builder import PromptBuilder
      from haystack.components.retrievers.in_memory import InMemoryBM25Retriever
      from haystack.document_stores.in_memory import InMemoryDocumentStore
      from haystack_integrations.components.generators.ollama import OllamaGenerator

      管道
      document_store = InMemoryDocumentStore()
      documents = [
          Document(
              content="Naruto Uzumaki is a ninja from the Hidden Leaf Village and aspires to become Hokage."
          ),
          Document(
              content="Luffy is the captain of the Straw Hat Pirates and dreams of finding the One Piece."
          ),
          Document(
              content="Goku, a Saiyan warrior, has defended Earth from numerous powerful enemies like Frieza and Cell."
          ),
          Document(
              content="Light Yagami finds a mysterious Death Note, which allows him to eliminate people by writing their names."
          ),
          Document(
              content="Levi Ackerman is humanity’s strongest soldier, fighting against the Titans to protect mankind."
          ),
      ]
      管道是Haystack框架的骨幹。它們定義了不同組件之間的數(shù)據(jù)流。管道本質(zhì)上是有向的無環(huán)圖(DAG)。一個具有多個輸出的單個組件可以連接到具有多個輸入的另一個單個組件。

      >

      您可以通過

      >定義管道

      您可以可視化管道

      pipe = Pipeline()
      
      pipe.add_component("retriever", InMemoryBM25Retriever(document_store=document_store))
      pipe.add_component("prompt_builder", PromptBuilder(template=template))
      pipe.add_component(
          "llm", OllamaGenerator(model="llama3.2:1b", url="http://localhost:11434")
      )
      pipe.connect("retriever", "prompt_builder.documents")
      pipe.connect("prompt_builder", "llm")

      管道提供:

      image_param = {
          "format": "img",
          "type": "png",
          "theme": "forest",
          "bgColor": "f2f3f4",
      }
      pipe.show(params=image_param)

      模塊化工作流程管理

        靈活組件佈置
      • >輕鬆調(diào)試和監(jiān)視
      • 可擴(kuò)展的處理體系結(jié)構(gòu)
      • >節(jié)點
      • 節(jié)點是可以在管道中連接的基本處理單元,這些節(jié)點是執(zhí)行特定任務(wù)的組件。 來自上述管道的節(jié)點的示例

      連接圖

      連接圖定義了組件如何相互作用。

      從上面的管道中,您可以可視化連接圖。
      pipe.add_component("retriever", InMemoryBM25Retriever(document_store=document_store))
      pipe.add_component("prompt_builder", PromptBuilder(template=template))
      pipe.add_component(
          "llm", OllamaGenerator(model="llama3.2:1b", url="http://localhost:11434")
      )
      
      >

      這個圖形結(jié)構(gòu):
      image_param = {
          "format": "img",
          "type": "png",
          "theme": "forest",
          "bgColor": "f2f3f4",
      }
      pipe.show(params=image_param)

      定義組件之間的數(shù)據(jù)流

      > 如何使用Haystack Framework構(gòu)建代理QA抹布系統(tǒng)>管理輸入/輸出關(guān)係

      在可能的情況下啟用並行處理

      >

      創(chuàng)建靈活的處理途徑。
      • 現(xiàn)在,我們可以使用提示來查詢動漫知識庫。 >
      • 創(chuàng)建一個提示模板
      • 此提示將提供一個從文檔庫中獲取信息的答案。
      • >
      >使用提示和檢索器查詢

      響應(yīng):

      template = """
      Given only the following information, answer the question.
      Ignore your own knowledge.
      
      Context:
      {% for document in documents %}
          {{ document.content }}
      {% endfor %}
      
      Question: {{ query }}?
      """

      這個抹布對新來者來說很簡單,但在概念上很有價值?,F(xiàn)在,我們已經(jīng)了解了大多數(shù)Haystack框架的概念,我們可以深入研究我們的主要項目。如果有什麼新事物出現(xiàn),我將在此過程中解釋。

      >

      >高中物理學(xué)的問答抹布項目

      >我們將為高中生建立一個基於NCERT物理書籍的問題答案抹布。它將通過從NCERT書籍中獲取信息來提供查詢的答案,如果不存在信息,它將搜索網(wǎng)絡(luò)以獲取該信息。


      local llama3.2:3b或llama3.2:1b

        Chromadb用於嵌入存儲
      • 用於本地嵌入
      • 的通用嵌入文本模型
      • duckduckgo搜索網(wǎng)絡(luò)搜索或tavily搜索(可選)
      • >
      • 我使用一個免費的,完全局部的系統(tǒng)。
      • >
      設(shè)置開發(fā)人員環(huán)境

      我們將設(shè)置一個conda env python 3.12

      安裝必要的軟件包

      $ pip install haystack-ai ollama-haystack
      
      # On you system download Ollama and install LLM
      
      ollama pull llama3.2:3b
      
      ollama pull nomic-embed-text
      
      
      # And then start ollama server
      ollama serve

      現(xiàn)在創(chuàng)建一個名為

      QAGENT
      from haystack import Document, Pipeline
      from haystack.components.builders.prompt_builder import PromptBuilder
      from haystack.components.retrievers.in_memory import InMemoryBM25Retriever
      from haystack.document_stores.in_memory import InMemoryDocumentStore
      from haystack_integrations.components.generators.ollama import OllamaGenerator
      的項目目錄。

      。 >您可以為項目或jupyter筆記本使用普通的Python文件,這無關(guān)緊要。我將使用一個普通的python文件。

      document_store = InMemoryDocumentStore()
      documents = [
          Document(
              content="Naruto Uzumaki is a ninja from the Hidden Leaf Village and aspires to become Hokage."
          ),
          Document(
              content="Luffy is the captain of the Straw Hat Pirates and dreams of finding the One Piece."
          ),
          Document(
              content="Goku, a Saiyan warrior, has defended Earth from numerous powerful enemies like Frieza and Cell."
          ),
          Document(
              content="Light Yagami finds a mysterious Death Note, which allows him to eliminate people by writing their names."
          ),
          Document(
              content="Levi Ackerman is humanity’s strongest soldier, fighting against the Titans to protect mankind."
          ),
      ]
      在項目根上創(chuàng)建

      main.py

      文件。

      > 導(dǎo)入必要的庫

      >系統(tǒng)軟件包

        > Core Haystack組件
      • ChromAdb用於嵌入組件
      • 元素推斷的ollama組件
      • >
      • 和用於Web搜索的DuckDuckgo
      pipe = Pipeline()
      
      pipe.add_component("retriever", InMemoryBM25Retriever(document_store=document_store))
      pipe.add_component("prompt_builder", PromptBuilder(template=template))
      pipe.add_component(
          "llm", OllamaGenerator(model="llama3.2:1b", url="http://localhost:11434")
      )
      pipe.connect("retriever", "prompt_builder.documents")
      pipe.connect("prompt_builder", "llm")
      image_param = {
          "format": "img",
          "type": "png",
          "theme": "forest",
          "bgColor": "f2f3f4",
      }
      pipe.show(params=image_param)
      pipe.add_component("retriever", InMemoryBM25Retriever(document_store=document_store))
      pipe.add_component("prompt_builder", PromptBuilder(template=template))
      pipe.add_component(
          "llm", OllamaGenerator(model="llama3.2:1b", url="http://localhost:11434")
      )
      
      創(chuàng)建文檔商店
      image_param = {
          "format": "img",
          "type": "png",
          "theme": "forest",
          "bgColor": "f2f3f4",
      }
      pipe.show(params=image_param)
      template = """
      Given only the following information, answer the question.
      Ignore your own knowledge.
      
      Context:
      {% for document in documents %}
          {{ document.content }}
      {% endfor %}
      
      Question: {{ query }}?
      """
      Document store is the most important here we will store our embedding for retrieval, we use

      ChromaDB

      for the embedding store, and as you may see in the earlier example, we use InMemoryDocumentStore for fast retrieval because then our data was tiny but for a robust system of retrieval we don’t rely on the InMemoryStore, it will hog the memory and we will have creat embeddings every time we start系統(tǒng)。

      該解決方案是矢量數(shù)據(jù)庫,例如Pinecode,Weaviate,Postgres Vector DB或Chromadb。我之所以使用chromadb,是因為免費,開源,易於使用且健壯。 >

      persist_path
      query = "How Goku eliminate people?"
      response = pipe.run({"prompt_builder": {"query": query}, "retriever": {"query": query}})
      print(response["llm"]["replies"])
      是您要存儲嵌入的位置。

      pdf文件路徑

      >它將從數(shù)據(jù)文件夾中創(chuàng)建文件列表,該文件由我們的PDF文件組成。 >

      文檔預(yù)處理組件
      $conda create --name agenticlm python=3.12
      
      $conda activate agenticlm

      >我們將使用Haystack的內(nèi)置文檔預(yù)處理器,例如清潔器,分離器和文件轉(zhuǎn)換器,然後使用Writer將數(shù)據(jù)寫入商店。

      清潔器:

      它將清除文檔中的額外空間,重複的線條,空線等。

      分離器:>它將以各種方式分開文檔,例如單詞,句子,para,pages。

      >
      $pip install haystack-ai ollama-haystack pypdf
      
      $pip install chroma-haystack duckduckgo-api-haystack

      >>文件轉(zhuǎn)換器:它將使用PYPDF將PDF轉(zhuǎn)換為文檔。 。

      $ pip install haystack-ai ollama-haystack
      
      # On you system download Ollama and install LLM
      
      ollama pull llama3.2:3b
      
      ollama pull nomic-embed-text
      
      
      # And then start ollama server
      ollama serve

      作者:>它將存儲文檔要存儲文檔和重複文檔的文檔,它將與先前的文檔覆蓋。 >

      from haystack import Document, Pipeline
      from haystack.components.builders.prompt_builder import PromptBuilder
      from haystack.components.retrievers.in_memory import InMemoryBM25Retriever
      from haystack.document_stores.in_memory import InMemoryDocumentStore
      from haystack_integrations.components.generators.ollama import OllamaGenerator
      現(xiàn)在設(shè)置文檔索引的嵌入式。

      >

      嵌入:nomic嵌入文本>

      >我們將使用somic-embed-text嵌入器,這是非常有效且免費的插入面和ollama。

      > 在運行索引管道之前,請打開終端並在下面鍵入sumic-embed-text和llama3.2:3b模型從Ollama模型商店

      >通過在您的終端中鍵入命令
      document_store = InMemoryDocumentStore()
      documents = [
          Document(
              content="Naruto Uzumaki is a ninja from the Hidden Leaf Village and aspires to become Hokage."
          ),
          Document(
              content="Luffy is the captain of the Straw Hat Pirates and dreams of finding the One Piece."
          ),
          Document(
              content="Goku, a Saiyan warrior, has defended Earth from numerous powerful enemies like Frieza and Cell."
          ),
          Document(
              content="Light Yagami finds a mysterious Death Note, which allows him to eliminate people by writing their names."
          ),
          Document(
              content="Levi Ackerman is humanity’s strongest soldier, fighting against the Titans to protect mankind."
          ),
      ]
      ollama serve

      來啟動Ollama 現(xiàn)在嵌入組件

      我們使用

      > ollamadocumentembedder
      pipe = Pipeline()
      
      pipe.add_component("retriever", InMemoryBM25Retriever(document_store=document_store))
      pipe.add_component("prompt_builder", PromptBuilder(template=template))
      pipe.add_component(
          "llm", OllamaGenerator(model="llama3.2:1b", url="http://localhost:11434")
      )
      pipe.connect("retriever", "prompt_builder.documents")
      pipe.connect("prompt_builder", "llm")
      組件嵌入文檔,但是如果您要嵌入文本字符串,則必須使用

      ollamatextemtembedder。 創(chuàng)建索引管道 就像我們以前的玩具抹布示例一樣,我們將首先啟動管道類別。 >

      現(xiàn)在,我們將一一

      一個添加到管道中的組件

      >在管道中添加組件並不關(guān)心訂單,因此您可以按任何順序添加組件。但是連接是重要的。
      image_param = {
          "format": "img",
          "type": "png",
          "theme": "forest",
          "bgColor": "f2f3f4",
      }
      pipe.show(params=image_param)

      將組件連接到管道圖

      pipe.add_component("retriever", InMemoryBM25Retriever(document_store=document_store))
      pipe.add_component("prompt_builder", PromptBuilder(template=template))
      pipe.add_component(
          "llm", OllamaGenerator(model="llama3.2:1b", url="http://localhost:11434")
      )
      

      >在這裡,訂單很重要,因為如何連接組件告訴管道數(shù)據(jù)將如何流過管道。就像,在哪個順序或購買水管物品的位置都沒關(guān)係,但是如何將它們放在一起會決定您是否獲得水。

      >

      >轉(zhuǎn)換器將PDF轉(zhuǎn)換並發(fā)送清潔以進(jìn)行清潔。然後,清潔工將清潔的文檔發(fā)送到分離器以進(jìn)行分解。然後,這些塊將傳遞到嵌入式矢量化,最後嵌入的嵌入將把這些嵌入到作者的存儲中。

      。
      image_param = {
          "format": "img",
          "type": "png",
          "theme": "forest",
          "bgColor": "f2f3f4",
      }
      pipe.show(params=image_param)
      理解!好的,讓我給您索引的視覺圖,以便您可以檢查數(shù)據(jù)流。

      繪製索引管道

      是的,您可以輕鬆地從Haystack管道中創(chuàng)建一個漂亮的美人魚圖。

      索引管道的圖

      >
      template = """
      Given only the following information, answer the question.
      Ignore your own knowledge.
      
      Context:
      {% for document in documents %}
          {{ document.content }}
      {% endfor %}
      
      Question: {{ query }}?
      """

      我假設(shè)您現(xiàn)在已經(jīng)完全掌握了Haystack管道背後的想法。感謝您的水管工。

      實現(xiàn)路由器

      >現(xiàn)在,我們需要創(chuàng)建一個路由器來通過其他路徑路由數(shù)據(jù)。在這種情況下,我們將使用條件路由器,該路由器將在某些條件下完成路由工作。條件路由器將根據(jù)組件輸出評估條件。它將通過不同的管道分支來指導(dǎo)數(shù)據(jù)流,從而實現(xiàn)動態(tài)決策。它也將具有強大的後備策略。
      $ pip install haystack-ai ollama-haystack
      
      # On you system download Ollama and install LLM
      
      ollama pull llama3.2:3b
      
      ollama pull nomic-embed-text
      
      
      # And then start ollama server
      ollama serve

      系統(tǒng)從嵌入式商店上下文中獲得NO_ANSWER回復(fù)時,它將轉(zhuǎn)到Web搜索工具以從Internet收集相關(guān)數(shù)據(jù)。

      >用於網(wǎng)絡(luò)搜索,我們將使用DuckDuckgo API或Tavely,在這裡我使用了DuckDuckgo。

      好的,大多數(shù)繁重的舉重已經(jīng)完成?,F(xiàn)在,是時候及時工程
      from haystack import Document, Pipeline
      from haystack.components.builders.prompt_builder import PromptBuilder
      from haystack.components.retrievers.in_memory import InMemoryBM25Retriever
      from haystack.document_stores.in_memory import InMemoryDocumentStore
      from haystack_integrations.components.generators.ollama import OllamaGenerator

      創(chuàng)建提示模板

      我們將使用Haystack提示式佈置組件來從模板

      構(gòu)建提示

      首先,我們將為QA

      創(chuàng)建一個提示

      >它將從文檔中獲取上下文,並嘗試回答問題。但是,如果它在文檔中找不到相關(guān)上下文,它將回復(fù)no_answer。
      document_store = InMemoryDocumentStore()
      documents = [
          Document(
              content="Naruto Uzumaki is a ninja from the Hidden Leaf Village and aspires to become Hokage."
          ),
          Document(
              content="Luffy is the captain of the Straw Hat Pirates and dreams of finding the One Piece."
          ),
          Document(
              content="Goku, a Saiyan warrior, has defended Earth from numerous powerful enemies like Frieza and Cell."
          ),
          Document(
              content="Light Yagami finds a mysterious Death Note, which allows him to eliminate people by writing their names."
          ),
          Document(
              content="Levi Ackerman is humanity’s strongest soldier, fighting against the Titans to protect mankind."
          ),
      ]
      現(xiàn)在,在從LLM獲取NO_ANSWER之後的第二個提示中,系統(tǒng)將使用Web搜索工具從Internet收集上下文。

      > duckduckgo提示模板

      >它將有助於系統(tǒng)進(jìn)入Web搜索並嘗試回答查詢。 >

      使用Haystack
      pipe = Pipeline()
      
      pipe.add_component("retriever", InMemoryBM25Retriever(document_store=document_store))
      pipe.add_component("prompt_builder", PromptBuilder(template=template))
      pipe.add_component(
          "llm", OllamaGenerator(model="llama3.2:1b", url="http://localhost:11434")
      )
      pipe.connect("retriever", "prompt_builder.documents")
      pipe.connect("prompt_builder", "llm")

      的提示構(gòu)建器創(chuàng)建提示

      我們將使用HayStack提示Joiner一起加入提示的分支。 >實現(xiàn)查詢管道

      image_param = {
          "format": "img",
          "type": "png",
          "theme": "forest",
          "bgColor": "f2f3f4",
      }
      pipe.show(params=image_param)
      >查詢管道將嵌入嵌入的查詢收集上下文資源,並使用LLM或Web搜索工具回答我們的查詢。

      它類似於索引管道。

      pipe.add_component("retriever", InMemoryBM25Retriever(document_store=document_store))
      pipe.add_component("prompt_builder", PromptBuilder(template=template))
      pipe.add_component(
          "llm", OllamaGenerator(model="llama3.2:1b", url="http://localhost:11434")
      )
      
      啟動管道

      >在查詢管道中添加組件

      在這裡,對於LLM生成,我們使用ollamagenerator組件使用Llama3.2:3b或1b或您喜歡使用工具調(diào)用的任何LLM生成答案。 >

      將所有組件連接在一起以進(jìn)行查詢流並回答生成

      image_param = {
          "format": "img",
          "type": "png",
          "theme": "forest",
          "bgColor": "f2f3f4",
      }
      pipe.show(params=image_param)
      總結(jié)上述連接:>

      發(fā)送到回獵犬的查詢嵌入的text_embedder的嵌入。
      template = """
      Given only the following information, answer the question.
      Ignore your own knowledge.
      
      Context:
      {% for document in documents %}
          {{ document.content }}
      {% endfor %}
      
      Question: {{ query }}?
      """

      獵犬將數(shù)據(jù)發(fā)送到提示_builder的文檔。

      提示構(gòu)建器轉(zhuǎn)到提示木器以加入其他提示。

      >

      提示木匠將數(shù)據(jù)傳遞給LLM發(fā)電。
      query = "How Goku eliminate people?"
      response = pipe.run({"prompt_builder": {"query": query}, "retriever": {"query": query}})
      print(response["llm"]["replies"])
      llm的答復(fù)轉(zhuǎn)到路由器以檢查答復(fù)是否具有

      no_answer

      >> no_answer。
        Web搜索將數(shù)據(jù)發(fā)送到Web搜索提示
      1. Web搜索文檔將數(shù)據(jù)發(fā)送到Web搜索文檔。
      2. Web搜索提示符將數(shù)據(jù)發(fā)送到提示點。
      3. >提示木器將將數(shù)據(jù)發(fā)送到LLM以進(jìn)行答案。
      4. 為什麼不看自己?
      5. >
      6. 繪製查詢管道圖
      7. QUERY GRAPH
      8. 我知道這是一個巨大的圖表,但它會向您顯示野獸腹部下發(fā)生的事情。

        現(xiàn)在是時候享受我們辛勤工作的果實了。

        創(chuàng)建一個用於易於查詢的函數(shù)。

        >

        $ pip install haystack-ai ollama-haystack
        
        # On you system download Ollama and install LLM
        
        ollama pull llama3.2:3b
        
        ollama pull nomic-embed-text
        
        
        # And then start ollama server
        ollama serve
        這是一個簡單的簡單函數(shù)。

        現(xiàn)在運行您的主要腳本以索引NCERT物理書

        >

        >這是一項一次性工作,在索引之後,您必須對此行評論,否則它將開始重新索引書籍。
        from haystack import Document, Pipeline
        from haystack.components.builders.prompt_builder import PromptBuilder
        from haystack.components.retrievers.in_memory import InMemoryBM25Retriever
        from haystack.document_stores.in_memory import InMemoryDocumentStore
        from haystack_integrations.components.generators.ollama import OllamaGenerator

        和文件的底部,我們?yōu)椴樵?/p>編寫驅(qū)動程序代碼

        關(guān)於本書知識的電阻率的

        > MCQ
        document_store = InMemoryDocumentStore()
        documents = [
            Document(
                content="Naruto Uzumaki is a ninja from the Hidden Leaf Village and aspires to become Hokage."
            ),
            Document(
                content="Luffy is the captain of the Straw Hat Pirates and dreams of finding the One Piece."
            ),
            Document(
                content="Goku, a Saiyan warrior, has defended Earth from numerous powerful enemies like Frieza and Cell."
            ),
            Document(
                content="Light Yagami finds a mysterious Death Note, which allows him to eliminate people by writing their names."
            ),
            Document(
                content="Levi Ackerman is humanity’s strongest soldier, fighting against the Titans to protect mankind."
            ),
        ]

        書中不在書中的另一個問題 如何使用Haystack Framework構(gòu)建代理QA抹布系統(tǒng)

        輸出

        pipe = Pipeline()
        
        pipe.add_component("retriever", InMemoryBM25Retriever(document_store=document_store))
        pipe.add_component("prompt_builder", PromptBuilder(template=template))
        pipe.add_component(
            "llm", OllamaGenerator(model="llama3.2:1b", url="http://localhost:11434")
        )
        pipe.connect("retriever", "prompt_builder.documents")
        pipe.connect("prompt_builder", "llm")

        讓我們嘗試另一個問題。

        如何使用Haystack Framework構(gòu)建代理QA抹布系統(tǒng)

        image_param = {
            "format": "img",
            "type": "png",
            "theme": "forest",
            "bgColor": "f2f3f4",
        }
        pipe.show(params=image_param)
        >所以,它正在工作!我們可以使用更多數(shù)據(jù),書籍或PDF來嵌入,這將產(chǎn)生更多的上下文感知答案。此外,諸如GPT-4O,Anthropic的Claude或其他Cloud LLM等LLM會更好地完成工作。

        > 如何使用Haystack Framework構(gòu)建代理QA抹布系統(tǒng)結(jié)論

        >我們的代理抹布系統(tǒng)展示了Haystack框架與組合組件和管道的功能的靈活性和魯棒性??梢酝ㄟ^部署到Web服務(wù)平臺,並使用付費更好的LLM(例如OpenAI和Nththththopic)來準(zhǔn)備生產(chǎn)。您可以使用簡化或基於React的Web Spa構(gòu)建UI,以獲得更好的用戶體驗。

        >您可以在此處找到本文中使用的所有代碼。

        >

        鑰匙要點

        與傳統(tǒng)的抹布相比,

        代理抹布系統(tǒng)提供了更聰明,更靈活的響應(yīng)。 Haystack的管道體系結(jié)構(gòu)啟用複雜的模塊化工作流程。

        路由器在響應(yīng)生成中啟用動態(tài)決策。

        >

        連接圖提供了靈活且可維護(hù)的組件交互。
          >
        • 多個知識來源的集成增強了響應(yīng)質(zhì)量。
        • >
        • 本文所示的媒體不歸Analytics Vidhya擁有,並由作者的酌情決定
        • 。
        • 常見問題
        • > Q1。系統(tǒng)如何處理未知查詢?當(dāng)本地知識不足時,系統(tǒng)使用其路由器組件自動返回Web搜索,從而確保全面的覆蓋範(fàn)圍。管道架構(gòu)提供了哪些優(yōu)點?管道體系結(jié)構(gòu)可實現(xiàn)模塊化開發(fā),易於測試和靈活的組件佈置,使系統(tǒng)可維護(hù)和擴(kuò)展。 Q3。連接圖如何增強系統(tǒng)功能?該連接圖可實現(xiàn)複雜的數(shù)據(jù)流和並行處理,提高系統(tǒng)效率以及在處理不同類型的查詢時的靈活性。

          Q4。我可以使用其他LLM API?是的,很容易只為各自的LLM API安裝必要的集成包,例如Gemini,Anthropic和Groq,然後將其與API鍵一起使用。

          >

以上是如何使用Haystack Framework構(gòu)建代理QA抹布系統(tǒng)的詳細(xì)內(nèi)容。更多資訊請關(guān)注PHP中文網(wǎng)其他相關(guān)文章!

本網(wǎng)站聲明
本文內(nèi)容由網(wǎng)友自願投稿,版權(quán)歸原作者所有。本站不承擔(dān)相應(yīng)的法律責(zé)任。如發(fā)現(xiàn)涉嫌抄襲或侵權(quán)的內(nèi)容,請聯(lián)絡(luò)admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅(qū)動的應(yīng)用程序,用於創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

前7個筆記本替代品 前7個筆記本替代品 Jun 17, 2025 pm 04:32 PM

Google的NotebookLM是由Gemini 2.5提供動力的智能AI筆記工具,它在匯總文檔方面表現(xiàn)出色。但是,它在工具使用方面仍然有局限性,例如源蓋,雲(yún)依賴性和最近的“發(fā)現(xiàn)”功能

從採用到優(yōu)勢:2025年塑造企業(yè)LLM的10個趨勢 從採用到優(yōu)勢:2025年塑造企業(yè)LLM的10個趨勢 Jun 20, 2025 am 11:13 AM

以下是重塑企業(yè)AI景觀的十種引人注目的趨勢。對LLMSorganizations的財務(wù)承諾正在大大增加其在LLMS的投資,其中72%的人預(yù)計他們的支出今年會增加。目前,近40%a

AI投資者停滯不前? 3條購買,建造或與人工智能供應(yīng)商合作的戰(zhàn)略途徑 AI投資者停滯不前? 3條購買,建造或與人工智能供應(yīng)商合作的戰(zhàn)略途徑 Jul 02, 2025 am 11:13 AM

投資蓬勃發(fā)展,但僅資本還不夠。隨著估值的上升和獨特性的衰落,以AI為中心的風(fēng)險投資的投資者必須做出關(guān)鍵決定:購買,建立或合作夥伴才能獲得優(yōu)勢?這是評估每個選項和PR的方法

生成AI的不可阻擋的增長(AI Outlook第1部分) 生成AI的不可阻擋的增長(AI Outlook第1部分) Jun 21, 2025 am 11:11 AM

披露:我的公司Tirias Research已向IBM,NVIDIA和本文提到的其他公司諮詢。 Growth驅(qū)動力的生成AI採用的激增比最樂觀的預(yù)測更具戲劇性。然後,

新蓋洛普報告:AI文化準(zhǔn)備就緒需要新的心態(tài) 新蓋洛普報告:AI文化準(zhǔn)備就緒需要新的心態(tài) Jun 19, 2025 am 11:16 AM

廣泛採用和情感準(zhǔn)備之間的差距揭示了人類如何與越來越多的數(shù)字伴侶互動。我們正在進(jìn)入共存階段,算法編織到我們的日?,F(xiàn)場

這些初創(chuàng)公司正在幫助企業(yè)出現(xiàn)在AI搜索摘要中 這些初創(chuàng)公司正在幫助企業(yè)出現(xiàn)在AI搜索摘要中 Jun 20, 2025 am 11:16 AM

由於AI,那些日子是編號的。根據(jù)一個螺柱,搜索企業(yè)諸如Travel網(wǎng)站皮劃艇和Edtech Company Chegg之類的企業(yè)正在下降,部分原因是60%的網(wǎng)站搜索不會導(dǎo)致用戶單擊任何鏈接。

AGI和AI超級智能將嚴(yán)重?fù)糁腥祟愄旎ò宓募僭O(shè)障礙 AGI和AI超級智能將嚴(yán)重?fù)糁腥祟愄旎ò宓募僭O(shè)障礙 Jul 04, 2025 am 11:10 AM

讓我們來談?wù)劇? 對創(chuàng)新AI突破的分析是我正在進(jìn)行的AI中正在進(jìn)行的福布斯列覆蓋的一部分,包括識別和解釋各種有影響力的AI複雜性(請參閱此處的鏈接)。 前往Agi和

思科在美國2025 思科在美國2025 Jun 19, 2025 am 11:10 AM

讓我們仔細(xì)研究一下我發(fā)現(xiàn)的最重要的東西,以及思科如何以其目前的努力來進(jìn)一步實現(xiàn)其野心。

See all articles