跳至主要内容
前往文档
⌘U
Weaviate 数据库

使用 Weaviate 的 APIs 和工具开发 AI 应用

部署

部署、配置和维护 Weaviate 数据库

Weaviate Agents

使用 Weaviate 构建和部署智能代理

Weaviate Cloud

在云端管理和扩展 Weaviate

更多资源

集成
贡献者指南
活动 & 工作坊
Weaviate Academy

需要帮助?

Weaviate Logo询问 AI 助手⌘K
社区论坛

Weaviate 查询代理:概述

仅 Weaviate Cloud

Weaviate 查询代理是一种预构建的代理服务,旨在根据存储在 Weaviate Cloud 中的数据回答自然语言查询。

用户只需提供自然语言的提示/问题,查询代理就会负责所有中间步骤以提供答案。

Weaviate Query Agent from a user perspective Weaviate Query Agent from a user perspective

架构

查询代理作为 Weaviate Cloud 上的服务提供。

当用户提供提示/查询时,查询代理会分析它以及任何其他已知上下文,以自主地执行搜索。

查询代理上下文

查询代理分析集合和属性描述,以更好地理解如何构造相关的查询。

上下文还可能包括先前的对话历史记录以及任何其他相关信息。

查询代理:可视化工作流程

Weaviate Query Agent at a high level Weaviate Query Agent at a high level

查询代理遵循以下高级步骤

  • 使用适当的生成模型(例如,大型语言模型)来分析任务和所需的查询。确定要执行的确切查询。(步骤 1 和 2)
  • 将查询发送到 Weaviate。Weaviate 会根据需要使用指定的向量化器集成对查询进行向量化。(步骤 3-5)
  • 接收来自 Weaviate 的结果,并使用适当的生成模型生成最终响应给用户提示/查询。(步骤 6)

然后,查询代理将答案返回给用户,以及中间输出,例如来自 Weaviate 的底层搜索结果。

请注意,术语 查询代理 指的是整个系统。查询代理可能包含多个子系统,例如幕后的微服务和/或代理,每个子系统负责特定的任务。

Weaviate Query Agent comprises multiple agents Weaviate Query Agent comprises multiple agents

查询

查询代理支持两种查询类型

  • 搜索 使用查询代理以自然语言搜索 Weaviate。查询代理将处理问题,在 Weaviate 中执行必要的搜索,并返回相关对象。

  • 提问 使用自然语言向查询代理提问。查询代理将处理问题,在 Weaviate 中执行必要的搜索,并返回答案。

基本用法

以下是如何使用此 Weaviate 代理的概述。有关更详细的信息,请参阅 用法 页面。

先决条件

此代理仅可用于具有 Weaviate Cloud 实例和受支持版本的 Weaviate 客户端库

示例用法

将 Weaviate 客户端的实例传递给查询代理,查询代理将从客户端提取必要的信息以执行查询。

import os
import weaviate
from weaviate.classes.init import Auth
from weaviate.agents.query import QueryAgent


headers = {
# Provide your required API key(s), e.g. Cohere, OpenAI, etc. for the configured vectorizer(s)
"X-INFERENCE-PROVIDER-API-KEY": os.environ.get("YOUR_INFERENCE_PROVIDER_KEY", ""),
}

client = weaviate.connect_to_weaviate_cloud(
cluster_url=os.environ.get("WEAVIATE_URL"),
auth_credentials=Auth.api_key(os.environ.get("WEAVIATE_API_KEY")),
headers=headers,
)

# Instantiate a new agent object
qa = QueryAgent(
client=client, collections=["ECommerce", "FinancialContracts", "Weather"]
)

然后,提供自然语言查询输入。查询代理将处理查询,在 Weaviate 中执行必要的搜索,并返回答案。

搜索(仅检索)

# Perform a search using Search Mode (retrieval only, no answer generation)
search_response = qa.search("Find me some vintage shoes under $70", limit=10)

# Access the search results
for obj in search_response.search_results.objects:
print(f"Product: {obj.properties['name']} - ${obj.properties['price']}")

查询代理甚至可以处理后续查询,将先前的响应用作附加上下文。

# Perform a follow-up query and include the answer from the previous query
from weaviate.agents.classes import ChatMessage

conversation = [
ChatMessage(role="assistant", content=response.final_answer),
ChatMessage(
role="user",
content="I like the vintage clothes options, can you do the same again but above $200?",
),
]

following_response = qa.ask(conversation)

# Print the response
following_response.display()

提问(带有答案生成)

# Perform a query using Ask Mode (with answer generation)
response = qa.ask(
"I like vintage clothes and nice shoes. Recommend some of each below $60."
)

# Print the response
response.display()

更多资源

有关如何使用此代理的更详细信息,请参阅 用法 页面。

问题和反馈

如果您有任何问题或反馈,请在 用户论坛 中告诉我们。