组件接入 · LLAMAINDEX

LlamaIndex 搜索工具接入指南

在 LlamaIndex 中将 Annolux 作为搜索工具或检索器,为 RAG 知识库提供带时间戳的中英检索。

Python 接入方式

将 Annolux 搜索接口封装为 LlamaIndex FunctionTool,供 Agent 与 QueryEngine 检索调用。

import os
import requests
from llama_index.core.tools import FunctionTool

def search_web(query: str, limit: int = 10) -> str:
    """Search curated English and Chinese technical web pages with timestamps."""
    api_key = os.environ.get("ANNOLUX_API_KEY", "")
    res = requests.post(
        "https://api.annolux.com/api/v1/search",
        headers={"Authorization": f"Bearer {api_key}"},
        json={"query": query, "limit": limit, "deduplicate": True},
        timeout=30,
    )
    return res.text if res.ok else f"Error: {res.status_code}"

annolux_tool = FunctionTool.from_defaults(
    fn=search_web,
    name="annolux_search",
    description="Search curated English and Chinese technical web pages with verified fetched_at timestamps."
)

在 Agent 中使用搜索

在 RAG 流程中,当本地向量库相似度不足时,Agent 会调用 search_web 发起检索,每条结果带明确抓取时间。

边界与点数

search_web 查询精选中英索引。只有成功的 2xx 搜索扣 1 点,错误和超时不扣。新账户有 1,000 免费点数。