Skip to content

Qdrant

Qdrant MCP Server 将你的 ADK 智能体连接到 Qdrant,这是一个开源向量搜索引擎。此集成使你的智能体能够使用语义搜索存储和检索信息。

使用场景

  • 智能体的语义记忆: 存储对话上下文、事实或智能体稍后可使用自然语言查询检索的学习信息。

  • 代码仓库搜索: 构建可搜索的代码片段索引、文档和实现模式,可以进行语义查询。

  • 知识库检索: 通过存储文档并检索相关上下文以用于回复,创建检索增强生成 (RAG) 系统。

先决条件

  • 一个正在运行的 Qdrant 实例。你可以:
    • 使用 Qdrant Cloud(托管服务)
    • 使用 Docker 本地运行:docker run -p 6333:6333 qdrant/qdrant
  • (可选)用于身份验证的 Qdrant API 密钥

与智能体一起使用

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-2.5-pro",
    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,
            ),
        )
    ],
)

可用工具

工具 描述
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 嵌入提供程序(fastembedollama 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.",
}

额外资源