首頁 >科技週邊 >人工智慧 >如何使用Haystack Framework構建代理QA抹布系統

如何使用Haystack Framework構建代理QA抹布系統

尊渡假赌尊渡假赌尊渡假赌
尊渡假赌尊渡假赌尊渡假赌原創
2025-03-03 18:35:10650瀏覽

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

學習目標

  • 知道什麼是代理LLM,並且了解它與抹布系統有何不同。 >
  • 熟悉Agesic LLM應用程序的Haystack框架。
  • >了解從模板提示構建的過程,並學習如何將不同的提示連接在一起。
  • 學習如何在Haystack中使用Chromadb創建嵌入。
  • >
  • 學習如何建立從嵌入到世代的完整本地開發系統。
  • >本文是

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

組件

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

    rag vs agentic rag

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

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

    如何使用Haystack Framework構建代理QA抹布系統現在,一個代理抹布系統通過以下方式增強了此過程

    評估查詢要求

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

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

    您可以使用Haystack構建什麼?

    >使用強大的檢索和發電技術易於促進數據的抹布。

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

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

    >從文檔或構建知識圖中提取信息。

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

      組件

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

      有合作夥伴公司和社區的集成集合。 >

      >

      >安裝庫,並設置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
      導入一些組件

      創建文檔和文檔存儲
      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框架的骨幹。它們定義了不同組件之間的數據流。管道本質上是有向的無環圖(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)

      模塊化工作流程管理

        靈活組件佈置
      • >輕鬆調試和監視
      • 可擴展的處理體系結構
      • >節點
      • 節點是可以在管道中連接的基本處理單元,這些節點是執行特定任務的組件。 來自上述管道的節點的示例

      連接圖

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

      從上面的管道中,您可以可視化連接圖。
      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")
      )
      
      >

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

      定義組件之間的數據流

      > 如何使用Haystack Framework構建代理QA抹布系統>管理輸入/輸出關係

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

      >

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

      響應:

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

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

      >

      >高中物理學的問答抹布項目

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


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

        Chromadb用於嵌入存儲
      • 用於本地嵌入
      • 的通用嵌入文本模型
      • duckduckgo搜索網絡搜索或tavily搜索(可選)
      • >
      • 我使用一個免費的,完全局部的系統。
      • >
      設置開發人員環境

      我們將設置一個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

      現在創建一個名為

      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文件,這無關緊要。我將使用一個普通的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."
          ),
      ]
      在項目根上創建

      main.py

      文件。

      > 導入必要的庫

      >系統軟件包

        > 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")
      )
      
      創建文檔商店
      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系統。

      該解決方案是矢量數據庫,例如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文件路徑

      >它將從數據文件夾中創建文件列表,該文件由我們的PDF文件組成。 >

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

      >我們將使用Haystack的內置文檔預處理器,例如清潔器,分離器和文件轉換器,然後使用Writer將數據寫入商店。

      清潔器:

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

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

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

      >>文件轉換器:它將使用PYPDF將PDF轉換為文檔。

      $ 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
      現在設置文檔索引的嵌入式。

      >

      嵌入: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 現在嵌入組件

      我們使用

      > 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。 創建索引管道 就像我們以前的玩具抹布示例一樣,我們將首先啟動管道類別。 >

      現在,我們將一一

      一個添加到管道中的組件

      >在管道中添加組件並不關心訂單,因此您可以按任何順序添加組件。但是連接是重要的。
      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")
      )
      

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

      >

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

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

      繪製索引管道

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

      索引管道的圖

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

      我假設您現在已經完全掌握了Haystack管道背後的想法。感謝您的水管工。

      實現路由器

      >現在,我們需要創建一個路由器來通過其他路徑路由數據。在這種情況下,我們將使用條件路由器,該路由器將在某些條件下完成路由工作。條件路由器將根據組件輸出評估條件。它將通過不同的管道分支來指導數據流,從而實現動態決策。它也將具有強大的後備策略。
      $ 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

      系統從嵌入式商店上下文中獲得NO_ANSWER回复時,它將轉到Web搜索工具以從Internet收集相關數據。

      >用於網絡搜索,我們將使用DuckDuckgo API或Tavely,在這裡我使用了DuckDuckgo。

      好的,大多數繁重的舉重已經完成。現在,是時候及時工程
      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

      創建提示模板

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

      構建提示

      首先,我們將為QA

      創建一個提示

      >它將從文檔中獲取上下文,並嘗試回答問題。但是,如果它在文檔中找不到相關上下文,它將回复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."
          ),
      ]
      現在,在從LLM獲取NO_ANSWER之後的第二個提示中,系統將使用Web搜索工具從Internet收集上下文。

      > duckduckgo提示模板

      >它將有助於系統進入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")

      的提示構建器創建提示

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

      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或您喜歡使用工具調用的任何LLM生成答案。 >

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

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

      發送到回獵犬的查詢嵌入的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 }}?
      """

      獵犬將數據發送到提示_builder的文檔。

      提示構建器轉到提示木器以加入其他提示。

      >

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

      no_answer

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

        現在是時候享受我們辛勤工作的果實了。

        創建一個用於易於查詢的函數。

        >

        $ 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
        這是一個簡單的簡單函數。

        現在運行您的主要腳本以索引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

        和文件的底部,我們為查詢

        編寫驅動程序代碼

        關於本書知識的電阻率的

        > 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構建代理QA抹布系統

        輸出

        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構建代理QA抹布系統

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

        > 如何使用Haystack Framework構建代理QA抹布系統結論

        >我們的代理抹布系統展示了Haystack框架與組合組件和管道的功能的靈活性和魯棒性。可以通過部署到Web服務平台,並使用付費更好的LLM(例如OpenAI和Nththththopic)來準備生產。您可以使用簡化或基於React的Web Spa構建UI,以獲得更好的用戶體驗。

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

        >

        鑰匙要點

        與傳統的抹布相比,

        代理抹布系統提供了更聰明,更靈活的響應。 Haystack的管道體系結構啟用複雜的模塊化工作流程。

        路由器在響應生成中啟用動態決策。

        >

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

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

          >

以上是如何使用Haystack Framework構建代理QA抹布系統的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn