跳到主内容
@wquguru
精选75Cloudflare AI Search(Changelog)云与平台

Cloudflare AI Search 集成 Agents SDK

AI Search - Use AI Search with the Agents SDK, AI SDK, and LangChain

原文
发到 X
推荐理由

AI 开发者可直接在常用 Agent 框架中接入 AI Search,省去手写 REST 调用,建议查看新指南并试用集成包。

You can now use AI Search directly from popular agent frameworks, adding grounded retrieval to an existing app instead of calling the REST API by hand. The new Agents section has guides for the Vercel AI SDK, LangChain, and the Cloudflare Agents SDK. The AI SDK integration is a new package, and the LangChain integration is a new retriever in the existing langchain-cloudflare package.

Vercel AI SDK

The ai-search-provider ↗ package connects AI Search to the AI SDK, and targets AI SDK v6 (ai@^6). Pass instance.chat() to generateText or streamText to generate a response grounded in your indexed content, with the retrieved chunks returned as sources. You can also expose instance.search() as a tool for agent loops.

代码 · 7
import { createAISearchNamespace } from "ai-search-provider";
import { generateText } from "ai";
const aiSearch = createAISearchNamespace({ binding: env.AI_SEARCH });
const { text, sources } = await generateText({
	model: aiSearch.get("knowledge-base").chat(),
	messages: [{ role: "user", content: "How does caching work?" }],
});
代码 · 7
import { createAISearchNamespace } from "ai-search-provider";
import { generateText } from "ai";
const aiSearch = createAISearchNamespace({ binding: env.AI_SEARCH });
const { text, sources } = await generateText({
	model: aiSearch.get("knowledge-base").chat(),
	messages: [{ role: "user", content: "How does caching work?" }],
});

LangChain

The langchain-cloudflare package (PyPI ↗, GitHub ↗) provides CloudflareAISearchRetriever, a standard LangChain retriever backed by AI Search. Use it on its own, wrap it with create_retriever_tool to give an agent a search tool, or drop it into a RAG chain. It works with REST credentials or a Worker binding inside a Python Worker.

代码 · 8
from langchain_cloudflare import CloudflareAISearchRetriever
retriever = CloudflareAISearchRetriever(
    account_id=ACCOUNT_ID,
    api_token=API_TOKEN,
    instance_name="knowledge-base",
    retrieval_type="hybrid",
)
docs = retriever.invoke("How do I configure Workers AI?")

Cloudflare Agents SDK

The Cloudflare Agents SDK could already reach AI Search through the Workers binding. The new guide walks through building a stateful chat agent that provisions its own instance, indexes content, and searches it from a tool.

代码 · 9
import { tool } from "ai";
import { z } from "zod";
const instance = env.AI_SEARCH.get("knowledge-base");
// Expose AI Search to the agent's model as a tool it can call.
const searchKnowledgeBase = tool({
	description: "Search the knowledge base for relevant content.",
	inputSchema: z.object({ query: z.string() }),
	execute: ({ query }) => instance.search({ query }),
});
代码 · 9
import { tool } from "ai";
import { z } from "zod";
const instance = env.AI_SEARCH.get("knowledge-base");
// Expose AI Search to the agent's model as a tool it can call.
const searchKnowledgeBase = tool({
	description: "Search the knowledge base for relevant content.",
	inputSchema: z.object({ query: z.string() }),
	execute: ({ query }) => instance.search({ query }),
});

For the full walkthroughs, including creating an instance and indexing content, refer to the Agents guides.

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

相似阅读

另一事件,读法相近