Qdrant MCP 工具(用于 ADK)¶
在 ADK 中得到支持。PythonTypeScript
The Qdrant MCP Server 将您的 ADK 代理连接到…… Qdrant这是一个开源的向量搜索引擎。通过这次集成,您的代理程序将能够使用语义搜索功能来存储和检索信息。
使用场景¶
-
代理的语义记忆(Semantic Memory for Agents):存储对话的上下文、相关事实以及学习到的信息,以便代理(agents)日后可以通过自然语言查询来检索这些数据。
-
代码仓库搜索:构建一个可搜索的索引,其中包含代码片段、文档以及实现模式等内容,用户可以对其进行语义查询(即根据代码的含义或用途来查找相关信息)。
-
知识库检索通过存储文档并检索与回复相关的内容,来创建一个基于“检索增强生成”(Retrieval-Augmented Generation, RAG)技术的系统。
先决条件¶
- 一个正在运行的 Qdrant 实例。您可以:
- 使用 Qdrant Cloud (托管服务)
- 使用 Docker 在本地运行该应用程序:
docker run -p 6333:6333 qdrant/qdrant
- (可选)用于身份验证的 Qdrant API 密钥
与代理程序(agent)一起使用。¶
from google.adk.agents import Agent
from google.adk.tools.mcp_tool import McpToolset
from google.adk.tools.mcp_tool.mcp_session_manager import StdioConnectionParams
from mcp import StdioServerParameters
QDRANT_URL = "http://localhost:6333" # Or your Qdrant Cloud URL
COLLECTION_NAME = "my_collection"
# QDRANT_API_KEY = "YOUR_QDRANT_API_KEY"
root_agent = Agent(
model="gemini-flash-latest",
name="qdrant_agent",
instruction="Help users store and retrieve information using semantic search",
tools=[
McpToolset(
connection_params=StdioConnectionParams(
server_params=StdioServerParameters(
command="uvx",
args=["mcp-server-qdrant"],
env={
"QDRANT_URL": QDRANT_URL,
"COLLECTION_NAME": COLLECTION_NAME,
# "QDRANT_API_KEY": QDRANT_API_KEY,
}
),
timeout=30,
),
)
],
)
import { LlmAgent, MCPToolset } from "@google/adk";
const QDRANT_URL = "http://localhost:6333"; // Or your Qdrant Cloud URL
const COLLECTION_NAME = "my_collection";
// const QDRANT_API_KEY = "YOUR_QDRANT_API_KEY";
const rootAgent = new LlmAgent({
model: "gemini-flash-latest",
name: "qdrant_agent",
instruction: "Help users store and retrieve information using semantic search",
tools: [
new MCPToolset({
type: "StdioConnectionParams",
serverParams: {
command: "uvx",
args: ["mcp-server-qdrant"],
env: {
QDRANT_URL: QDRANT_URL,
COLLECTION_NAME: COLLECTION_NAME,
// QDRANT_API_KEY: QDRANT_API_KEY,
},
},
}),
],
});
export { rootAgent };
可用的工具¶
| 工具 | 描述 |
|---|---|
qdrant-store |
将商店信息存储在 Qdrant 中,并可选择是否添加元数据。 |
qdrant-find |
使用自然语言查询来搜索相关信息。 |
配置¶
Qdrant MCP 服务器可以通过环境变量进行配置:
| 变量 | 描述 | 默认值 |
|---|---|---|
QDRANT_URL |
Qdrant 服务器的 URL | None (必填) |
QDRANT_API_KEY |
用于 Qdrant Cloud 认证的 API 密钥 | None |
COLLECTION_NAME |
要使用的集合的名称 | None |
QDRANT_LOCAL_PATH |
用于本地持久存储的路径(作为 URL 的替代方案) | None |
EMBEDDING_MODEL |
要使用的嵌入模型 | sentence-transformers/all-MiniLM-L6-v2 |
EMBEDDING_PROVIDER |
用于生成嵌入向量的服务提供商:)fastembed 或者 ollama) |
fastembed |
TOOL_STORE_DESCRIPTION |
该商店工具的自定义描述 | 默认描述 |
TOOL_FIND_DESCRIPTION |
查找工具的自定义描述 | 默认描述 |
自定义工具描述¶
您可以自定义工具描述,以指导代理的行为。
env={
"QDRANT_URL": "http://localhost:6333",
"COLLECTION_NAME": "code-snippets",
"TOOL_STORE_DESCRIPTION": "Store code snippets with descriptions. The 'information' parameter should contain a description of what the code does, while the actual code should be in 'metadata.code'.",
"TOOL_FIND_DESCRIPTION": "Search for relevant code snippets using natural language. Describe the functionality you're looking for.",
}