# Download the configuration file and rename it as docker-compose.yml C:\>Invoke-WebRequest https://github.com/milvus-io/milvus/releases/download/v2.6.0/milvus-standalone-docker-compose.yml -OutFile docker-compose.yml
# Start Milvus C:\>docker compose up -d
注意设置环境变量DOCKER_VOLUME_DIRECTORY来决定卷映射的路径
容器
镜像
在 Milvus 中的角色
一句话说明
etcd
quay.io/coreos/etcd:v3.5.18
元数据与协调中心
负责“记帐”——存索引结构、集合信息、节点心跳等,相当于 Milvus
的“大脑备忘录”。
minio
minio/minio:RELEASE.2024-12-18T13-15-44Z
对象存储
负责“存文件”——把向量索引文件、大字段、日志快照等落地成对象,相当于
Milvus 的“硬盘”。
standalone
milvusdb/milvus:v2.6.0
计算节点(单机版)
负责“干活”——接受 SDK 请求、做向量检索、构建索引,相当于 Milvus
的“工人”。
安装
1
pip install -U pymilvus
基本概念
数据库
在 Milvus
中,数据库是组织和管理数据的逻辑单元。为了提高数据安全性并实现多租户,你可以创建多个数据库,为不同的应用程序或租户从逻辑上隔离数据。例如,创建一个数据库用于存储用户
A 的数据,另一个数据库用于存储用户 B 的数据。
flowchart TB subgraph "Plan-and-Execute阶段" A["用户输入"] --> B["Planner Agent"] B --> C["Agent Executor"] C --> D["Replanner"] D -->|"需要更多信息"| C D -->|"信息充足"| E["输出结构化信息"] end subgraph "内容生成阶段" E --> F["大纲设计节点"] F --> G["页面内容生成节点"] G --> H["HTML代码生成节点"] end subgraph "文件转换阶段" H --> I["html演示生成"] I --> J["转换pptx节点"] J --> K["输出PPTX文件"] end
REWRITE_PROMPT = ( "Look at the input and try to reason about the underlying semantic intent / meaning.\n" "Here is the initial question:" "\n ------- \n" "{question}" "\n ------- \n" "Formulate an improved question:" )
GENERATE_PROMPT = ( "You are an assistant for question-answering tasks. " "Use the following pieces of retrieved context to answer the question. " "If you don't know the answer, just say that you don't know. " "Use three sentences maximum and keep the answer concise.\n" "Question: {question} \n" "Context: {context}" )
from typing import Annotated from langchain_core.tools import tool, InjectedToolCallId from langgraph.prebuilt import InjectedState from langgraph.graph import StateGraph, START, MessagesState from langgraph.types import Command
工具 (Tool): 在 AI
应用中,工具是代理(Agent)可以调用的函数或能力。这个函数创建的工具就是一个封装好的、可以被
Agent 调用的函数,用于执行创建、更新、删除记忆的操作。
什么时候agent会调用记忆工具
image-20250814163150589
ai是这样回答的,ReAct架构的agent是否调用工具由他自己决定
实战
导入库
1 2 3 4 5 6 7 8
from langgraph.checkpoint.memory import MemorySaver from langgraph.prebuilt import create_react_agent from langgraph.store.memory import InMemoryStore from langgraph.utils.config import get_store from langmem import ( # 让智能体创建、更新和删除记忆 create_manage_memory_tool, )
返回记忆提示词
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
def prompt(state): """为LLM准备消息。""" # 从配置的上下文变量中获取存储; store = get_store() # 与提供给 `create_react_agent` 的相同 memories = store.search( # 在与我们为智能体配置的相同命名空间内搜索 ("memories",), query=state["messages"][-1].content, ) system_msg = f"""You are a helpful assistant.
# This will be the public-facing agent card public_agent_card = AgentCard( name='Hello World Agent', description='Just a hello world agent', url='http://localhost:9999/', version='1.0.0', # 默认输入模式:Agent 能够接收的输入类型列表,这里仅支持纯文本 default_input_modes=['text'], # 默认输出模式:Agent 能够产生的输出类型列表,这里仅返回纯文本 default_output_modes=['text'], # 能力声明:告知调用方 Agent 支持的能力,例如是否支持流式输出(streaming) capabilities=AgentCapabilities(streaming=True), skills=[skill], # Only the basic skill for the public card supports_authenticated_extended_card=True, )
这张卡片告诉我们代理名为 “Hello World Agent”,运行在
http://localhost:9999/,支持文本交互,并具有
hello_world
技能。它还表明支持公开认证,意味着无需特定凭证。